Java Quiz

A vibrant illustration of a computer screen displaying Java code with a coffee cup beside it, symbolizing Java programming.

Java Quiz Challenge

Test your Java knowledge with our comprehensive quiz! Designed for both beginners and experienced programmers, this quiz covers a wide range of Java concepts.

Prepare to challenge yourself with questions that include:

  • Basics of Java classes
  • String handling
  • Threads and exceptions
  • Memory allocation and arrays
16 Questions4 MinutesCreated by CodingNinja542
What is a class in java?
A class is a blue print from which individual objects are created. A class can contain fields and methods to describe the behavior of an object.
Class is a special data type.
Class is used to allocate memory to a data type.
None of the above.
What is the default value of String variable?
""
''
NULL
None of the above.
Which of the following is not a Java keyword?
Try
Static
New
Integer
Which of these are not legal identifiers?
1ietk
I_e_t_k
?ietk
A and C
An object could be …
A program
A data container
An algorithm
Anything
Given the following code snippet;
int salaries[];
int index = 0;
salaries = new int salaries[4];
while (index < 4)
{ salaries[index] = 10000;
   index++;
}
What is the value of salaries [8]?
40000
10000
20000
None of the above.
When a thread terminates its processing, into what state that thread enters?
Dead state
Waiting state
Running state
Beginning state
What all gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens".
Select the two correct answers.
public class test
{
public static void main(String args[])
{
System.out.println(args[0]+" "+args.length);
}
}
a. java
b. test
c. lets
d. 3
e. 4
f. 5
g. 6
A,b
C,d
B,e
C,e
What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{ badMethod();
System.out.print("A");
}
catch (RuntimeException ex) /* Line 10 */
{
System.out.print("B");
}
catch (Exception ex1)
{
System.out.print("C");
}
finally
{
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod()
{
throw new RuntimeException();
}
}
BD
BCD
B
BDE
What is the result of compiling and running the following program.
public class test
{
public static void main(String args[])
{
String str1="abc";
String str2="def";
String str3=str1.concat(str2);
str1.concat(str2);
System.out.println(str1);
}
}
Def
Abc
Abcabc
Abcdef
What is the result of compiling and running the following program.
Select the one correct answer.
class test
{
public static void main(String args[])
{
char ch;
String test2 = "abcd";
String test = new String("abcd");
if(test.equals(test2))
{
if(test == test2)
ch = test.charAt(0);
else
ch = test.charAt(1);
}
else
{
if(test == test2)
ch = test.charAt(2);
else
ch = test.charAt(3);
}
System.out.println(ch);
}
}
'a'
'b'
'c'
'd'
In the following class definition, which is the first line (if any) that causes a compilation error.
Select the one correct answer.
public class test
{
public static void main(String args[])
{
char c;
int I;
c = 'A'; // 1
i = c; //2
c = I + 1; //3
c++; //4
}
}
The line labeled 1.
The line labeled 2.
The line labeled 3.
All the lines are correct and the program compiles.
What all gets printed when the following gets compiled and run.
Select the two correct answers.
public class test
{
public static void main(String args[])
{
int i=1, j=1;
try
{
i++;
j--;
if(i == j)
i++;
}
catch(ArithmeticException e)
{
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println(1);
}
catch(Exception e)
{
System.out.println(2);
}
finally
{
System.out.println(3);
}
System.out.println(4);
}
}
a. 0 
b. 1 
c. 2 
d. 3 
e. 4 
A,d,c
B,c,a
D,e
A,b
What is the result of compiling and running the following program.
Select the one correct answer.
class test
{
public static void main(String args[])
{
int[] arr = {1,2,3,4};
call_array(arr[0], arr);
System.out.println(arr[0] + "," + arr[1]);
}
static void call_array(int I, int arr[])
{
arr[i] = 6; I = 5;
}
}
1,2
5,2
1,6
5,6
By whom and when JAVA was founded ?
James Gosling,1995
James denver,1978
Dan Brown,1954
Seregy brin,1988
{"name":"Java Quiz", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Test your Java knowledge with our comprehensive quiz! Designed for both beginners and experienced programmers, this quiz covers a wide range of Java concepts.Prepare to challenge yourself with questions that include:Basics of Java classesString handlingThreads and exceptionsMemory allocation and arrays","img":"https:/images/course2.png"}
Powered by: Quiz Maker