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.

Question1

The combination of interpreter and compilation in Java is for?

  1. Security & robustness
  2. Faster execution
  3. Native code
  4. Platform independent byte code

Answer to Question 1

Question 2

What is the correct ordering for the import, class and package declarations when found in a single file?

  1. package, import, class
  2. class, import, package
  3. import, package, class
  4. package, class, import

Answer to Question 2

Question 3

Machine independent byte code is interpreted by

  1. Java interpreter
  2. Java compiler
  3. Java Virtual Machine
  4. Browser

Answer to Question 3

Question 4

Which of the following is platform dependent?

  1. Java virtual machine
  2. Java runtime compiler
  3. Java compiler
  4. All

Answer to Question 4

Question 5

What does the compareTo() method in the String class of Java do?

  1. Compares whether two strings are same and returns a boolean value.
  2. Compares the total number of characters in two given Strings and based on that returns a boolean value.
  3. Compares the given strings according to their Unicode values of the caharacters and returns an integer value.
  4. Compares whether the two strings are same but differ only in their cases i.e the first one is lower case and the second one is in uppercase or viceversa.

Answer to Question 5

Question 6

The four parts to the Java virtual machine are

  1. Stack, Queue, Registers and Method area
  2. Stack, Queue, Registers and garbage-collection heap
  3. Stack, Queue, Method area and garbage-collection heap
  4. Stack, Registers, garbage-collection heap and Method area

Answer to Question 6

Question 7

What is the return type of the following declaration?
    int value = 10;
    String.valueOf(value);

  1. 64k
  2. 32k
  3. 16k
  4. No limit

Answer to Question 7

Question 8

What is the output of the program?

    public class test {
        public static void main(String arg[]) {
            switch(0) {
                case 0: System.out.print("0");
                default:System.out.print("9");
                case 1:System.out.print("1");
            }
        }
    }

  1. No output
  2. 0 9
  3. 0 9 1
  4. Error: Default should be the last statement

Answer to Question 8

Question 9

StringTokenizer is a class of which package?  

  1. java.util
  2. java.io
  3. java.lang
  4. java.text

Answer to Question 9

Question 10

What is the output of the program?

    public class test {
        public static void main(String arg[]) {
            int p = 0, q =1;
            if( p=1) {
                p = q++ + 99;
                q = p++ + 99;
            }
            System.out.println (p);
            System.out.println (q);
        }
    }

  1. 0 1
  2. 101 199
  3. 101 201
  4. Error at compilation time

Answer to Question 10

Question 11

Whenever you allocate memory with the new operator, where is the memory allocated?

  1. Stack
  2. Heap
  3. RAM
  4. Registers

Answer to Question 11

Question 12

What of the following statement regarding an Event adapter class  ?

  1. Event Adapter class are the classes which provide body/implementation to the methods of the interfaces
    which it implements and need to be extended compulsorily.
  2. Event Adapter class are the classes which provide empty implementation to the methods of the interfaces
    which it implements and need to be extended compulsorily.
  3. Event Adapter class are the classes which provide empty implementation to the methods of the interfaces which it
    implements and need not to be extended compulsorily.
  4. Event Adapter class are the classes which provide body/implementation to the methods of the interfaces
    which it implements and need not to be extended compulsorily.

Answer to Question 12

Question 13

What is the return type of the read() method of InputStream class in java.io package?

  1. int
  2. String
  3. StringBuffer
  4. byte

Answer to Question 13

Question 14

    public class myprog{
        public static void main(String argv[]) {
            System.out.println(argv[2]) ;
        }
    }

What will be the output if we execute the program with the command given in the next line:
    java myprog Good Morning

  1. myprog
  2. Good
  3. Morning
  4. Exception is given : java.lang.ArrayIndexOutOfBounds

Answer to Question 14

Question 15

What is the output of the program?

    public class divtest {
        public void divide(int a, int b) {
            try {
                int c = a / b;
            }
            catch (Exception e) {
                System.out.print("Exception ");
            }
            finally {
                 System.out.println("Finally");
            }
        }
        public static void main( String args[ ]) {
             int result = 0;
             divtest dv = new divtest();
             dv.divide(4, 0);
        }
    }

  1. Prints out: Exception Finally
  2. Prints out: Finally
  3. Prints out: Exception
  4. No output

Answer to Question 15

Question 16

The "System.in" object used for the standard input operations is instantiated from which class?

  1. System class
  2. InputStream class
  3. DataInputStream class.
  4. Object class

Answer to Question 16

Question 17

Java interpreter option, which checks to see if the source code is newer than its class file.

  1. –sourcecheck
  2. –checksource
  3. -checktime
  4. -checksrc

Answer to Question 17

Question 18

    import java.util.*;
    public class mathTest {
        public static void main( String args[ ]){
            // The required statement needs to come here.
        }
    }

Which of the following will output -4.0?

  1. System.out.println(Math.floor(-4.7));
  2. System.out.println(Math.round(-4.7));
  3. System.out.println(Math.ceil(-4.7));
  4. System.out.println(Math.Min(-4.7));

Answer to Question 18

Question 19

How are parameters and Objects passed in Java?

  1. Both are passed by value.
  2. Both are passed by reference.
  3. Parameters are passed by value but Objects by reference.
  4. Parameters are passed by reference but Objects are passed by value.

Answer to Question 19

Question 20

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

  1. Parentheses i.e [ ], ()
  2. Multiplicative operators i.e *, / , %
  3. Additive operators i.e +, - 
  4. Assignment Operator i.e =

Answer to Question 20

Answers

Answer 1 - D

Back to question 1

Answer 2 - A

Back to question 2

Answer 3 -  C

Back to question 3

Answer 4 - B

Back to question 4

Answer 5 - C

Back to question 5

Answer 6 - D

Back to question 6

Answer 7 - D

Back to question 7

Answer 8 - C

Back to question 8

Answer 9 - A

Back to question 9

Answer 10 - D

Back to question 10

Answer 11 - B

Back to question 11

Answer 12 - C

Back to question 12

Answer 13 - A

Back to question 13

Answer 14 - D

Back to question 14

Answer 15 - A

Back to question 15

Answer 16 - B

Back to question 16

Answer 17 - B

Back to question 17

Answer 18 - C

Back to question 18

Answer 19 - C

Back to question 19

Answer 20 - A

Back to question 20

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