1. Define Java and mention its original name.
Answer: 1. Java is a high-level, object-oriented programming language originally named 'Oak' by its
creator James Gosling.
2. List and briefly explain any three features of Java.
Answer: 2. Three features of Java are: Platform Independence (via JVM), Object-Oriented
Programming, and Automatic Garbage Collection.
3. What is JVM? How does it relate to platform independence?
Answer: 3. JVM (Java Virtual Machine) executes bytecode and enables Java programs to run on
any platform without modification.
4. Differentiate between JDK, JRE, and JVM.
Answer: 4. JDK (Java Development Kit) includes tools to develop Java programs. JRE (Java
Runtime Environment) runs them. JVM executes bytecode.
5. Explain the purpose of 'javac' and 'java' tools.
Answer: 5. 'javac' compiles Java source files into bytecode. 'java' runs the compiled bytecode via the
JVM.
6. Describe the use of comments in Java. Mention all types.
Answer: 6. Java supports single-line (//), multi-line (/* */), and documentation (/** */) comments for
code explanation and documentation.
7. What are primitive data types in Java? List them.
Answer: 7. Java has 8 primitive data types: byte, short, int, long, float, double, boolean, and char.
8. Explain the difference between primitive and reference variables.
Answer: 8. Primitive variables store actual values; reference variables store memory addresses of
objects.
9. Describe the rules for naming variables in Java.
Answer: 9. Variable names must start with a letter, underscore, or dollar sign and can't contain
spaces or be Java keywords.
10. What is the purpose of the main method in Java programs?
Answer: 10. The main method is the entry point of any standalone Java application: public static
void main(String[] args).
11. Write a simple Java program to print 'Hello World'.
Answer: 11. public class HelloWorld { public static void main(String[] args) {
System.out.println("Hello World"); } }
12. What is the difference between = and == in Java?
Answer: 12. '=' is an assignment operator; '==' checks equality between values.
13. Define and explain three types of control statements.
Answer: 13. Control statements: Selection (if, switch), Looping (for, while, do-while), and Jumping
(break, continue, return).
14. Explain the syntax and use of if-else-if ladder.
Answer: 14. The if-else-if ladder checks multiple conditions in sequence and executes the matching
block.
15. Write a program using a for loop to print numbers 1 to 5.
Answer: 15. for (int i = 1; i <= 5; i++) { System.out.println(i); }
16. Define a class and explain its components.
Answer: 16. A class is a blueprint for creating objects. Components include fields, methods,
constructors, and access modifiers.
17. What is an object in Java? Give two real-life examples.
Answer: 17. An object is an instance of a class. E.g., a Car, a Student.
18. Write the syntax to create an object from a class.
Answer: 18. ClassName obj = new ClassName();
19. What is a constructor? How is it different from a method?
Answer: 19. A constructor initializes objects and has no return type. A method defines behavior and
can return values.
20. Explain the concept of method overloading with an example.
Answer: 20. Method overloading allows multiple methods with the same name but different
parameters.
21. What is the purpose of the 'this' keyword?
Answer: 21. 'this' refers to the current object and is used to resolve naming conflicts between
instance variables and parameters.
22. Distinguish between instance and class (static) variables.
Answer: 22. Instance variables are unique to each object. Class (static) variables are shared among
all instances.
23. Explain how to define and use a static method.
Answer: 23. Static methods are declared with the static keyword and are accessed using the class
name.
24. What is an access modifier? Name and explain four types.
Answer: 24. Access modifiers: public (accessible everywhere), private (within class), protected
(within package and subclasses), default (package-private).
25. Write a class named Student with fields and a constructor.
Answer: 25. public class Student { String name; int id; Student(String n, int i) { name = n; id = i; } }
26. Describe how class variables are accessed in Java.
Answer: 26. Class variables are accessed using ClassName.variableName or through any instance
(not recommended).
27. What will happen if you access an uninitialized object in an array?
Answer: 27. A NullPointerException occurs because the object elements in the array are not
instantiated.
28. Explain the difference between local, instance, and class variables.
Answer: 28. Local variables exist inside methods, instance variables belong to objects, and class
variables are shared among all instances.
29. What are the steps involved in creating and using an object?
Answer: 29. Define a class, declare an object, use 'new' to instantiate it, and then access members
using dot notation.
30. Describe how Java achieves security in code execution.
Answer: 30. Java secures code using JVM, bytecode verification, and the class loader to prevent
malicious code execution.