Java Programming – 5th Semester (NEP 2020)
Complete Notes – Unit 1
UNIT – 1 : Introduction to Java Programming
1. Introduction to Java
Java is a high-level, object-oriented, platform-independent programming language. It follows the
principle: Write Once, Run Anywhere (WORA).
2. Features of Java
• Simple
• Object Oriented
• Platform Independent
• Secure
• Robust
• Multithreaded
• Portable
3. Java Architecture
Source Code (.java) → Compiler → Bytecode (.class) → JVM
JDK = JRE + Development Tools
JRE = JVM + Libraries
4. Basic Syntax
class Hello {
public static void main(String[] args) {
[Link]("Hello Java");
}
}
5. Data Types
Primitive: int, float, double, char, boolean
Non-primitive: String, Arrays, Objects
6. Operators
Arithmetic, Relational, Logical, Assignment, Unary, Conditional
7. Control Statements
if, if-else, switch, for loop, while loop, do-while
8. Arrays
int[] a = {10, 20, 30};
9. Strings
String s = "Hello";
Important methods: length(), charAt(), substring(), toUpperCase()
SOLVED PROGRAMS
1. Check Even or Odd
import [Link].*;
class EvenOdd {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
if(n % 2 == 0)
[Link]("Even");
else
[Link]("Odd");
}
}
2. Largest of Three Numbers
import [Link].*;
class Largest {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int a=[Link](), b=[Link](), c=[Link]();
if(a>b && a>c)
[Link](a + " Biggest");
else if(b>a && b>c)
[Link](b + " Biggest");
else
[Link](c + " Biggest");
}
}
3. Print 1 to 10
for(int i=1;i<=10;i++)
[Link](i);
4. Largest Element in Array
int[] a = {5,8,12,3,7};
int max = a[0];
for(int i=0;i if(a[i] > max) max = a[i];
[Link](max);
End of Unit 1