Which engineer designed the Java language at Sun Microsystems?
Answer : James Gosling
James Gosling designed Java at Sun Microsystems; the language was announced in 1995.
Revise Java: here is a selection of questions of every level, with the answer and an explanation. To test yourself without seeing the answers, play the quizzes.
Play the Java quizzesAnswer : James Gosling
James Gosling designed Java at Sun Microsystems; the language was announced in 1995.
Answer : The Java Virtual Machine (JVM)
The JVM reads the bytecode and executes it, which lets the same program run on several operating systems.
Answer : javac
javac produces .class files containing the bytecode; the java command then runs this bytecode in the JVM.
Answer : boolean
boolean is the primitive type for logical values; bool is not a keyword in Java.
Answer : char
Between single quotes, a value is a character: the char type encodes one character on 16 bits (UTF-16).
Answer : The JDK contains the development tools, the JRE is only for running programs
The JDK bundles the tools for developing (including javac); the JRE contains only what is needed to run a Java program.
Answer : length()
The length() method returns the number of characters of a String; size() is the method of collections, such as List.
Answer : 4
Indexes start at 0: an array of five cells has the indexes 0, 1, 2, 3 and 4.
Answer : extends
extends links a subclass to its superclass, from which it inherits the accessible members.
Answer : private
private restricts access to the class that declares the field; it is a pillar of encapsulation, with getters if needed.
Answer : It has the exact name of the class and no return type
A constructor has the exact name of its class and no return type; new calls it to initialize the object when it is created.
Answer : The class itself, shared by all its objects
A static field exists only once for the class: it is shared by all objects and can be used without creating an object.
Answer : With the implements keyword
A class that implements an interface says so with implements and must provide the code of every abstract method of the interface.
Answer : finally
finally runs after the try and after any catch, whether or not the exception was raised (except if the JVM stops abruptly).
Answer : Set
A Set does not keep duplicates: add returns false if the element is already present. HashSet is a common implementation.
Answer : The type of the keys
The first parameter of Map designates the type of the keys, the second the type of the associated values.
Answer : The heap
Objects live on the heap, which is shared between threads; the stack of each thread stores the local variables and the references to these objects.
Answer : It frees the memory of objects that have become unreachable
The garbage collector reclaims the memory of objects that can no longer be reached from the program; it manages neither files nor bytecode.
Answer : It does not modify the original and returns the result in a String
A String is immutable: no method changes its content; they return the result as a String (here, the concatenation).
Answer : Only one thread at a time can run the synchronized methods of this object
Each object has a lock: a thread must acquire it to enter a synchronized method, which prevents concurrent access.
Answer : volatile
volatile ensures the visibility of writes between threads, but does not make a compound operation such as x++ atomic.
Answer : Manage a thread pool and submit tasks to it
An ExecutorService separates the submission of tasks from the creation of threads, and reuses the threads of a pool.
Answer : An interface that declares exactly one abstract method
A lambda can implement a functional interface; the @FunctionalInterface annotation is optional, but the compiler checks the rule if it is present.
Answer : 2014
Java 8 was released in March 2014; it also brought Optional and the functional interfaces of the java.util.function package.