WorksheetsMastering Java Concepts
Total questions: 10
Worksheet time: 5mins
What is the main purpose of the Java Virtual Machine (JVM)?
To provide a graphical user interface for Java programs.
To manage memory allocation for Java applications.
To compile Java source code into machine code.
The main purpose of the Java Virtual Machine (JVM) is to execute Java bytecode and provide platform independence.
Explain the difference between JDK, JRE, and JVM.
JVM is a programming language.
JDK is for development, JRE is for running applications, and JVM is the execution engine.
JRE includes the development tools.
JDK is only for running applications.
What are the main features of Java?
Java does not support multithreading.
Main features of Java include portability, security, automatic memory management, multithreading, and a rich standard library.
Java is only used for web development.
Java requires manual memory management.
What is a constructor in Java?
A constructor is a special method in Java used to initialize objects.
A constructor is used to delete objects in Java.
A constructor is a method that returns a value in Java.
A constructor is a type of variable in Java.
How does Java achieve platform independence?
Java relies on native libraries for platform-specific features.
Java uses bytecode and the Java Virtual Machine (JVM) to achieve platform independence.
Java compiles directly to machine code for each platform.
Java uses a different programming language for each platform.
What is the difference between '== 'and 'equals()' in Java?
'==' is for reference comparison, 'equals()' is for value comparison.
'==' compares values, 'equals()' compares references.
'==' is used for primitive types, 'equals()' is for objects only.
'==' can be overridden, 'equals()' cannot be overridden.
What are the access modifiers in Java?
static
final
public, private, protected, default
abstract
What is the purpose of the 'static' keyword in Java?
The 'static' keyword indicates that a member belongs to the class rather than instances.
The 'static' keyword is used to create private variables.
The 'static' keyword allows for instance-specific methods.
The 'static' keyword is used to define a constant value.
Explain the concept of inheritance in Java.
Inheritance is a method to create new classes without any relationship to existing ones.
Inheritance allows a subclass to inherit properties and behaviors from a superclass, promoting code reuse and establishing a class hierarchy.
Inheritance allows a class to inherit only static methods from another class.
Inheritance in Java is used to delete properties from a superclass.
What is an interface in Java and how is it different from an abstract class?
An interface is a contract that classes can implement, while an abstract class can provide some method implementations and state.
An interface is a type of class that cannot be instantiated, while an abstract class can be instantiated.
An interface can have instance variables, while an abstract class cannot.
An interface can only contain static methods, while an abstract class can contain instance methods.
