Java Learning Guide (With Explanations)
1. What is Java?
Java is a high-level, object-oriented language used in web, mobile, and desktop applications. It is
platform-independent and secure.
2. Java Program Structure
class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
3. Data Types: int, float, char, boolean, String (non-primitive).
4. Variables and Type Casting
int a = 10; double b = a; int c = (int)b;
5. Operators: Arithmetic (+, -, *, /), Relational (==, !=), Logical (&&, ||), Assignment (=, +=)
6. Control Statements: if-else, switch
7. Loops: for, while, do-while
8. Class & Object: Blueprint vs real-world entity
9. Constructor: Initializes an object
10. Inheritance: class Dog extends Animal
11. Polymorphism: Overloading & Overriding
12. Abstraction: Hides implementation using abstract class or interface
13. Exception Handling: try-catch-finally
14. Keywords: this, super, static, final
15. Access Modifiers: public, private, protected, default
16. Static Keyword: Belongs to class not object
17. Final Keyword: Prevents change or override
18. Interface vs Abstract Class:
- Interface: all abstract methods
- Abstract class: can have both abstract and concrete methods
19. Packages: Group of similar classes (e.g. java.util)
20. Comments: // for single line, /* */ for multi-line
50 Advanced Level Java MCQs with Answers
1. Which of the following is not a Java features?
A. Dynamic
B. Architecture Neutral
C. Use of pointers
D. Object-oriented
Answer: C
2. Which package contains the Random class?
A. java.util package
B. java.lang package
C. java.awt package
D. java.io package
Answer: A
3. What is the return type of the hashCode() method in the Object class?
A. Object
B. int
C. long
D. void
Answer: B
Java Learning Guide (With Explanations)
1. What is Java?
Java is a high-level, object-oriented language used in web, mobile, and desktop applications. It is
platform-independent and secure.
2. Java Program Structure
class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
3. Data Types: int, float, char, boolean, String (non-primitive).
4. Variables and Type Casting
int a = 10; double b = a; int c = (int)b;
5. Operators: Arithmetic (+, -, *, /), Relational (==, !=), Logical (&&, ||), Assignment (=, +=)
6. Control Statements: if-else, switch
7. Loops: for, while, do-while
8. Class & Object: Blueprint vs real-world entity
9. Constructor: Initializes an object
10. Inheritance: class Dog extends Animal
11. Polymorphism: Overloading & Overriding
12. Abstraction: Hides implementation using abstract class or interface
13. Exception Handling: try-catch-finally
14. Keywords: this, super, static, final
15. Access Modifiers: public, private, protected, default
16. Static Keyword: Belongs to class not object
17. Final Keyword: Prevents change or override
18. Interface vs Abstract Class:
- Interface: all abstract methods
- Abstract class: can have both abstract and concrete methods
19. Packages: Group of similar classes (e.g. java.util)
20. Comments: // for single line, /* */ for multi-line
50 Advanced Level Java MCQs with Answers
1. Which of the following is not a Java features?
A. Dynamic
B. Architecture Neutral
C. Use of pointers
D. Object-oriented
Answer: C
2. Which package contains the Random class?
A. java.util package
B. java.lang package
C. java.awt package
D. java.io package
Answer: A
3. What is the return type of the hashCode() method in the Object class?
A. Object
B. int
C. long
D. void
Answer: B
5. What is the size of an int variable in Java?
A. 8 bit
B. 16 bit
C. 32 bit
D. 64 bit
Answer: C
6. Which of the following is not a keyword in Java?
A. static
B. Boolean
C. void
D. private
Answer: B
7. Which exception is thrown when an array is accessed with an illegal index?
A. ArithmeticException
B. NullPointerException
C. ArrayIndexOutOfBoundsException
D. NumberFormatException
Answer: C
8. What is the default value of a local variable?
A. null
B. 0
C. depends on data type
D. No default value
Answer: D
9. Which method can be defined only once in a program?
A. main method
B. finalize method
C. static method
D. private method
Answer: A
10. Which of these is used to handle exceptions in Java?
A. try
B. catch
C. finally
D. All of the above
Answer: D
11. Which of these is not a type of constructor in Java?
A. Default
B. Parameterized
C. Copy
D. Friend
Answer: D
12. Which collection class allows you to grow or shrink its size and provides indexed access to its
elements?
A. Java.util.HashSet
B. Java.util.LinkedList
C. Java.util.ArrayList
D. Java.util.List
Answer: C
13. Which interface does java.util.HashTable implement?
A. Map
B. List