menu

Java Basics


1. Which keyword is used to declare a variable in Java?

var

let

int

def


2. Which of the following is NOT a valid identifier in Java?

myVariable

$variable

2variable

_variable


3. Which of the following is NOT a primitive data type in Java?

int

boolean

double

string


4. Which of the following is NOT a primitive data type in Java?

int

boolean

double

string


5.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
int x = 5;
int y = 2;
System.out.println(x / y);
 }
}

2

2.5

2

None of the above


6.

What is Java?

A programming language

An operating system

A database management system

A web browser


7.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
String name = "Java";
System.out.println(name.substring(1, 3));
 }
}

Ja

av

Jav

No output


8. Which of the following is a valid way to declare an array in Java?

int[] numbers = {1, 2, 3};

int numbers[] = {1, 2, 3};

int numbers = {1, 2, 3};

Both A and B


9.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
String name = "Java";
for(int i = 0; i < name.length(); i++) {
System.out.print(name.charAt(i) + " ");
  }
 }
}

J a v a

Java

Jv

No output


10.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
System.out.println("Hello" + " World");
}

Hello

World

Hello World

HelloWorld