Try to answer these 800+ Java MCQs and check your understanding of the Java subject. Scroll down and let's begin!
A. an instantiator.
B. a constructor.
C. a destructor.
A. No, it does not compile
B. Yes, but will not run
A. Two
B. Three
C. One
A. Arithmetic comparator "=="
B. Equals Method
C. Both
A. use the myClass property.
B. use the instanceOf operator.
C. use the getClass() method.
A. LocalThread
B. Thread
C. Runnable
D. ThreadLocal
A. stop()
B. sleep(long milliseconds)
C. yield()
D. join()
A. Ensures that each call to a synchronized method is run in a separate thread.
B. Creates a new semaphore to prevent two threads from accessing the method simultaneously.
C. Prevents objects outside the current package from accessing the method.
D. Uses the object's intrinsic lock to prevent two threads from accessing the method simultaneously.
A. They may exist, and they can be transient but not volatile.
B. They cannot exist and the compiler will throw a 'field name is ambiguous' error if you attempt to make them.
C. They may exist, and they can be transient and volatile.
D. They may exist, and they can be volatile but not transient.
E. They may exist, but they must be public, static and final.
A. All of these answers are correct
B. Is not required to implement an interface method.
C. Is not required to override an inherited method in a parent class.
D. Will warn you on compilation if your annotated method signature doesn't match a method in a parent class or interface.
E. Clearly documents the intention to override a method in a parent class or implement a method declared in an interface.
A. creating strings which change considerably.
B. creating strings which only change once.
C. retrieval of all or part of a string but not altering the string.
A. has a circular dependency on 2 or more synchronized objects, causing one of the objects to wait indefinitely.
B. has a for loop or while loop that can never satisfy its condition, causing the loop to run forever and the program to wait indefinitely.
C. has a circular try-catch block, in which the catch results in the catch block being reached again repeatedly, causing the program to run indefinitely.
A. They are not equal
B. They are equal
A. m=5
B. m=3
C. Runtime error
D. Compile error
A. No
B. Yes
A. "depth" must be an int.
B. "submarine" must be a method.
C. "dive" must be a method.
D. "submarine" must be the name of a class.
E. "dive" must be the name of an instance field.
A. There is nothing wrong with this method.
B. static methods cannot return type "int"
C. static methods cannot refer to "this" or "super"
A. ArrayList<String> myList = new ArrayList<String>(10);
B. ArrayList<String> myList = new ArrayList<String>();
C. ArrayList<Integer> myList = new ArrayList<Integer>();
D. ArrayList<Double> myList = new ArrayList<Double>();
E. ArrayList<String> myList = new ArrayList<Integer>();
A. Passed by value
B. Passed by reference
A. the Observer Pattern
B. the Flyweight pattern
C. the Singleton pattern
D. the Factory pattern
A. java.naming.security.credential
B. java.naming.security.authentication
C. java.naming.security.principal
D. All of these
A. myClass::~myClass();
B. You don't need a destructor
C. @Override System.gc(){ }
D. @destructor myClass(){ }
A. No, never
B. Yes, as long as they are public, static and final
A. No
B. Yes
A. which must be serializable so that the state can be stored.
B. which must have a public, no-argument constructor.
C. all of these
D. which must follow standard naming conventions for attributes such as getXxxx.
A. Yes
B. No
A. import pkg
B. Import pkg.*
C. import pkg.*
D. Import pkg
A. a class can implement multiple interface
B. a class can inherit multiple superclass
C. a class can inherit multiple abstract superclass
A. class MyDerived implements MyClass
B. public class MyDerived : MyClass
C. class MyDerived extends MyClass
A. public void static main(String[] args)
B. private void main (String[] args)
C. public static main(String[] args)
D. private static void main(String[] args)
E. public static void main(String[] args)
A. Package
B. package
C. pkg
D. pack
E. Pkg
A. Yes
B. No
A. All of these
B. Within a session, the appropriate sender or publisher or receiver or subscriber objects.
C. A connection object provided by the JMS server (the message broker)
D. Within a connection, one or more sessions, which provide a contest for message sending and receiving
A. processes the java code through the Java Virtual Machine (JVM).
B. processes the java code through the native OS interpreter.
C. process the java code through the interpreter which is pointed to by the CLASSPATH statement.
D. none of these
A. stop; jump
B. stop; continue
C. break; jump
D. break; continue
A. river
B. 6
C. 8
D. Columbia
E. 7
A. |
B. &&
C. &
D. ||
A. MyClass mc = MyClass;
B. MyClass mc = new MyClass;
C. MyClass mc = new MyClass();
D. It can't be done. The constructor of MyClass should be defined as public void MyClass(){/*code*/}
E. MyClass mc = MyClass();
A. throw, take, finally
B. try, catch, end
C. throw, catch, end
D. try, catch, finally
E. throw, catch, do
A. typecasting
B. hardcasting
C. datatyping
A. foo("bar1");
B. foo("bar1", "bar2");
C. All of these.
D. foo("bar1", "bar2", "bar3");
A. Encapsulation
B. Abstraction
C. Inheritance
D. Type casting
A. public static void main(String[] args)
B. public void main(String[] args)
C. public static void main(Collection
D. public static int main(String[] args)
A. gcc compiler
B. system runtime compiler
C. javac compiler
A. protected
B. public
C. all of these
D. private
A. All of these
B. Stop running
C. Start running
D. Self initialize
A. Variables
B. Methods
C. All of these
D. Classes
A. only Microsoft Windows platforms.
B. all platforms.
C. only on UNIX based platforms.
A. get
B. import
C. uses
D. using
E. add
A. public final void main(String arg0, String arg1="default") {}
B. public static void main(String [] args) { }
C. public void main(int argc, String [] argv) {}
D. @Main public void main(int argc, String[] argv) {}
A. Google
B. Microsoft
C. IBM
D. Facebook
E. Sun Microsystems (Oracle)
A. The parameters passed to the method cannot be modified.
B. The method cannot be overridden in subclasses.
C. The return value of the method will be final.
D. The method can only accept final parameters.
A. Yes
B. No
A. additional pylons
B. abstract methods
C. fields
D. constructors
A. Declare the class as abstract.
B. Declare the class as final.
C. Declare all member variables and methods as protected.
D. Declare all its members as private.
A. Yes
B. No
A. Method overloading
B. Object orientation overdev
C. Method overdriving
D. Method overriding
A. A token is any character that may be used as punctuation
B. A token is a type of expression
C. A token is a group of characters that means something in a particular context.
D. A token is a group of digits
A. Equals
B. Same Equals
C. The code compiles, but nothing is displayed upon execution.
D. Same
A. they have multiple call signatures
B. the method throws an exception
C. they have different return types
D. You cannot overload a method
A. x.add(1, "Chicago")
B. x.add("Chicago")
C. x.add(2, "Chicago")
D. x.add(0, "Chicago")
A. Yes
B. No
A. neither of these
B. reference, where the data is accessed indirectly.
C. wide, which reference a double byte variable.
A. Runtime Error
B. hello
C. Nothing display
D. error:class decleration not valid
A. Yes
B. No
A. java.util.WeakHashMap
B. java.util.concurrent.ConcurrentHashMap
C. java.util.TreeMap
D. java.util.LinkedHashMap
A. List
B. SortedSet
C. Set
D. SortedMap
A. double
B. char
C. long
D. float
E. int
A. No
B. Yes
A. Vector is synchronized whereas ArrayList is not
B. ArrayList is synchronized whereas Vector is not
C. Both are identical
A. ...will generally run under previous versions of the platform.
B. ...will generally run under future versions of the platform.
C. ...can never run under future versions of the platform.
D. ...can only run under that version of the platform.
A. String toString()
B. int compareTo(String anotherString)
C. boolean isNull()
D. String valueOf(char[] data)
A. java -jar program.jar
B. java -run program.jar
C. jar program.jar
D. java -run program
E. java -jar program
A. Provides a convenient shortcut for creating threads
B. Prohibits code from being executed during garbage collection
C. Aligns samples within the JVM for accuracy when profiling
D. Ensures that each call finishes at the same time
E. Prevents concurrency within methods or statements
A. The syntax is incorrect.
B. The statement does not do anything.
C. The object reference variable 'a1' should be in title case.
D. An object 'a1' of class 'A' is created.
E. The object reference variable 'a1' is declared.
A. No
B. Yes
A. Perform pseudo-pointer manipulations in Java.
B. Dynamically change the Java Heap Size.
C. Optimize recursion at runtime by extending the reflection class.
D. Obtain the names of a class' members and display them at runtime.
A. It is the default variable in the class.
B. A variable which is not static.
C. A variable which is serialized.
D. A variable which is not serialized.
A. for (Object o : collection)
B. foreach (Object o : collection)
C. there is no foreach loop in Java
D. for (Object o in collection)
E. foreach (collection as Object o)
A. In order to compile
B. Both of these
C. In order to execute
A. you end up with two copies of the data and two references to the variable.
B. you end up with one copy of the data and one reference to the data.
C. you end up with one copy of the data and two references to the data.
A. public int hash()
B. public static int hash()
C. public int hashCode()
D. public static int hashCode()
A. that, if constant, they cannot be changed once they are created.
B. that they can be changed one time without changing the reference.
C. that they can be changed multiple times without altering the reference.
A. finalizeGarbageCollection
B. final
C. finalize
D. finally
A. It has to be a FileReader
B. It has to be a BufferReader.
C. It can neither be a FileReader or a BufferReader.
D. It can either be a FileReader or a BufferReader.
A. True
B. False
A. A class with an undefined constructor
B. A class that does not define all of its methods
C. A class of methods that must be implemented
D. A class that is defined by another class
A. static
B. abstract
C. private
D. final
E. package private
A. Sort.sort
B. Collection.sort
C. CollectionsUtils.sortCollection
D. Collections.sort
A. transient
B. volatile
C. serializable
D. break
E. synchronized
A. final classes.
B. one other interface.
C. nothing: extension is not valid for interfaces.
D. multiple interfaces.
A. component set (subclasses of JComponent),support classes,interfaces
B. interfaces,component set (subclasses of JComponent)
C. component set (subclasses of JComponent)
D. support classes,interfaces
A. No
B. Yes
A. &
B. !
C. ?
D. %
A. JNDI SPI
B. Java API
C. JNDI API and JNDI SPI
D. JNDI API
A. The code prints "null" on console.
B. The code throws NullPointerException.
C. The code does not compile.
A. True
B. Only if they are private
C. False
D. Only if they are public
A. The code throws NullPointerException.
B. The code prints NULL on console.
C. The code does not compile.
A. No
B. Yes
A. A globally declared mutex.
B. The method's mutex.
C. The owning object's (this's) mutex.