Play and learn 300 000+ tabs online

Thursday, March 18, 2010

Hexaware Interview Questions

Directions for questions 1-10: Expand the following terms (HexaWare)
1. ODBC    Ans. Open Database Connectivity.
2. HTML    Ans. Hyper Text Markup Language
3. RISC    Ans. Reduced Instruction Set Computing
4. ASCII    Ans. American Standard Code For Information Interchange
5.ANSI    Ans. American National Standard Institute.
6. XML     Ans. Extended Markup Language
7. FLOPS    Ans. Floating Point Operating Per Second
8. SQL        Ans. Sequential Query Language
9. QBE    Ans. Query By Example
10. ALE    Ans. Address Latch Enable
11. What is lagging in DBMS ?     Ans. Reduced Redundancy.
Directions 12 to 20: For the following questions find the odd man out
12. Unix
      OS/2
      CMOS
      MSDOS    Ans. CMOS
13. Oracle
      Informix
      Sybase
      LISP    Ans. LISP
14. Laser
      Inkjet
      Dotmatirx
      Mouse    Ans. Mouse
15. Dir
      Cls
      Csh
      Copy    Ans. Csh
16. Bit
      Byte
      Nibble
      Digit    Ans. Digit
17. Hard Disk
      Floppy Drive
      CD ROM
      Cache    Ans. Cache
18. SQL
      QUEL
      QBE
      ORACLE    Ans. Oracle
19. C++
      JAVA
      VC++
      PASCAL    Ans. PASCAL
20. Projection Operation
      Selection Operation
      Intersection
      Set Difference Operation        Ans. Intersection
21. Which of the following is a universal gate ?
(a) OR
(b) AND
(c) XOR
(d) NOR    Ans. NOR
22. The default back end of the VB is
(a) Oracle
(b) Sybase
(c) Informics    Ans. Sybase
23. What is meant by Superconductivity?    Ans. No reistance
24. Viscosity                    Ans. Friction
25. What is the Lock Based Protocol used for?    Ans. Concurrency Control in DBMS
Directions for question 25 to 32: Convert the decimal numbers on the left to the required form
25. 9's complement of 28    Ans. 71
26. Binary of 58        Ans. 111010
27. Octal of 359        Ans.547
28. Hexadecimal of 650    Ans.28A
29. BCD of 18            Ans.0001 1000
30. BCD of 34.8        Ans.0011 0100.1000
31. Excess-3 code of 6    Ans.1001
32. Excess-3 code of 9    Ans.1100
33.  If Ax + By = 1F16; Cx + Dy = 2510 .Find the value of x and y
34. Semaphore is used for
(a) synchronization
(b) dead-lock avoidence
(c) box
(d) none                        Ans.  A
35. For addressing 1 MB memory, the  number of address lines required,
(a)11
(b)16
(c)22
(d) 24                            Ans.  b
36. Which of the following remains in memory temporarily
(a) Resident portion of COMMAND.COM
(b) Transient portion of COMMAND.COM
(c) API
(d) Disk BIOS                        Ans.  b
37. Pick the odd man out
(a) IO.SYS
(b) MSDOS.SYS
(c) ROM-BIOS
(d) COMMAND.COM                Ans.  C
38. OS/2 is a
(a) Single User OS
(b) Multi User OS
(c) Multi Tasking OS
(d) None of these                    Ans.  C
39. Bootstrap loader program is a program belonging to
(a) ROM startup software
(b) ROM extension software
(c) ROM BIOS software
(d) ROM Basic software                Ans.  A
40. The entry of starting cluster of a file is present in
(a) Boot Parameters
(b) Directory
(c) FAT
(d) Partition Table and master boot program        Ans.  C

JAVA Servlet Interview Questions

        Interview Based Questions

1. What are the types of ServletEngines?
Standalone ServletEngine:A standalone engine is a server that includes built-in support for servlets.

Add-on ServletEngine:Its a plug-in to an existing server.It adds servlet support to a server that was not originally designed with servlets in mind.

Embedded ServletEngine:

2.What is the difference between a Generic Servlet and Http Servlet?

Generic Servlet                    Http Servlet
Class which internally implements     An abstract class which acts as a child class both for Servlet and ServletConfig     GenericServlet and in addition provides interfaces. some additional methods
like doGet(),doPost(),doDelete() &
doPut().

3.What is a Session Id?

It is a unique id assigned by the server to the user when a user first accesses a site or an application ie. when a request is made.

4. List out Differences between CGI Perl and Servlet?

Servlet                            CGI

Platform independent                Platform dependent.
Language dependent                Language independent.

5. What is Bootstrapping in RMI?

Dynamic loading of stubs and skeletons is known as Boot Strapping.

6. What are different types of Exceptions?.
Runtime exceptions, Errors, Program Exceptions

7. What are types of applets?.
Trusted Applets: Applets with predefined security
Untrusted Applets: Applets without any security

8. When does an Exception occur?.

Whenever an error occurs in an Application,(either at compile time)or runtime,it raises an Exception.

9. What is servlet tunnelling?.
Used in applet to servlet communications, a layer over http is built so as to enable object serialization.

10. What is a cookie?.

Cookies are a way for a server to send some information to a client to store and for the server to later retrieve its data from that client.Web browser supports 20 cookies/host of 4kb each.

11.What is the frontend in Java?.Also what is Backend?.
Frontend: Applet
Backend : Oracle, Ms-Access(Using JDBC).

12. Define a JSP?.
Java Server Pages includes scripplets of Servletcode in an Html page.This creates dynamism in the other-wise static HTML.A JSP is a document that describes how to process a request to creeate response.

13. The length of an identifier is

14. Stored procedures can be called by Callable Statement.

15. Stack class implements LIFO(Last In First Out).

16. Servlet Class defines init.

17. Reference of any instance variable inside a static method is legal if declared static.

18. What will a read() function do?.
A method in Input Stream.It reads a single byte or an array of bytes.Returns no of bytes read or -1 if EOF(End of file)is reached.

19.To implement a Throwable array,which class is used.
Vector
LinkedList
Stack
ArrayList - Answer(To be Confirmed)

20. The method for precompiled SQL Statement in JDBC is prepareStatement().

21. Static binding occurs at
Compile Time
Runtime
Both at compile and runtime.

22. Virtual Methods are default in
Java
C
C++ - Answer
All

23. Storage space in java is of the form
Stack
Queue
Heap
List

24. What is java code embedded in a web page known as
Applets
Servlets
scriptlets
snippets

25. Which of the following attributes are compulsory with an <applet> tag?.
code,height & width.

26. What does 'CODEBASE' in an applet tag specify?.
Files absolute path.

27. What are AccessSpecifiers & Access Modifiers.
Access Specifiers: Give access previleges to outside applications or users. They are :-
Public: any one can access
private:only class members can access.cannot be inherited.
protected: can be accessed by a derived class.
default: can access data from the current directory.

Access Modifiers: Which gives additional meaning to data, methods and classes.
(i) Final: cannot be modified at any point of time.

28. Tools provided by JDK
(i)    javac - compiler
(ii)    java - interpretor
(iii)    jdb - debugger
(iv)    javap - Disassembles
(v)    appletviewer - Applets
(vi)    javadoc - documentation generator
(vii)    javah - 'C' header file generator

29.Hostile Applets:Its an applet which when downloaded attempts to exploit your system's resources in an inappropriate manner.It performs or causes you to perform an action which you would not otherwise care to perform.

30.RemoteObjects: Objects that have methods that can be called accross virtual machines are 0000000000000000Remote Objects.An object becomes Remote by implementing Remote Interface.

31.Compiling: Conversion of Programmer-readable Text into Bytecodes,which are platform independent,is known as Compiling.

32.Java Primitive Data Types:
Byte-8-bit
short-16-bit
int-32-bit
Long-64-bit
Float-32-bit floating point
Double-64-bit floating point
Char-16-bit Unicode

33.What is a unicode?
Unicode is a standard that supports International Characters.

34. What are blocks?.
They are statements appearing within braces {}.

35. What are types of Java applications?.

(i) Standalone applications(No browser).
(ii) Applets(Browser).

36. What is the method that gets invoked first in a stand alone application?.

The main()method.

37. What is throwing an Exception?.
The act of passing an Exception Object to the runtime system is called Throwing an Exception.

38. What are the packages in JDK?.

There are 8 packages
(i) java.lang(ii)java.util(iii)java.io(iv)java.applet(v) java.awt
(vi) java.awt.image(vii)java.awt.peer(viii)java.awt.net

39. What is a thread?.
Its a single sequential stream of execution.

40. What is runnable?.
Its an Interface through which Java implements Threads.The class can extend from any class but if it implements Runnable,Threads can be used in that particular application.

41. What is preemptive and Non-preemptive Time Scheduling?.
 Preemptive: Running tasks are given small portions of time to execute by using time-slicing.
Non-Preemptive: One task doesn't give another task a chance to run until its finished or has normally yielded its time.

42. What is synchronization?.
Two or more threads trying to access the same method at the same point of time leads to synchronization.If that particular method is declared as synchronized only one thread can access it at a time. Another thread can access it only if the first thread's task is complete.

43. What are the various thread priorities?.

(i)  Min-Priority-value(1).
(ii) Normal-Priority-value(5).
(iii)Max-Priority-value(10).

44.What is Inter-Thread communication?.
To exchange information between two threads.

45.The package java.applet.* has only one class.

46.BorderLayout is the default layout of Dialog object.

47.executeQuery() returns ResultSet.

48.Throwable class is a sub-class of object and implements Serializable.

49.Super class of TextArea and TextField is TextComponent.

50. Skeletons are server side proxies and stubs are client side proxies.

51. GridBagConstraints class helps in positioning of parameters of a
component within an object laidout using GridBagLayout.

52. Netscape introduced JScript language - True

53. EventDelegation model was introduced by JDK 1.1 - False

54. StringTokenizer provides two constructors - False

55. java.applet is one of the smallest package in Java API - True

56. Drag and Drop API consist of java.awt.dnd package - False

57. What is IP?.
IP is Internet Protocol. It is the network protocol which is used to send information from one computer to another over the network over the internet in the form of packets.

58. What is a port?.
A port is an 16-bit address within a computer.Ports for some common Internet Application protocols.

File Transfer Protocol-21.
Telnet Protocol-23.
Simple Mail Transfer Protocol-25.
Hypertext Transfer Protocol-80.

59.What is hypertext?.
Sockets are endpoints of Internet Communication.They are associated with a host address and a port address.
Clients create client sockets and connect them to server sockets.UDP is a connectionless protocol.

MIME(Multipurpose Internet Mail Extension) is a general method by which the content of different types of Internet objects can be identified.

61. What is an abstract class?.
A class which cannot be Instantiated.

62.ServletRunner options are:
-p-port number(8080).
-b-backlog connections(50).
-m-maximum no.of connection handlers(100).
-t-connection timeout in milliseconds
-d-servlet directory (current directory)
-s-servlet properties file

63.How many standard ports are available?.
1024.

64.What is a policy?.
It's an abstract class for representing the system security policy for a Java application environment(specifying which permissions are available for code from various sources). Java security properties file resides in <JAVA-HOME>/lib/security/java.security directory. Value of "policy.provider" should be changed.

65. What are different ways of Session-Tracking?.
(i) User-Authorization
(ii) Hidden Files
(iii) Persistant Cookies
(iv) URL Rewriting.

66. If the browser does not support cookies or if they are disabled, how is session tracking done?.

Session tracking is done by URL Rewriting.
* Multiple requests can be handled by a servlet and it also can synchronize them.ex: On-line conferencing.
* Servlets have no Graphic User Interface.
* We can synchronize the service() method for a major performance impact as multiple requests are involved in case of servlets.
* We can make a servlet handle a single client/request by implementing single threadmodel interface.

67. What is a Swing?.
It is a GUI component with a pluggable look and feel.

68. What is default Look-and-Feel of a Swing Component?.
Java Look-and-Feel.

69. Awt Components and Swing Components can be inter-mingled in an Application - False

70. What are the features coming with JFC?.
(i) Pluggable Look-and-Feel
(ii) Accessibility API
(iii) Java 2D/API(JDK 1.2).
(iv) Drag and Drop Support(JDK 1.2)

71. What does x mean in javax.swing?.       
Extension of java.
72. Images can be displayed on Swing Components
- True
73. Borders can be changed or added for a LightWeight Components
- True
74. Swing Components are always rectangular
- False
75. When Swing components overlap with Heavyweight components, it is the latter that is on the top
 - True

76. What are the components which are termed to be Heavy-weight, available in Light-weight component?.

77. What are invisible components?.
They are light weight components that perform no painting, but can take space in the GUI.

78. What is the default layout for a ContentPane in JFC?.
BorderLayout.

79. What are the borders provided by Swing?.
(i) Simple        (ii) Matte        iii) Titled    iv) Compound.

80. What does Realized mean?.
Realized mean that the component has been painted on screen or that is ready to be painted. Realization can take place by invoking any of these methods.
setVisible(true), show() or pack().

81. What is a convertor?.
Its an application that converts distance measurements between metric and U.S units.

82. What is the return type of interrupt method?.        void.
83. What is the superclass of exception?.        Throwable.
84. What is servlet exception?.            It indicates that there is a problem in the servlet.
85. What is the difference between a Canvas and a Scroll Pane?.
=====================================================================
Canvas                    ScrollPane
=====================================================================
Its a component                             Its a container.
------------------------------------------------------------------------------------------------------------------------------
A rectangular area where the application        Implements horizontal and vertical
can draw or trap input events.            scrolling.
=====================================================================
86. What are the restrictions imposed by a Security Manager on Applets?.

i) cannot read or write files on the host that's executing it.
ii) cannot load libraries or define native methods.
iii) cannot make network connections except to the host that it came from
iv) cannot start any program on the host that's executing it.
v) cannot read certain system properties.
vi) windows that an applet brings up look different than windows that an application brings up.

87. Can we access a database using applets?.            Yes.
88. What is the default HttpRequest method?.            doGet().
89. What is the life cycle of a servlet?.
Removing Handling zero or more client requests.Loading and Initializing.
90. RPC stands for Remote Procedure Call.
91. The three layers in RMI are Application Layer,RemoteReferenceLayer and Network Layer.

Interviewer's Questions type

Type of Questions

Interviewers use five different types of questions - directive, non-directive, hypothetical, behavior descriptive, and stress. Being aware of the different types can help you in the preparation stage as you  build your skills  inventory. It may also help you focus in on exactly what is being asked and what the employer is looking for in specific questions.

 

 Directive Questions

 

The interviewer determines the focus of your answer. The information that the interviewer wants is very clear. If you have completed the research on yourself, this type of question should be easy to answer.

 

 Example: "What skills do you have that relate to this position?"

 

"I have very good communication and interpersonal skills that I have refined through several summer and part-time jobs working with the public. In addition, I am fluent in both English and French."

 

 Non-Directive Questions

 

You determine the focus of your answer. The interviewer asks a general question and does not ask for specific information. The most common non-directive question is

 

"Tell me about yourself."

 

When answering the question, keep in mind that the employer is interested in knowing how your background and personality qualify you for the job. In your answer, you should cover four areas: your education, related experience, skills and abilities, and personal attributes. As you talk about these areas, relate them to the job you are seeking. Decide what your response will be before starting to speak, this helps to keep responses concise.

 

Example: " Tell me about yourself."

 

"I have a Bachelor of Arts Degree in Psychology, and have recently completed the course

 

in Volunteer Management through the Volunteer Center of Winnipeg. These have given me a strong background in many of the principles of human behavior and the recruitment, training, and supervision of volunteers. I have experience in working with young adults in a helping capacity, both through my position as a Peer Advisor at the University of Manitoba, and as a camp counselor at a camp for behaviorally troubled adolescents. Both of these positions involved individual counseling, facilitating discussion groups, and teaching young people about health issues - all of which relate directly to the services which I would be training volunteers to provide within your organization. In addition, I thoroughly enjoy working with young people, and can establish rapport with them easily."

 

 Hypothetical or Scenario Questions

 

When asking a hypothetical question, the interviewer describes a situation, which you may encounter in the position and asks how you would react in a similar situation. This is a good way to test problem-solving abilities. When answering this type of question, try applying a simple problem solving model to it – gather information, evaluate the information, priories the information, seek advice, weigh the alternatives, make a decision, communicate the decision, monitor the results and modify if necessary.

 

Example: "Suppose you are working your first day in our laboratory, and a fire at a nearby work station breaks out. What would you do?"

 

"Before I start working in any laboratory, I always locate the emergency equipment, such as eye washes, fire blankets and alarms. I would also review the safety protocols. So in this situation, I would be aware of these. As soon as I noticed the fire, I would shut down my experiment and if the fire is significant, I would pull the firm alarm and help to evacuate the lab. In the case of very small flame, I would ask the staff member at the station what I could do to help, Which would vary with the type of substances involved.”

 

 Behavior Descriptive or Behavioral Questions

 

This type of question is becoming increasingly popular in interview situations. It asks what you did in a particular situation rather than what you would do. Situations chosen usually follow the job description fairly closely. Some employers feel that examples of past performance will help them to predict future performance in similar situations. There is no right or wrong answer to this type of question, but keep in mind that you should relate the answer to the position. If you are interviewing for a research position, talk about a research project you completed.

 

Example: "Give me an example of a work situation in which you were proud of your performance."

 

"While working as a sales representative for XYZ Company for the summer, I called on Prospective clients and persuaded them of the ecological and economic benefits of Recycling. I also followed up on clients to ensure that they were satisfied with the service They received. This involved both telephone and in-person contacts. I increased sales 34% over the same period in the previous year."

 

When preparing for this type of questioning, it is crucial that you review the skills and qualities that the position would require and identify specific examples from your past which demonstrated those traits.

 

Stress Questions

 

Some questions will surprise you and possibly make you feel uncomfortable during an interview. For

 

Example:"  Which do you prefer, fruits or vegetables?" There are many reasons why an interviewer might ask such questions. They may want to see how you react in difficult situations, or they may simply be trying to test your sense of humor. Such questions may directly challenge an opinion that you have just stated or say something negative about you or a reference. Sometimes they ask seemingly irrelevant questions such as,

 

"If you were an animal, what type of animal would you be?"

 

The best way to deal with this type of question is to recognize what is happening. The interviewer is trying to elicit a reaction from you. Stay calm, and do not become defensive. If humor comes naturally to you, you might try using it in your response, but it is important to respond to the question. What you say is not nearly as important as maintaining your composure.

 

Example: "Which do you like better, Lions or Tigers?"

 

"Oh, lions definitely. They appear so majestic and are very sociable. To be honest, I think that seeing The Lion King four times has probably contributed to this!"

Java , applet , swing Interview quesions with answers

1]Which declaration of the main method below would allow a class to be started as a standalone program. Select the one correct answer.
a)    public static int main(char args[])
b)    public static void main(String args[])
c)    public static void MAIN(String args[])
d)    public static void main(String args)
e)    public static void main(char args[])
What all gets printed when the following code is compiled and run? Select the three correct answers.
public class xyz {
   public static void main(String args[]) {
      for(int i = 0; i < 2; i++) {
         for(int j = 2; j>= 0; j--) {
            if(i == j) break;
            System.out.println("i=" + i + " j="+j);
         }      }   } }
a)    i=0 j=0
b)    i=0 j=1
c)    i=0 j=2
d)    i=1 j=0
e)    i=1 j=1
f)    i=1 j=2
g)    i=2 j=0
h)    i=2 j=1
i)    i=2 j=2
What gets printed when the following code is compiled and run with the following command -
java test 2      Select the one correct answer.
public class test {
   public static void main(String args[]) {
      Integer intObj=Integer.valueOf(args[args.length-1]);
      int i = intObj.intValue();
      if(args.length > 1)
         System.out.println(i);
      if(args.length > 0)
         System.out.println(i - 1);
      else
         System.out.println(i - 2);
   }}
a)    test
b)    test -1
c)    0
d)    1
e)    2
In Java technology what expression can be used to represent number of elements in an array named arr ?
How would the number 5 be represented in hex using up-to four characters.
Which of the following is a Java keyword. Select the four correct answers.
a)    extern
b)    synchronized
c)    volatile
d)    friend
e)    friendly
f)    transient
g)    this
h)    then
Is the following statement true or false. The constructor of a class must not have a return type.
a)    true             b)false
What is the number of bytes used by Java primitive long. Select the one correct answer.
a)    The number of bytes is compiler dependent.
b)    2
c)    4
d)    8
e)    64
What is returned when the method substring(2, 4) is invoked on the string "example"? Include the answer in quotes as the result is of type String.

Which of the following is correct? Select the two correct answers.
a)    The native keyword indicates that the method is implemented in another language like C/C++.
b)    The only statements that can appear before an import statement in a Java file are comments.
c)    The method definitions inside interfaces are public and abstract. They cannot be private or protected.
d)    A class constructor may have public or protected keyword before them, nothing else.

What is the result of evaluating the expression 14 ^ 23. Select the one correct answer.
a)    25        37     6     31     17     9     24

11] Which of the following are true. Select the one correct answers.
a)    && operator is used for short-circuited logical AND.
b)    ~ operator is the bit-wise XOR operator.
c)    | operator is used to perform bitwise OR and also short-circuited logical OR.
d)    The unsigned right shift operator in Java is >>.

Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class.

Which of the following is true. Select the two correct answers.
a)    A class that is abstract may not be instantiated.
b)    The final keyword indicates that the body of a method is to be found elsewhere. The code is written in non-Java language, typically in C/C++.
c)    A static variable indicates there is only one copy of that variable.
d)    A method defined as private indicates that it is accessible to all other classes in the same package.

14] What all gets printed when the following program is compiled and run. Select the two correct answers.
public class test {
   public static void main(String args[]) {
      int i, j=1;
      i = (j>1)?2:1;
      switch(i) {
        case 0: System.out.println(0); break;
        case 1: System.out.println(1);
        case 2: System.out.println(2); break;
        case 3: System.out.println(3); break;
      }       }    }
a)    0     1     2     3

15] What all gets printed when the following program is compiled and run. Select the one correct answer.
public class test {
   public static void main(String args[]) {
      int i=0, j=2;
      do {
         i=++i;
         j--;
      } while(j>0);
      System.out.println(i);
   }}
   a) 0         1     2    The program does not compile because of statement "i=++i;"
 
16]What all gets printed when the following gets compiled and run. Select the three correct answers.
public class test {
    public static void main(String args[]) {
        int i=1, j=1;
        try {
            i++;
            j--;
            if(i/j > 1)
                i++;
        }
        catch(ArithmeticException e) {
            System.out.println(0);
        }
        catch(ArrayIndexOutOfBoundsException e) {
            System.out.println(1);
        }
        catch(Exception e) {
            System.out.println(2);
        }
        finally {
            System.out.println(3);
        }
        System.out.println(4);
     }    }
 
a)    0     1     2     3     4
 17] What all gets printed when the following gets compiled and run. Select the two correct answers.
public class test {
    public static void main(String args[]) {
        int i=1, j=1;
        try {
            i++;
            j--;
            if(i == j)
                i++;
        }
        catch(ArithmeticException e) {
            System.out.println(0);
        }
        catch(ArrayIndexOutOfBoundsException e) {
            System.out.println(1);
        }
        catch(Exception e) {
            System.out.println(2);
        }
        finally {
            System.out.println(3);
        }
        System.out.println(4);
     }    }
a)    0     1     2     3     4
What all gets printed when the following gets compiled and run. Select the two correct answers.

public class test {
    public static void main(String args[]) {
    String s1 = "abc";
    String s2 = "abc";
    if(s1 == s2)
        System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }    }

a)    1
b)    2
c)    3
d)    4
19]What all gets printed when the following gets compiled and run. Select the two correct answers.
public class test {
    public static void main(String args[]) {
    String s1 = "abc";
    String s2 = new String("abc");
    if(s1 == s2)
        System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }  }      
a)    1
b)    2
c)    3
d)    4

20] Which of the following are legal array declarations. Select the three correct answers.
int i[5][];
int i[][];
int []i[];
int i[5][5];
int[][] a;

21]What is the range of values that can be specified for an int. Select the one correct answer.
a)    The range of values is compiler dependent.
b)    -231 to 231 - 1
c)    -231-1 to 231
d)    -215 to 215 - 1
e)    -215-1 to 215

How can you ensure that the memory allocated by an object is freed. Select the one correct answer.
a)    By invoking the free method on the object.
b)    By calling system.gc() method.
c)    By setting all references to the object to new values (say null).
d)    Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object.

23]What gets printed when the following code is compiled and run. Select the one correct answer.
public class test {
    public static void main(String args[]) {
    int i = 1;
    do {
        i--;
    } while (i > 2);
    System.out.println(i);
    }
 }
a)    0
b)    1
c)    2
d)    -1

24]Which of these is a legal definition of a method named m assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.
a)    void m() throws IOException{}
b)    void m() throw IOException{}
c)    void m(void) throws IOException{}
d)    m() throws IOException{}
e)    void m() {} throws IOException

25] Which of the following are legal identifier names in Java. Select the two correct answers.
a)    %abcd
b)    $abcd
c)    1abcd
d)    package
e)    _a_long_name

At what stage in the following method does the object initially referenced by s becomes available for garbage collection. Select the one correct answer.
void method X()  {
    String r = new String("abc");
    String s = new String("abc");
    r = r+1; //1
    r = null; //2
    s = s + r; //3
} //4
a)    Before statement labeled 1
b)    Before statement labeled 2
c)    Before statement labeled 3
d)    Before statement labeled 4
e)    Never.

27]String s = new String("xyz"); Assuming the above declaration, which of the following statements would compile. Select the one correct answer.
a)    s = 2 * s;
b)    int i = s[0];
c)    s = s + s;
d)    s = s >> 2;
e)    None of the above.

28]Which of the following statements related to Garbage Collection are correct. Select the two correct
a)    It is possible for a program to free memory at a given time.
b)    Garbage Collection feature of Java ensures that the program never runs out of memory.
c)    It is possible for a program to make an object available for Garbage Collection.
d)    The finalize method of an object is invoked before garbage collection is performed on the object.

29]If a base class has a method defined as --void method() { }
Which of the following are legal prototypes in a derived class of this class. Select the two correct answers.
a)    void method() { }
b)    int method() { return 0;}
c)    void method(int i) { }
d)    private void method() { }

30] In which all cases does an exception gets generated. Select the two correct answers.
a)    int i = 0, j = 1;
b)    if((i == 0) || (j/i == 1))
c)    if((i == 0) | (j/i == 1))
d)    if((i != 0) && (j/i == 1))
e)    if((i != 0) & (j/i == 1))

31] Which of the following statements are true. Select the two correct answers.
a)    The wait method defined in the Thread class, can be used to convert a thread from Running state to Waiting state.
b)    The wait(), notify(), and notifyAll() methods must be executed in synchronized code.
c)    The notify() and notifyAll() methods can be used to signal and move waiting threads to ready-to-run state.
d)    The Thread class is an abstract class.

Which keyword when applied on a method indicates that only one thread should execute the method at a time. Select the one correct answer.
a)    transient
b)    volatile
c)    synchronized
d)    native
e)    static
f)    final

What is the name of the Collection interface used to represent elements in a sequence (in a particular order). Select the one correct answer.
a)    Collection
b)    Set
c)    List
d)    Map

34]Which of these classes implement the Collection interface SortedMap. Select the one correct answers.
a)    HashMap
b)    Hashtable
c)    TreeMap
d)    HashSet
e)    TreeSet
f)    Vector

35]Which of the following are true about interfaces. Select the two correct answers.
a)    Methods declared in interfaces are implicitly private.
b)    Variables declared in interfaces are implicitly public, static, and final.
c)    An interface can extend any number of interfaces.
d)    The keyword implements indicate that an interface inherits from another.

Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C). Select the one correct answer.
a)    test();
b)    super.test();
c)    super.super.test();
d)    ::test();
e)    C.test();
f)    It is not possible to invoke test() method defined in C from a method in A.

37]What is the return type of method round(double d) defined in Math class.

38]What gets written on the screen when the following program is compiled and run. Select one right ans
public class test {
   public static void main(String args[]) {
   int i;
   float  f = 2.3f;
   double d = 2.7;
   i = ((int)Math.ceil(f)) * ((int)Math.round(d));
   System.out.println(i);
   } }
a)    4
b)    5
c)    6
d)    6.1
e)    9
39]Is the following statement true or false. As the toString method is defined in the Object class, System.out.println can be used to print any object.
a)    true      false
40] Which of these classes defined in java.io and used for file-handling are abstract. Select two correct ans a)    InputStream
b)    PrintStream
c)    Reader
d)    FileInputStream
e)    FileWriter
41]Name the collection interface used to represent collections that maintain unique elements.
42]What is the result of compiling and running the following program.

public class test {
   public static void main(String args[]) {
      String str1="abc";
      String str2="def";
      String str3=str1.concat(str2);

      str1.concat(str2);
      System.out.println(str1);
   }
}


a)    abc
b)    def
c)    abcabc
d)    abcdef
e)    defabc
f)    abcdefdef

43]Select the one correct answer. The number of characters in an object of a class String is given by
a)    The member variable called size
b)    The member variable called length
c)    The method size() returns the number of characters.
d)    The method length() returns the number of characters.

Select the one correct answer. Which method defined in Integer class can be used to convert an Integer object to primitive int type.
a)    valueOf
b)    intValue
c)    getInt
d)    getInteger

45]Name the return type of method hashCode() defined in Object class, which is used to get the unique hash value of an Object.

46]Which of the following are correct. Select the one correct answer.
a)    An import statement, if defined, must always be the first non-comment statement of the file.
b)    private members are accessible to all classes in the same package.
c)    An abstract class can be declared as final.
d)    Local variables cannot be declared as static.

Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class. Select the one correct answer.
a)    static
b)    final
c)    abstract
d)    native
e)    volatile
f)    transient

48]Which of these are core interfaces in the collection framework. Select the one correct answer.
a)    Tree
b)    Stack
c)    Queue
d)    Array
e)    LinkedList
f)    Map
 
Which of these statements are true. Select the two correct answers.
a)    For each try block there must be at least one catch block defined.
b)    A try block may be followed by any number of finally blocks.
c)    A try block must be followed by at least one finally or catch block.
d)    If both catch and finally blocks are defined, catch block must precede the finally block.

==================================================================================================
The remaining questions are related to AWT, event classes, and layout managers. These topics are not included in 1.4 version of the exam.


The default layout manager for a Frame is ...
a)    FlowLayout
b)    BorderLayout
c)    GridLayout
d)    GridBagLayout
e)    CardLayout

51]Which of the following are valid adapter classes in Java. Select the two correct answers.
a)    ComponentAdapter
b)    ActionAdapter
c)    AdjustmentAdapter
d)    ItemAdapter
e)    FocusAdapter

52]Which method defined in the EventObject class returns the Object that generated an event. The method should be given in the format - return_type method_name();

Which of the following object receives ActionEvent. Select the four correct answers.
a)    List
b)    Button
c)    Choice
d)    CheckBox
e)    TextField
f)    MenuItem

54]Name the class that may be used to create submenus in pull-down menus.

55]In which class is the wait() method defined. Select the one correct answer.
a)    Applet
b)    Runnable
c)    Thread
d)    Object

Which is the only layout manager that always honors the size of a component. Select the one correct answer.
a)    FlowLayout
b)    GridLayout
c)    BorderLayout
d)    CardLayout
e)    GridBagLayout

Which of these are valid Event Listener interfaces. Select the two correct answers.
a)    MouseMotionListener
b)    WindowListener
c)    DialogListener
d)    PaintListener

58]Which abstract class is the super class of all menu-related classes.

Answers to Sample Test 1

1)    b
2)    b, c, f
3)    d. Note that the program gets one command line argument - 2. args.length will get set to 1. So the condition if(args.length > 1) will fail, and the second check if(args.length > 0) will return true.
4)    arr.length
5)    4]Any of these is correct - 0x5, 0x05, 0X05, 0X5
6)    b, c, f, g
7)    a
8)    d
9)    "am"
10)    a, c. Please note that b is not correct. A package statement may appear before an import statement. A class constructor may be declared private also. Hence d is incorrect.
11)    a
12)    a
13)    12]protected
14)    a, c
15)    b, c
16)    c
17)    a, d, e
18)    d, e
19)    18]a, c
20)    b, c
21)    20]b, c, e
22)    b
23)    d
24)    23]a
25)    a
26)    b, e . The option c is incorrect because a Java identifier name cannot begin with a digit.
27)    26]d
28)    c
29)    c, d
30)    a, c
31)    30]b, d
32)    b, c
33)    c
34)    c
35)    c
36)    35]b, c
37)    f
38)    long
39)    e
40)    a
41)    a, c
42)    41]Set
43)    a
44)    d
45)    b
46)    45]int
47)    d
48)    a
49)    f
50)    c, d
51)    50]b
52)    a, e
53)    Object getSource();
54)    a, b, e, f
55)    Menu
56)    d
57)    a
58)    a, b
59)    MenuComponent

Mock Exam 2
Which of the following are Java keywords? Select the three correct answers.
a)    external
b)    implement
c)    throw
d)    void
e)    integer
f)    private
g)    synchronize
h)    unsigned


Which of the following are legal definitions of the main method that can be used to execute a class. Select the one correct answer.
a)    public void main(String args)
b)    public static int main(String args[])
c)    public static void main(String args[])
d)    static public void MAIN(String args[])
e)    public static void main(string args[])
f)    public static void main(String *args)


Which of these are legal array declarations or definitions? Select the two correct answers.
a)    int[] []x[];
b)    int *x;
c)    int x[5];
d)    int[] x = {1,2,3};


Name the collection interface used to represent a sequence of numbers in a fixed order.


The class Hashtable is used to implement which collection interface. Select the one correct answer.
a)    Table
b)    List
c)    Set
d)    SortedSet
e)    Map


What gets printed when the following program is compiled and run? Select the one correct answer.


class test {
    public static void main(String args[]) {
        int i;
        do {
            i++;
        }
        while(i < 0);
        System.out.println(i);
    }
}


a)    The program does not compile as i is not initialized.
b)    The program compiles but does not run.
c)    The program compiles and runs but does not print anything.
d)    The program prints 0.
e)    The program prints 1.


What gets printed when the following program is compiled and run? Select the one correct answer.

class xyz {
    static int i;
    public static void main(String args[]) {

        while (i < 0) {
            i--;
        }
        System.out.println(i);
    }
}


a)    The program does not compile as i is not initialized.
b)    The program compiles but does not run.
c)    The program compiles and runs but does not print anything.
d)    The program prints 0.
e)    The program prints 1.


What gets printed when the following program is compiled and run? Select the one correct answer.

class xyz {
 
    public static void main(String args[]) {
        int i,j,k;
        for (i = 0; i < 3; i++) {
            for(j=1; j < 4; j++) {
                for(k=2; k<5; k++) {
                    if((i == j)   && (j==k))
                        System.out.println(i);
                }               
            }
        }
    }
}


a)    0
b)    1
c)    2
d)    3
e)    4


Using up to four characters what is the Java representation of the number 23 in hex?


What gets printed when the following program is compiled and run? Select the one correct answer.

class test {
    static boolean check;
    public static void main(String args[]) {
        int i;
        if(check == true)
            i=1;
        else
            i=2;

        if(i=2) i=i+2;
        else i = i + 4;
        System.out.println(i);
     }
}


a)    3
b)    4
c)    5
d)    6
e)    The program does not compile because of the statement if(i=2)


Select the one correct answer. The smallest number that can be represented using short primitive type in Java is -
a)    0
b)    -127
c)    -128
d)    -16384
e)    -32768
f)    The smallest number is compiler dependent.


Given the following declarations, which of the assignments given in the options below would compile. Select the two correct answers.

a)    int i = 5;
b)    boolean t = true;
c)    float f = 2.3F;
d)    double d = 2.3;


e)    t = (boolean) i;
f)    f = d;
g)    d = i;
h)    i = 5;
i)    f = 2.8;


What gets printed when the following program is compiled and run. Select the one correct answer.

public class incr {
    public static void main(String args[]) {
        int i , j;
        i = j = 3;
        int n = 2 * ++i;
        int m = 2 * j++;
        System.out.println(i + " " + j + " " + n + " " + m);
    }
}


a)    4 4 8 6
b)    4 4 8 8
c)    4 4 6 6
d)    4 3 8 6
e)    4 3 8 8
f)    4 4 6 8


Given two non-negative integers a and b and a String str, what is the number of characters in the expression str.substring(a,b) . Select the one correct answer.
a)    a + b
b)    a - b
c)    b - a - 1
d)    b - a + 1
e)    b - a
f)    b


What is the result of compiling and running the following program. Select the one correct answer.

class test {
    public static void main(String args[]) {
        char ch;
        String test2 = "abcd";
        String test = new String("abcd");
        if(test.equals(test2)) {
            if(test == test2)
                ch = test.charAt(0);
            else
                ch = test.charAt(1);              
        }
        else {
            if(test == test2)
                ch = test.charAt(2);
            else               
                ch = test.charAt(3);
        }
        System.out.println(ch);
    }
}


a)    'a'
b)    'b'
c)    'c'
d)    'd'


What is the result of compiling and running the following program. Select the one correct answer.

class test {
    public static void main(String args[]) {
     int i,j=0;
     for(i=10;i<0;i--) { j++; }
     switch(j) {
     case (0) :
         j=j+1;
     case(1):
         j=j+2;
         break;
     case (2) :
         j=j+3;
         break;
    
     case (10) :
         j=j+10;
         break;
     default :
         break;
     }
   System.out.println(j);
   }
}


a)    0
b)    1
c)    2
d)    3
e)    10
f)    20


What is the number displayed when the following program is compiled and run.

class test {
    public static void main(String args[]) {
        test test1 = new test();
            System.out.println(test1.xyz(100));   
    }
    public int xyz(int num) {
        if(num == 1) return 1;
        else return(xyz(num-1) + num);
    }
}




Which of the following statements are true. Select the one correct answer.
a)    Arrays in Java are essentially objects.
b)    It is not possible to assign one array to another. Individual elements of array can however be assigned.
c)    Array elements are indexed from 1 to size of array.
d)    If a method tries to access an array element beyond its range, a compile warning is generated.


Which expression can be used to access the last element of an array. Select the one correct answer.
a)    array[array.length()]
b)    array[array.length() - 1]
c)    array[array.length]
d)    array[array.length - 1]


What is the result of compiling and running the following program. Select the one correct answer.

class test {
    public static void main(String args[]) {
        int[] arr = {1,2,3,4};
        call_array(arr[0], arr);
        System.out.println(arr[0] + "," + arr[1]);       
    }
    static void call_array(int i, int arr[]) {
        arr[i] = 6;
        i = 5;
    }   
}


a)    1,2
b)    5,2
c)    1,6
d)    5,6


Which of the following statements are correct. Select the one correct answer.
a)    Each Java file must have exactly one package statement to specify where the class is stored.
b)    If a Java file has both import and package statement, the import statement must come before package statement.
c)    A Java file has at least one class defined.
d)    If a Java file has a package statement, it must be the first statement (except comments).


What happens when the following program is compiled and then the command "java check it out" is executed. Select the one correct answer.

class check {
    public static void main(String args[]) {
        System.out.println(args[args.length-2]);
    }
}


a)    The program does not compile.
b)    The program compiles but generates ArrayIndexOutOfBoundsException exception.
c)    The program prints java
d)    The program prints check
e)    The program prints it
f)    The program prints out


What all gets printed when the following code is compiled and run. Select the three correct answers.

class test {
    public static void main(String args[]) {
        int i[] = {0,1};
        try {
            i[2] = i[0] + i[1];
        }
        catch(ArrayIndexOutOfBoundsException e1) {
            System.out.println("1");
        }
        catch(Exception e2) {
            System.out.println("2");
        }
        finally {
            System.out.println(3);
        }
        System.out.println("4"); 
     }
}


a)    1
b)    2
c)    3
d)    4


A program needs to store the name, salary, and age of employees in years. Which of the following data types should be used to create the Employee class. Select the three correct answers.
a)    char
b)    boolean
c)    Boolean
d)    String
e)    int
f)    double


To make a variable defined in a class accessible only to methods defined in the classes in same package, which of the following keyword should be used. Select the one correct answer.
a)    By using the keyword package before the variable.
b)    By using the keyword private before the variable.
c)    By using the keyword protected before the variable.
d)    By using the keyword public before the variable.
e)    The variable should not be preceded by any of the above mentioned keywords.


In implementing two classes Employee and Manager, such that each Manager is an Employee, what should be the relationship between these classes. Select the one correct answer.
a)    Employee should be the base class of Manager class.
b)    Manager should be the base class of Employee class.
c)    Manager class should include the Employee class as a data member.
d)    Employee class should include Manager class as a data member.
e)    The Manager and Employee should not have any relationship.


Select the one most appropriate answer. What is the purpose of method parseInt defined in Integer class.
a)    The method converts an integer to a String.
b)    The method is used to convert String to an integer, assuming that the String represents an integer.
c)    The method is used to convert String to Integer class, assuming that the String represents an integer.
d)    The method converts the Integer object to a String.


What should be done to invoke the run() method on a thread for an object derived from the Thread class. Select the one correct answer.
a)    The run() method should be directly invoked on the Object.
b)    The start() method should be directly invoked on the Object.
c)    The init() method should be directly invoked on the Object.
d)    The creation of the object using the new operator would create a new thread and invoke its run() method.


What is the default priority of a newly created thread.
a)    MIN_PRIORITY (which is defined as 1 in the Thread class.)
b)    NORM_PRIORITY (which is defined as 5 in the Thread class.)
c)    MAX_PRIORITY (which is defined as 10 in the Thread class.)
d)    A thread inherits the priority of its parent thread.
The remaining questions are from AWT and related topics, and are not relevant for SCJP 1.4 .


Which of following correctly describes the functionality of the method drawRect(int a, int b, int c, int d) defined in jawa.awt.Graphics class. Select the one correct option.
a)    Draws the outline of a rectangle with a, b being the x,y co-ordinates of top left corner, and c,d being the x,y co-ordinates of the bottom right corner.
b)    Draws the outline of a rectangle with a, b being the x,y co-ordinates of top left corner, and c,d being the width and height of the rectangle.
c)    Draws a filled rectangle with a, b being the x,y co-ordinates of top left corner, and c,d being the x,y co-ordinates of the bottom right corner.
d)    Draws a filled rectangle with a, b being the x,y co-ordinates of top left corner, and c,d being the width and height of the rectangle.


Which Listener interface must be implemented by a class responsible for handling mouse clicks on buttons?


The getSource method defined in the EventObject class returns the source of an event. What is the return type of this getSource method?
a)    EventObject
b)    Event
c)    Object
d)    Component
e)    Button


The focusLost method is defined in FocusListener interface and is executed when a control loses focus. What is the argument of focusLost method?


Which of the following is the super class of these classes - ContainterEvent, FocusEvent, InputEvent, PaintEvent, WindowEvent. Select the one correct answer.
a)    ActionEvent
b)    AdjustmentEvent
c)    ComponentEvent
d)    ItemEvent
e)    TextEvent
f)    Event


Which of these are adapter classes. Select the three correct answers.
a)    ComponentAdapter
b)    ItemAdapter
c)    ActionAdapter
d)    KeyAdapter
e)    ContainerAdapter


Which of the following statements about layout managers is true. Select the one correct answer.
a)    FlowLayout places components left-aligned in a row (by default) and when there is no space in a row, another row is started.
b)    FlowLayout provides a constructor Flowlayout(int align, int x, int y), where x and y are the coordinates of the first component being added.
c)    The FlowLayout is the default layout manager for Window class
d)    Default horizontal and vertical gaps of components placed using FlowLayout is 5 pixels.


Which of the following is true about BorderLayout. Select the two correct answers.
a)    The default layout manager for Applet class is BorderLayout.
b)    BorderLayout places components in North, South, East and West first and then the remaining space is occupied by the Center component.
c)    When a component is added in BorderLayout using the add method, it is placed in the center by default.
d)    The BorderLayout always honors the size of components provided by the program.


Which of these is true about the GridBagLayout. Select the one correct answer.
a)    The weightx and weighty fields of GridBagConstraints specify how many column and rows each component occupies.
b)    The gridwidth and gridheight constraints of GridBagConstraints specify the width and height in pixels of each cell.
c)    GridBagLayout is the default layout manager of the Frame class.
d)    The gridx and gridy parameters of GridBagConstraints define the column and row position of the upper left corner of the component.




Answers to Sample Test 2


1)    c, d, f
2)    c. The main method must be static and return void. Hence a and b are incorrect. It must take an array of String as argument. Hence e and f are incorrect. As Java is case sensitive, d is incorrect.
3)    a, d
4)    List
5)    e. The collection interface Map has two implementation HashMap and Hashtable.
6)    Local variables are not initialized by default. They must be initialized before they are used.
7)    d. The variable i gets initialized to zero. The while loop does not get executed.
8)    During various iterations of three loops, the only time i, j and k have same values are when all of them are set to 2.
9)    0x17 or 0X17.
10)    e. The statement "i=2" evaluates to 2. The expression within the if block must evaluate to a boolean.
11)    e. The range of short primitive type is -32768 to 32767.
12)    c,d. Java does not allow casts between boolean values and any numeric types. Hence a is incorrect. Assigning double to a float requires an explicit cast. Hence b and e are incorrect.
13)    a
14)    e
15)    Both Strings test and test2 contain "abcd" . They are however located at different memory addresses. Hence test == test2 returns false, and test.equals(test2) returns true.
16)    The for loop does not get executed even once as the condition (i < 0) fails in the first iteration. In the switch statement, the statement j = j +1; gets executed, setting j to 1. As there is no break after this case, the next statement also gets executed setting j to 3.
17)    5050. The recursive function xyz essentially sums up numbers 1 to num. This evaluates to (num * (num + 1))/2.
18)    Java supports assignment of one array to another. Hence b is incorrect. Array elements are indexed from 0. Hence c is incorrect. A method that accesses array elements out of its range does not generate a compilation error. Hence d is incorrect.
19)    array.length gives the number of elements in the array. As indexes in Java start from 0, d is the correct answer.
20)    In the invocation of call_array, the first element is invoked using call-by-value, and the second using call-by-reference.
21)    import statement, package statement and class definitions are all optional in a file. Hence a and c are incorrect. If both import and package statements are present in a file, then package statement must appear before the import statement. Hence b is incorrect.
22)    The args array consists of two elements "it" and "out". args.length is set to two.
23)    a,c,d. The exception ArrayIndexOutOfBoundsException is generated as the main method tries to access i[2]. Hence 1 gets printed. After this finally block gets excuted, before the program exits.
24)    d,e,f
25)    A data member that does not have public/protected/private is accessible to all methods in the same package.
26)    The Manager and Employee share as "is a" relationship - A Manager is an Employee. This is captured by making Employee the base class of Manager.
27)    The method int parseInt(Sting s) returns the integer value corresponding to input String, assuming that the input string represents an integer in base 10.
28)    The start() method invokes the run() method when the thread is ready to execute.
29)    d
30)    b. drawRect method draws the outline of a rectangle. The last two arguments are width and height of the rectangle.
31)    ActionListener
32)    The getSource method returns a reference to the object where the event initially occurred.
33)    FocusEvent. A class implementing FocusListener interface must implement the following method -
34)    public void focusLost(FocusEvent)
35)    public void focusGained(FocusEvent)

36)    c
37)    a,d,e. There are no adapter classes corresponding to the following interfaces - ActionListener, ItemListener, AdjustmentListener, and TextListener.
38)    The default alignment for FlowLayout is CENTER. Hence a is incorrect. The default Layout Manager for Window class is BorderLayout. Hence c is incorrect. X and y in option b indicate horizontal and vertical gaps between components.
39)    b,c. The default Layout Manager for Applet class is FlowLayout. Hence a is incorrect. BorderLayout grows all components to fill the space available. Hence d is incorrect.
40)    d. The weightx and weighty specify how the size of a cell should change when the container exceeds the preferred size of component. Hence a is not correct. gridwidth and gridheight specify how many columns and rows the component specifies. So b is incorrect. BorderLayout is the default layout manager for Frame class.
home | tutorial | questions | test 1  Questions on Classes

What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.

protected class example {
    public static void main(String args[]) {
        String test = "abc";
        test = test + test;
        System.out.println(test);
    }
}


a)    The class does not compile because the top level class cannot be protected.
b)    The program prints "abc"
c)    The program prints "abcabc"
d)    The program does not compile because statement "test = test + test" is illegal.
A top level class may have only the following access modifier. Select the one correct answer.
a)    package
b)    friendly
c)    private
d)    protected
e)    public
Write down the modifier of a method that makes the method available to all classes in the same package and to all the subclasses of this class.
Select the one most appropriate answer. A top level class without any modifier is accessible to -
a)    any class
b)    any class within the same package
c)    any class within the same file
d)    any subclass of this class.
Is this True or False. In Java an abstract class cannot be sub-classed.
Is this True or False. In Java a final class must be sub-classed before it can be used.
Which of the following are true. Select the three correct answers.
a)    A static method may be invoked before even a single instance of the class is constructed.
b)    A static method cannot access non-static methods of the class.
c)    Abstract modifier can appear before a class or a method but not before a variable.
d)    final modifier can appear before a class or a variable but not before a method.
e)    Synchronized modifier may appear before a method or a variable but not before a class.
Answers to questions on classes in Java

1)    a
2)    e
3)    protected
4)    b
5)    False
6)    False
7)    a, b, c. final modifier may appear before a method, a variable or before a class.


Questions on AWT
This topic is part of SCJP 1.2 exam but not SCJP 1.4 exam.
Which of the following classes are derived from the Container class. Select the four correct answers.
a)    Component
b)    Panel
c)    java.applet.Applet
d)    Dialog
e)    Frame
f)    MenuComponent
Which of the following classes are derived from the Component class. Select the four correct answers.
a)    Container
b)    Window
c)    List
d)    MenuItem
e)    Choice
Name the class used to represent a GUI application window, which is optionally resizable and can have a title bar, an icon, and menus. Select the one correct answer.
a)    Window
b)    Panel
c)    Dialog
d)    Frame
Which abstract class is the super class of all menu related classes.
Which of these classes can be added to a Frame component. Select the three correct answers.
a)    Menu
b)    Button
c)    PopupMenu
d)    Window
e)    List
Which class can be used to represent a checkbox with a textual label that can appear in a menu. Select the one correct answer.
a)    MenuBar
b)    MenuItem
c)    CheckboxMenuItem
d)    Menu
e)    CheckBox
Which of these classes can be added to any Container class, using the add method defined in Container class. Select the two correct answers.
a)    Button
b)    CheckboxMenuItem
c)    Menu
d)    Canvas
Answers to questions on AWT

1)    b, c, d, e
2)    a, b, c, e
3)    d
4)    MenuComponent
5)    b, c, e
6)    c
7)    a, d


Questions on Collections

TreeMap class is used to implement which collection interface. Select the one correct answer.
a)    Set
b)    SortedSet
c)    List
d)    Tree
e)    SortedMap
Name the Collection interface implemented by the Vector class.
Name the Collection interface implemented by the Hashtable class.
Name the Collection interface implemented by the HashSet class.
Which of these are interfaces in the collection framework. Select the two correct answers.
a)    Set
b)    List
c)    Array
d)    Vector
e)    LinkedList
Which of these are interfaces in the collection framework. Select the two correct answers.
a)    HashMap
b)    ArrayList
c)    Collection
d)    SortedMap
e)    TreeMap
What is the name of collection interface used to maintain non-unique elements in order.
What is the name of collection interface used to maintain unique elements.
What is the name of collection interface used to maintain mappings of keys to values.
Is this true or false. Map interface is derived from the Collection interface.
a)    True
b)    False
Answers to questions on Collections

1)    e
2)    List
3)    Map
4)    Set
5)    a,b
6)    c,d
7)    List
8)    Set
9)    Map
10)    b
11)    Advertisement

March Mini Quiz
New to Java Programming Center
 
What is the intial layout manager of a JApplet?
  A.  FlowLayout
  B.  OverlayLayout
  C.  GridLayout
  D.  BorderLayout
  E.  AppletLayout



If you add a component to the content pane of a JApplet and don't specify any constraints, what happens to it?
  A.  The add method rejects the operation.
  B.  The add method adds the component to the container, but doesn't place it in any of the areas of the content pane.
  C.  The add method adds the component to the Center area of the pane.
  D.  There is no way to call add without any constraints.



Where can you place a JMenuBar in a Swing applet?
  A.  Top of applet
  B.  Left side of applet
  C.  Right side of applet
  D.  Bottom of applet
  E.  Any of the above



Should speed keys be used in applet menus?
  A.  Yes
  B.  No
  C.  It depends



Do I have to use the HTML Converter to add a Swing applet on my web page?
  A.  Yes
  B.  No


 
Java Technology Fundaments Newsletters
March Quiz Answers
(March 2003)
1. What is the intial layout manager of a JApplet? 
A is incorrect Answer (D): Even though you don't add components directly to a Swing applet, instead adding them to the content pane, the default layout manager of a JApplet really is BorderLayout.
 
2. If you add a component to the content pane of a JApplet and don't specify any constraints, what happens to it? 
A is incorrect Answer (C): When there are no constraints specified, a JApplet will place added components into the center area of the BorderLayout for its content pane.
 
3. Where can you place a JMenuBar in a Swing applet? 
B is incorrect Answer (E): While the setJMenuBar method will add a menu to the top of an applet, since JMenuBar is a component, it can be added anywhere that a component can be used. 
4. Should speed keys be used in applet menus? 
C is correct! Answer (C): While Swing permits menu items to have mnemonics associated with them, their use should probably be avoided, except where their usage is obvious. Speed keys only work when an applet has input focus. Thus, it may be confusing to the user to sometimes activate the menu associated with an applet and other times activate the menu associated wit the browser. 

 5. Do I have to use the HTML Converter to add a Swing applet on my web page?
A is incorrect Answer (B): Early versions of the Java Plugin required a tool called the HTML Converter to mangle the HTML that loaded a web page with the APPLET tag. Thankfully, that tool is no longer needed and you can use the APPLET tag directly, without the mangling.

Thursday, March 11, 2010

IBM ClearCase Commands


ClearCase Command
Description
Cleartool -ver
Display Clearcase, cleartool, db_server and VOB database schema version.
Cleartool lsvob
List vob mount table:
* /vob/VOB-NAME.vbt       /hosts/host-name/r1vob/vobs/vobstore/VOB-NAME.vbs public

  

  
* /vob/practice_vob.vbt  /hosts/host-name/view-name/Vobs/vobstore/practice_vob.vbs public
Cleartool dump element-or-DO
Print internal Clearcase info.
Cleartool lsview
List all views:
  millesc_view   /hosts/host-name/view-name/Views/millesc_view.vws

  

  
* user-name       /hosts/host-name/view-name/Views/reg_view.vws
Cleartool lsview view-tag
List view path.
cleartool mktag -view -tag dynamic-view-name -nstart /hosts/node-name/home/cleardata/views/dynamic-view-name
or
cleartool mktag -vob vob-tag ...
Create a view-tag or VOB-tag.
cleartool mkview -tag user1_view -stgloc viewstore
Create a new view in "viewstore" Clearcase server view mount point (see YoLinux client or server installation tutorial).
List view storage locations: ct lsstgloc
cleartool mkview -tag tmpA_view /hosts/node-name/home/cleardata/views/tmpA_view
Create a new view.
cleartool setview user-name_view
Set current view to user-name_view.
cleartool startview common_view
Set current view to common_view without starting a Clearcase shell environent. It allows one to view (only) the files. Path: /view/common_view/vob/vob-name/...
cleartool endview common_view
cleartool endview -server user-name_view
Deactivate a Clearcase view. (First exit view)
Useful if you get stale NFS handles.
cleartool rmview -tag temp_view
or
cleartool rmview temp_view
Remove view temp_view.
cleartool setview username_view
sv user-name_view
Set Clearcase view. See alias defined above.
cleartool pwv
Print working view/current view:
Working directory view: username_view

  

  
Set view: username_view
echo $CLEARCASE_ROOT
Print current view path.
cleartool ls -l
cleartool ls -vob_only
Using current view, show files, private files, file version and rule.
-vob_only: List elements and not derived objects
Format:
...

  

  
version              file.ext@@/main/2       Rule: element */main/LATEST

  

  
directory version    Directoy-name@@/main/2  Rule: element * /main/LATEST

  

  
view private object  file2.c

  

  
...
cleartool lstype -kind lbtype -list labels
List labels
cleartool lsvtree -all file-name.ext
List file version label and build label: (version tree)
file-name.ext@@/main

  

  
  file-name.ext@@/main/0

  

  
  file-name.ext@@/main/1 (BUILD_1_0)

  

  
  file-name.ext@@/main/2 (BUILD_1_1)
cleartool lsvtree -all pref*
List file version label and build label for files beginning with "pref"
cleartool lshistory [all] file-or-directory
cleartool lshistory file-name
List file or directory version history.
List event rocords for a given file.
cleartool chevent -c 'new-comment-goes-here' -replace -event event-id
cleartool chevent -c 'new-comment-goes-here' -replace -lbtype label
Change the comment on a version of an element.
Lookup event id: ct lsh -event file-or-element
Change the comment on a label.
cleartool lsco
cleartool lsco -r
cleartool lsco -avobs -me
cleartool lsco -avobs -cview
List all checked out files in current directory.
Flag "-r" recusivly looks in sub directories.
List all files checked out to all views.
List checkouts in view.
cleartool lscheckout -l
cleartool lsco -l
cleartool lsco -recursive -me -cview
List checked out files.
(same)
List files in current directory and subdirectories checked out to you in current view. Omit -cview tag to get all.
cleartool catcr file-name
List configuration record for a file.
cleartool find ./ -branch 'brtype(branch-name)' -print
cleartool find ./ -version(main/LATEST) && \! version(LABEL_X)' -print
cleartool find -avobs -nxname -element 'brtype(view_name)' -print
List files in branch with search name or attribute.
List files with label "LATEST" but not LABEL_X.
cleartool lsprivate
cleartool lsp -co
List all private files in current view. View private files are files residing in the Clearcase filesystem but not under the control of Clearcase. i.e. object files as a result of a compile. May not be viewable by others.
List files checked out to current view.
cleartool mklbtype -nc LABEL_NAME
cleartool mklbtype -c "comment" LABEL_NAME
Create a label to be used later.
cleartool lstype -kind lbtype -short | sort
List labels.
Cleartool describe -l file.ext
Describe object in VOB. Lists branch and version of file and configspec used in view.
Cleartool describe file-or-directory
List file or directory information.
cleartool describe -long element:file-or-directory
List file or directory information.
Cleartool describe -long vob:/vob
List vob information.
cleartool mklabel LABEL_NAME file-name.ext
cleartool mklabel -r LABEL_NAME
Apply label to a file.
Label elements in directory tree.
cleartool mklabel -replace NEW_LABEL_NAME file-name.ext@@/main/4
Apply label to a newer version of the file.
cleartool rmtype -rmall -force lbtype:LABEL_NAME
cleartool rmtype -lbtype -rmall LABEL_NAME
Remove a label of the name given. The option "-rmall" causes the removal of all instances of the label on all files / directories.Remove label type and all occurrences of the label.
Cleartool rmtype lbtype:LABEL_NAME
Remove label from Clearcase. It will not be removed if label has been applied. Use option "-rmall" to remove label and all instances of its application.
Cleartool rmtype -rmall -brtype branch-type
Remove branch and all files / directories in branch from Clearcase. Data disposed in "lost-found".
cleartool find -avobs -version "lbtype (Build-Label)" -print
cleartool find . -name '*.[hc]' -element 'lbtype_sub(LABEL_NAME)' -print
Print all files and file versions going into build specified.
list all .h and .c files whith the given label.
Cleartool co -nc file-name
Check-Out file (RCS command) -No Comment
Cleartool mkdir directory-name
Create a directory. Checkout parent directory first.
cleartool ln -s source-directory-name local-directory-name
Create a symbolic link to a directory. Checkout parent directory first.
Cleartool mkelem -ci -nc filename
Add file to Clearcase control.
Cleartool rmelem filename
Remove file from Clearcase control. All history and knowledge of the element is completely removed. By contrast, the "ct rm" command will remove the file and not the history and the directory must be checked out in order to make this change.
cleartool rmelem -rm filename
Remove file from Clearcase control and remove private view file.
cleartool rmelem directory-name/*
Remove directory, revision history and its contents from Clearcase control.
cleartool rmver filename@@/main/LATEST
or
cleartool rmver filename
or
cleartool rmver filename@@/main/22
or remove specifed version on main branch:
cleartool rmver -force -xlabel -ver /main/22 file-or-element-name
Remove latest version checked in of the file from Clearcase. Second example removes version 22 from the Clearcase change management system. Previous versions will be available from the archive.
cleartool rm filename
Remove file from Clearcase view. First perform a checkout ("ct co") of the file and directory. Past versions will be available from the archive although not visible in current view. Safer than "ct rmelem" which removes all knowledge of the file old and new.
cleartool reserve file-name
Lock file. Convert unreserved checkout to reserved.
cleartool unco file-name
cleartool unco -rm file-name
cleartool uncheckout file-name
UN-Check-Out file. Cancel a checkout of a file.
Cancel a checkout of a file and remove file which was checked out. Not removed from Clearcase, just view private the checked out file is deleted/cleaned up.
cleartool co -unr -nc file-name
Checkout file even though file is checked out by another. Checkout "unreserved", must be merged at a later time.
Cleartool checkout -unreserved file-name
Not locked. Checkout to read, print, etc. Same as above command.
Cleartool ci file-name
Check-In file. (also ct checkin file-name) Enter comment,enter "." as sole character on line and enter.
cleartool diff -gra -pre file-name &
cleartool diff -pred file-name
cleartool xdiff -pred file-name
Graphical Diff/Merge tool.
Clearcase diff between current file and predecessor.
X-windows diff with predecessor.
cleartool mv file-name_A file-name_B
Rename a file. Be sure to checkout the parent directory first. If moving file to a new directory, check out the target directory as well.
cleartool protect -r -chmod 775 directory-or-file-name
Set directory/file/element protection.
Configspec commands

cleartool catcs
cleartool catcs -tag view_tag
Print rules of current view (configspec):
element * CHECKEDOUT

  

  
element * /main/LATEST

Look at the configspec associated with another view.
cleartool edcs
Edit current rules of view (config spec):
Change from:
element * CHECKEDOUT

  

  
element * /main/LATEST
To:
element * Build-Label

  

  
element -directory * /main/Latest
Close vi: wq
Set config spec for view "username_view"? [yes]
cleartool setcs -default
cleartool setcs -cur
Reset to default view rules.
Re-evaluate current configspec.
cleartool update -add_loadrules
Updates elemets in snapshot view. GUI tool. Reevaluates config spec and reselects VOB elements to show. The option "-add_loadrules" allows you to load rules to your config spec and load elements which satisfy the rules.
Help and Information commands

cleartool man clearcase-command
cleartool man env_ccase
Man page for Clearcase command.
List Clearcase environment variables.
Cleartool apropos search-word
List commands and man page summaries for related Clearcase command.
cleartool help
cleartool help clearcase-command
Help facility (simple). Lists possible command arguments.
Tree/Branch commands

cleartool lstype -kind brtype
cleartool lstype -kind brtype -invob /vob/vob-name
List all branches.
List all branches in the vob specified.
cleartool find -avobs -version 'brtype(branch-type)' -print
Find all files of the specified branch name in all mounted VOB's. Find branch name with the ct lstype command..
cleartool lsvtree -all *
cleartool lsvtree file-name
cleartool lsvtree -g file-name
List version trees (labels and branches) of files (even those without labels or branches).
List all branches of specified file.
Launch GUI display and show version tree (labels and branches) for a given file.
(
[Potential Pitfall]: You may have to issue the command export LANG=C prior to launching GUI.)
cleartool chtype
Change element type or rename branch.
cleartool mkbranch
cleartool  mkbranch -nc branch-name file-to-branch.cpp
Create a new branch in version tree. Use the command mkbrtype to create the branch type (name) first. This command also checks out the file. The config spec needs to include this branch so file can be viewed.
cleartool rmbranch
Remove a branch in version tree.
cleartool mkbrtype
mkbrtype -c "Comment goes here" branch_name
Create a new branch type object.
Cleartool merge
Merge changes/differences of a file from another branch.
cleartool findmerge
cleartool findmerge ./ -flag VIEW-TAG -print
Determines whether a merge is required for a file in your view.
Find files in current directory tree which need to be merged. Use the describe command to see if branch has been merged. If so it wil be stated as such.