What does the javac compiler produce from Main.java?
Bytecode is platform-independent; the JVM turns it into native code at run time.
Java Basics, Syntax and Data Types · Exercise 1 of 4
Twenty multiple-choice questions on Java basics: JDK, JRE and JVM, bytecode, the main method, primitive data types, literals, var, final, type casting, promotion and overflow. Pick an option to check your answer instantly.
What does the javac compiler produce from Main.java?
Bytecode is platform-independent; the JVM turns it into native code at run time.
Which statement about JVM, JRE and JDK is correct?
JDK ⊃ JRE ⊃ JVM. To compile you need the JDK; to run, a runtime.
What makes compiled Java programs portable across operating systems?
The JVM itself is platform-specific; the bytecode is not.
Which declaration can the JVM use as a program's entry point?
It must be public, static, return void and take a String array (String... args also works).
Why is the main method static?
At start-up there are no objects yet; a static method belongs to the class itself.
A file contains public class Invoice { … }. What must the file be called?
The name must match exactly, including case. A file may contain at most one public top-level class.
How many primitive data types does Java have?
byte, short, int, long, float, double, char and boolean. String is a class.
How many bits does a Java char use?
A char is an unsigned 16-bit UTF-16 code unit (0 to 65,535).
Why does long x = 9000000000; not compile?
The literal itself must be valid before it is widened to long.
Which declaration compiles?
3.5 is a double literal; narrowing double → float needs the f suffix or a cast.
Timed online tests with instant scores and explanations.