Java Zero to Advanced
Prepared By Urveesh ■
This book is designed for students who want to learn Java from absolute beginner to advanced
level. It includes theory, code examples, practice programs, MCQs, and exam tips. Light humor is
included because debugging without humor is illegal in developer society. ■
Java Basics
Java is a high■level, object■oriented programming language developed by Sun Microsystems
Key Features:
- Platform Independent
- Object Oriented
- Secure
- Robust
- Multithreaded
- Portable
Write Once Run Anywhere means compiled Java code runs on any system with JVM.
JVM JRE JDK
JVM – Java Virtual Machine executes bytecode.
JRE – Java Runtime Environment provides libraries and JVM.
JDK – Java Development Kit includes compiler and tools.
Shortcut memory trick:
JDK > JRE > JVM
First Java Program
public class HelloWorld{
public static void main(String[] args){
[Link]("Hello World");
}
}
Variables and Data Types
Primitive Data Types:
byte, short, int, long
float, double
char
boolean
Example:
int age = 21;
double price = 199.99;
String name = "Developer";
Control Statements
if, else, switch
loops: for, while, do while
Example:
for(int i=0;i<5;i++){
[Link](i);
}
Arrays
Arrays store multiple values of same data type.
int arr[] = {1,2,3,4};
[Link](arr[0]);
OOP Concepts
Encapsulation – binding data and methods together.
Inheritance – acquiring properties of parent class.
Polymorphism – many forms of method behavior.
Abstraction – hiding implementation details.
Classes and Objects
class Student{
String name;
int age;
}
Student s = new Student();
Constructor
Constructor is called automatically when object is created.
class Test{
Test(){
[Link]("Constructor called");
}
}
Inheritance
class Animal{
void eat(){
[Link]("Eating");
}
}
class Dog extends Animal{
void bark(){
[Link]("Barking");
}
}
Exception Handling
try{
int a = 10/0;
}catch(Exception e){
[Link]("Handled");
}
Multithreading
Thread allows parallel execution.
Thread t = new Thread();
[Link]();
Collections Framework
Important classes:
ArrayList
HashMap
HashSet
LinkedList
Practice Java Programs (Very Important for Exams)
Program 1: Addition of Two Numbers
int a=5,b=10; [Link](a+b);
Program 2: Even or Odd
int n=4; if(n%2==0) [Link]("Even"); else [Link]("Odd");
Program 3: Factorial
int f=1; for(int i=1;i<=5;i++) f*=i;
Program 4: Fibonacci
int a=0,b=1,c; for(int i=0;i<10;i++){ c=a+b; a=b; b=c;}
Program 5: Reverse Number
int n=123,rev=0;
Program 6: Palindrome Check
compare original and reverse number
Program 7: Prime Number
loop from 2 to n-1
Program 8: Array Sum
sum elements of array
Program 9: Largest Element
find max in array
Program 10: Hello World
[Link]("Hello World");
Program 11: Addition of Two Numbers
int a=5,b=10; [Link](a+b);
Program 12: Even or Odd
int n=4; if(n%2==0) [Link]("Even"); else [Link]("Odd");
Program 13: Factorial
int f=1; for(int i=1;i<=5;i++) f*=i;
Program 14: Fibonacci
int a=0,b=1,c; for(int i=0;i<10;i++){ c=a+b; a=b; b=c;}
Program 15: Reverse Number
int n=123,rev=0;
Program 16: Palindrome Check
compare original and reverse number
Program 17: Prime Number
loop from 2 to n-1
Program 18: Array Sum
sum elements of array
Program 19: Largest Element
find max in array
Program 20: Hello World
[Link]("Hello World");
Program 21: Addition of Two Numbers
int a=5,b=10; [Link](a+b);
Program 22: Even or Odd
int n=4; if(n%2==0) [Link]("Even"); else [Link]("Odd");
Program 23: Factorial
int f=1; for(int i=1;i<=5;i++) f*=i;
Program 24: Fibonacci
int a=0,b=1,c; for(int i=0;i<10;i++){ c=a+b; a=b; b=c;}
Program 25: Reverse Number
int n=123,rev=0;
Program 26: Palindrome Check
compare original and reverse number
Program 27: Prime Number
loop from 2 to n-1
Program 28: Array Sum
sum elements of array
Program 29: Largest Element
find max in array
Program 30: Hello World
[Link]("Hello World");
Program 31: Addition of Two Numbers
int a=5,b=10; [Link](a+b);
Program 32: Even or Odd
int n=4; if(n%2==0) [Link]("Even"); else [Link]("Odd");
Program 33: Factorial
int f=1; for(int i=1;i<=5;i++) f*=i;
Program 34: Fibonacci
int a=0,b=1,c; for(int i=0;i<10;i++){ c=a+b; a=b; b=c;}
Program 35: Reverse Number
int n=123,rev=0;
Program 36: Palindrome Check
compare original and reverse number
Program 37: Prime Number
loop from 2 to n-1
Program 38: Array Sum
sum elements of array
Program 39: Largest Element
find max in array
Program 40: Hello World
[Link]("Hello World");
Program 41: Addition of Two Numbers
int a=5,b=10; [Link](a+b);
Program 42: Even or Odd
int n=4; if(n%2==0) [Link]("Even"); else [Link]("Odd");
Program 43: Factorial
int f=1; for(int i=1;i<=5;i++) f*=i;
Program 44: Fibonacci
int a=0,b=1,c; for(int i=0;i<10;i++){ c=a+b; a=b; b=c;}
Program 45: Reverse Number
int n=123,rev=0;
Program 46: Palindrome Check
compare original and reverse number
Program 47: Prime Number
loop from 2 to n-1
Program 48: Array Sum
sum elements of array
Program 49: Largest Element
find max in array
Program 50: Hello World
[Link]("Hello World");
Java MCQs for Exam Practice
1. Which keyword creates object?
Answer: new
2. Java is language
Answer: Object Oriented
3. Which loop executes at least once?
Answer: do while
4. Which collection stores key value pairs?
Answer: HashMap
5. Java is developed by?
Answer: Sun Microsystems
6. Which keyword creates object?
Answer: new
7. Java is language
Answer: Object Oriented
8. Which loop executes at least once?
Answer: do while
9. Which collection stores key value pairs?
Answer: HashMap
10. Java is developed by?
Answer: Sun Microsystems
11. Which keyword creates object?
Answer: new
12. Java is language
Answer: Object Oriented
13. Which loop executes at least once?
Answer: do while
14. Which collection stores key value pairs?
Answer: HashMap
15. Java is developed by?
Answer: Sun Microsystems
16. Which keyword creates object?
Answer: new
17. Java is language
Answer: Object Oriented
18. Which loop executes at least once?
Answer: do while
19. Which collection stores key value pairs?
Answer: HashMap
20. Java is developed by?
Answer: Sun Microsystems
21. Which keyword creates object?
Answer: new
22. Java is language
Answer: Object Oriented
23. Which loop executes at least once?
Answer: do while
24. Which collection stores key value pairs?
Answer: HashMap
25. Java is developed by?
Answer: Sun Microsystems
26. Which keyword creates object?
Answer: new
27. Java is language
Answer: Object Oriented
28. Which loop executes at least once?
Answer: do while
29. Which collection stores key value pairs?
Answer: HashMap
30. Java is developed by?
Answer: Sun Microsystems
31. Which keyword creates object?
Answer: new
32. Java is language
Answer: Object Oriented
33. Which loop executes at least once?
Answer: do while
34. Which collection stores key value pairs?
Answer: HashMap
35. Java is developed by?
Answer: Sun Microsystems
36. Which keyword creates object?
Answer: new
37. Java is language
Answer: Object Oriented
38. Which loop executes at least once?
Answer: do while
39. Which collection stores key value pairs?
Answer: HashMap
40. Java is developed by?
Answer: Sun Microsystems
41. Which keyword creates object?
Answer: new
42. Java is language
Answer: Object Oriented
43. Which loop executes at least once?
Answer: do while
44. Which collection stores key value pairs?
Answer: HashMap
45. Java is developed by?
Answer: Sun Microsystems
46. Which keyword creates object?
Answer: new
47. Java is language
Answer: Object Oriented
48. Which loop executes at least once?
Answer: do while
49. Which collection stores key value pairs?
Answer: HashMap
50. Java is developed by?
Answer: Sun Microsystems
51. Which keyword creates object?
Answer: new
52. Java is language
Answer: Object Oriented
53. Which loop executes at least once?
Answer: do while
54. Which collection stores key value pairs?
Answer: HashMap
55. Java is developed by?
Answer: Sun Microsystems
56. Which keyword creates object?
Answer: new
57. Java is language
Answer: Object Oriented
58. Which loop executes at least once?
Answer: do while
59. Which collection stores key value pairs?
Answer: HashMap
60. Java is developed by?
Answer: Sun Microsystems
61. Which keyword creates object?
Answer: new
62. Java is language
Answer: Object Oriented
63. Which loop executes at least once?
Answer: do while
64. Which collection stores key value pairs?
Answer: HashMap
65. Java is developed by?
Answer: Sun Microsystems
66. Which keyword creates object?
Answer: new
67. Java is language
Answer: Object Oriented
68. Which loop executes at least once?
Answer: do while
69. Which collection stores key value pairs?
Answer: HashMap
70. Java is developed by?
Answer: Sun Microsystems
71. Which keyword creates object?
Answer: new
72. Java is language
Answer: Object Oriented
73. Which loop executes at least once?
Answer: do while
74. Which collection stores key value pairs?
Answer: HashMap
75. Java is developed by?
Answer: Sun Microsystems
76. Which keyword creates object?
Answer: new
77. Java is language
Answer: Object Oriented
78. Which loop executes at least once?
Answer: do while
79. Which collection stores key value pairs?
Answer: HashMap
80. Java is developed by?
Answer: Sun Microsystems
81. Which keyword creates object?
Answer: new
82. Java is language
Answer: Object Oriented
83. Which loop executes at least once?
Answer: do while
84. Which collection stores key value pairs?
Answer: HashMap
85. Java is developed by?
Answer: Sun Microsystems
86. Which keyword creates object?
Answer: new
87. Java is language
Answer: Object Oriented
88. Which loop executes at least once?
Answer: do while
89. Which collection stores key value pairs?
Answer: HashMap
90. Java is developed by?
Answer: Sun Microsystems
91. Which keyword creates object?
Answer: new
92. Java is language
Answer: Object Oriented
93. Which loop executes at least once?
Answer: do while
94. Which collection stores key value pairs?
Answer: HashMap
95. Java is developed by?
Answer: Sun Microsystems
96. Which keyword creates object?
Answer: new
97. Java is language
Answer: Object Oriented
98. Which loop executes at least once?
Answer: do while
99. Which collection stores key value pairs?
Answer: HashMap
100. Java is developed by?
Answer: Sun Microsystems
Final Exam Strategy
1. Focus on OOP concepts 2. Practice 20–30 programs 3. Remember definitions 4. Write clean
syntax in exam And remember: if code works first time, developer gets suspicious. ■