LearnFrenzy
Sign in Take a free test

Java Basics, Syntax and Data Types · Exercise 1 of 4

Java Basics, Syntax and Data Types Java Basics MCQ

  • 20 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

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.

Question 1 Easy

What does the javac compiler produce from Main.java?

A An .exe file
B Bytecode in Main.class, run by the JVM
C C source code
D Machine code for the current CPU only
Question page & discussion
Question 2 Easy

Which statement about JVM, JRE and JDK is correct?

A The JVM contains the JDK
B The JDK contains the JRE (JVM + libraries) plus development tools like javac
C The JRE contains javac
D They are three names for the same thing
Question page & discussion
Question 3 Easy

What makes compiled Java programs portable across operating systems?

A Java has no operating-system calls
B The same bytecode runs on any platform that has a JVM
C javac compiles for every CPU at once
D Java programs are interpreted from source
Question page & discussion
Question 4 Easy

Which declaration can the JVM use as a program's entry point?

A public void main(String args)
B public static void main(String[] args)
C static int main()
D public static main(String[] args)
Question page & discussion
Question 5 Medium

Why is the main method static?

A To make it faster
B So the JVM can call it without first creating an object of the class
C Because static methods cannot throw exceptions
D It is optional
Question page & discussion
Question 6 Easy

A file contains public class Invoice { … }. What must the file be called?

A Main.java
B Invoice.java
C invoice.java (any case)
D Any name ending in .java
Question page & discussion
Question 7 Easy

How many primitive data types does Java have?

A 4
B 6
C 8
D 10
Question page & discussion
Question 8 Easy

How many bits does a Java char use?

A 8
B 16
C 32
D It depends on the platform
Question page & discussion
Question 9 Medium

Why does long x = 9000000000; not compile?

A long cannot hold that value
B Integer literals are int by default and 9000000000 is out of int range; write 9000000000L
C Underscores are required
D long needs a cast
Question page & discussion
Question 10 Easy

Which declaration compiles?

A float f = 3.5;
B float f = 3.5f;
C float f = (double) 3.5;
D float f = 3.5d;
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links