CodeStudy.net
Toggle Menu
Home
Online Java Compiler
Tutorials
Java Tutorial
Python Tutorial
SQL Database Design
Blog
All Posts
Java Fundamentals
Test your knowledge of Java syntax,variables,and control structures.
1. What is the entry point of a Java program?
main method
start method
run method
init method
2. Which keyword is used to declare a class in Java?
class
Class
object
Object
3. What is the default value of an int instance variable?
0
null
1
undefined
4. Which of these is a primitive data type in Java?
String
Integer
int
ArrayList
5. What does the 'static' keyword mean for a method?
Belongs to the class
Belongs to the object
Can't be overridden
Must return void
6. Which operator is used for string concatenation in Java?
+
&
&&
|
7. What is the output of System.out.println(5 + 2 + "Java");?
"7Java"
"52Java"
"Java7"
"Java52"
8. Which loop structure is best for when you don't know the number of iterations in advance?
for
while
do-while
enhanced for
9. Which keyword is used to inherit a class in Java?
extends
implements
inherit
super
10. What is the superclass of all classes in Java?
Object
Class
Super
Root
11. Which of the following are valid Java identifiers?
myVar
1var
var-1
$var
_var
12. Which keywords are used for access control in Java?
public
private
protected
internal
package
13. Which of these are checked exceptions?
NullPointerException
IOException
ArithmeticException
SQLException
ClassNotFoundException
14. Which of the following interfaces extend the Iterable interface, allowing traversal with an enhanced for-loop?
Collection
List
Map
Set
Queue
15. Which of these are valid ways to create a String in Java?
new String("hello")
"hello"
String.create("hello")
String.valueOf("hello")
"hello".intern()
16. Java is a case-sensitive language.
True
False
17. The 'final' keyword can be applied to a class, method, and variable.
True
False
18. A constructor can return a value.
True
False
19. What keyword is used to handle exceptions in Java (starts the block where exceptions may occur)?
20. Name the standard method used to print a line of text to the console (full method name).
Reset
Answered 0 of 0 — 0 correct