Search Header Logo

Java syntax

Authored by Wayground Content

Computers

University

Used 3+ times

Java syntax
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What symbol is used to end a Java statement?

.

;

:

!

Answer explanation

Java statements end with a semicolon (;).

2.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

How many primitive data types does Java have?

6

7

8

9

Answer explanation

Java has 8 primitive data types: byte, short, int, long, float, double, char, and boolean.

3.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What happens if a local int variable is used without initialization?

It is initialized to 0.

It retains a garbage value.

It causes a compilation error.

It is initialized to -1.

Answer explanation

"Local variables in Java must be explicitly initialized before use, as they do not have default values. Attempting to use an uninitialized local variable results in a compilation error.

4.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What is the size of the 'int' data type in Java?

2 bytes

4 bytes

8 bytes

16 bytes

Answer explanation

The 'int' data type in Java occupies 4 bytes (32 bits).

5.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What will this print?
int x = 5; int y = 3; System.out.println(x - y);

1

2

3

4

Answer explanation

The difference between x (5) and y (3) is 2.

6.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

Identify the error in this code:
int num; System.out.println(num);

Variable not initialized

Syntax error in declaration

Variable out of scope

Data type mismatch

Answer explanation

Local variables like num must be explicitly initialized before use.

7.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What is the output of this code? System.out.println("Java " + "Programming");

Java Programming

Java & Programming

JavaProgramming

Programming in Java

Answer explanation

The + operator concatenates the two strings, resulting in Java Programming.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Microsoft

Continue with Microsoft

or continue with

Facebook

Facebook

Apple

Apple

Others

Others

By signing up, you agree to our Terms of Service & Privacy Policy

Already have an account?