Genesis Insoft The name you can TRUST
twitterlogo facebooklogo
Home  |  Contact Us |  Careers
Java Question Bank / FAQs

This is a mock Exam based on the Objectives for the Sun Java Programmers Exam. It is created by Genesis InSoft Limited (admin@genesisinsoft.com) and may be freely distributed so long as it is unmodified. Please email us if you have any corrections or comments.

Question 1

Which of the following converts an array of bytes to an instance of class Class?

  1. toClass( )
  2. createClass()
  3. byteToClass()
  4. defineClass()

Answer to Question 1

Question 2

What is the general form of declaration for a method in Java?

  1. accessspecifier  modifier  returnvalue  name of method  (parameters)   throws  ExceptionList
  2. modifier  accessspecifier  returnvalue  name of method  (parameters)   throws  ExceptionList
  3. accessspecifier  returnvalue  modifier  name of method  (parameters)   throws  ExceptionList
  4. modifier  returnvalue  accessspecifier  name of method  (parameters)   throws  ExceptionList

Answer to Question 2

Question 3

What is the default Container layout combination  for a Panel?

  1. FlowLayout
  2. CardLayout
  3. BorderLayout
  4. GridLayout

Answer to Question 3

Question 4

________ a thread group is automatically destroyed when its last thread is stopped or its last 
thread group is destroyed.      

  1. Daemon
  2. Auto
  3. Default
  4. none

Answer to Question 4

Question 5

Which is the followig method returns the current number of active threads in this thread group

  1. currentCount()
  2. threadCount()
  3. activeCount()
  4. getActiveCount()

Answer to Question 5

Question 6

What is the output of the following code?

    int i = 16;
    int j = 17;
    System.out.println("i >> 1  =  " + (i >> 1));
    System.out.println("j >> 1  =  " + (j >> 1));

  1. Prints "i >> 1 = 8"
    "j >> 1 = 8"
  2. Prints "i >> 1 = 7"
    "j >> 1 = 7"
  3. Prints "i >> 1 = 8"
    "j >> 1 = 9"
  4. Prints "i >> 1 = 7"
    "j >> 1 = 8"

Answer to Question 6

Question 7

Which of the operators have the lowest precedence in Java Operators?

  1. Parentheses i.e [ ], ()
  2. Conditional i.e ?:
  3. Unary operators i.e +, -, ++, --
  4. Assignment Operator i.e =

Answer to Question 7

Question 8

1.    public class Q11{
2.        static String str1 = "main method with String[] args";
3.        static String str2 = "main method with int[] args";
4.        public static void main(String[] args){
5.            System.out.println(str1);
6.        }
7.        public static void main(int[] args){
8.            System.out.println(str2);
9.        }
10.  }

What will happen if you compile/run the following code?

  1. Duplicate method main(), compilation error at line 6.
  2. Duplicate method main(), compilation error at line 11.
  3. Prints "main method with main String[] args".
  4. Prints "main method with main int[] args".

Answer to Question 8

Question 9

    class Th22{
        public static void main(String args[ ]){
            int i = -333;
            int j = ~i;
            System.out.println(j);
        }
    }

The output of the above program is

  1. Compilation error . ~ operator applicable to boolean values only.
  2. Prints 333.
  3. Prints 332
  4. Prints 334

Answer to Question 9

Question 10

What is the output of the following code?

1.    class StringTest {
2.        public static void main(String args[ ]){
3.            String str = "Welcome";
4.            str.concat(" to Java!");
5.            System.out.println(str);
6.        }
7.    }

  1. Strings are immutable, compilation error at line 3.
  2. Strings are immutable, runtime exception at line 3.
  3. Prints "Welcome".
  4. Prints "Welcome to Java!".

Answer to Question 10

Question 11

Java archives (JAR files) can be used to improve the download speed of your applets.
What types of files can be stored in JAR archives?

  1. XML files
  2. BMP files
  3. Class files
  4. All of the above

Answer to Question 11

Question 12

What does the stop() internally do to stop a thread ?

  1. it calls the destroy() method of the Thread class.
  2. it calls the yield() method of the Thread class.
  3. it throws an instance of the ThreadDeath class.
  4. None of the above.

Answer to Question 12

Question 13

What is the only method available in the Runnable inteface ?

  1. start().
  2. stop().
  3. run().
  4. sleep().

Answer to Question 13

Question 14

What will happen if you compile/run the folowing lines of code?

    Vector a = new Vector();
    a.addElement(10);
    System.out.println(a.elementAt(0)); 

  1. Prints 10.
  2. Prints 11.
  3. Compilation error.
  4. Prints some garbage.

Answer to Question 14

Question 15

What will happen if you invoke the following method?

    public void check() {
        System.out.println(Math.min(-0.0,+0.0));
        System.out.println(Math.max(-0.0,+0.0));
        System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0));
    } 

  1. prints -0.0, +0.0 and false.
  2. prints -0.0, +0.0 and true.
  3. prints 0.0, 0.0 and false.
  4. prints 0.0, 0.0 and true.

Answer to Question 15

Question 16

    public class Test {
        //Some code comes here
    }

Which of the following can be used to define a constructor for this class?

  1. public void Test() {...}
  2. public Test() {...}
  3. public static Test() {...}
  4. public static void Test() {...}

Answer to Question 16

Question 17

What tags are mandatory when creating HTML to display an applet?

  1. name, height, width.
  2. code, name.
  3. codebase, height, width.
  4. code, height, width

Answer to Question 17

Question 18

Characters in java are based on which encoding scheme ?

  1. Unicode encoding scheme.
  2. ASCII / ANSI.
  3. UTF 8.
  4. None of the above.

Answer to Question 18

Question 19

    public class MyFor{
        public static void main(String argv[]){
            int i; int j;
            outer:for (i=1;i <3;i++){
                inner:for(j=1; j<3; j++) {
                    if (j==2)
                        continue outer;
                        System.out.println("Value for i=" + i + " Value for j=" +j);
                }
            }
        }
    }

What is the output of the above program?

  1. Value for i=1 value for j=1.
  2. Value for i=2 value for j=3.
  3. Value for i=2 value for j=2.
  4. Value for i=3 value for j=1

Answer to Question 19

Question 20

Which of the following technologies depend on the "Serialization" mechanism?

  1. JiniTM technology.
  2. JavaSpacesTM technology.
  3. RMI.
  4. All of the above

Answer to Question 20

Answers

Answer 1 - D

Back to question 1

Answer 2 - A

Back to question 2

Answer 3 - A

Back to question 3

Answer 4 - A

Back to question 4

Answer 5 - C

Back to question 5

Answer 6 - A

Back to question 6

Answer 7 - D

Back to question 7

Answer 8 - C

Back to question 8

Answer 9 - C

Back to question 9

Answer 10 - C

Back to question 10

Answer 11 - D

Back to question 11

Answer 12 - C

Back to question 12

Answer 13 - C

Back to question 13

Answer 14 - C

Back to question 14

Answer 15 - B

Back to question 15

Answer 16 - B

Back to question 16

Answer 17 - D

Back to question 17

Answer 18 - A

Back to question 18

Answer 19 - A,B

Back to question 19

Answer 20 - D

Back to question 20

Copyright © 2000 to 2024 Genesis InSoft Limited. All Rights Reserved.