0% found this document useful (0 votes)
5 views5 pages

Java Language Note

Uploaded by

lionheartav7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Java Language Note

Uploaded by

lionheartav7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Introduction
• Java is a high-level, object-oriented, platform-independent programming language.
• Developed by James Gosling at Sun Microsystems (1995).
• Motto: “Write Once, Run Anywhere” (WORA).

2. Features of Java
• Platform Independent → Runs on JVM (Java Virtual Machine).
• Object-Oriented → Based on classes & objects.
• Robust → Strong memory management & exception handling.
• Secure → No explicit pointers, bytecode verification.
• Multithreaded → Supports concurrent execution.
• Portable → Same code runs on different platforms.

3. Java Program Structure


class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

• class → blueprint for objects.


• main() → entry point.
• System.out.println() → prints output.

4. Data Types
Primitive Data Types:

• byte → 1 byte (–128 to 127)


• short → 2 bytes
• int → 4 bytes
• long → 8 bytes
• float → 4 bytes (decimal)
• double → 8 bytes (decimal)
• char → 2 bytes (Unicode)
• boolean → true/false

Non-Primitive:

• String, Arrays, Classes, Interfaces


5. Variables
int age = 25;
final double PI = 3.14; // constant

• Local Variable → declared inside a method.


• Instance Variable → declared inside class but outside methods.
• Static Variable → shared among all objects.

6. Operators
• Arithmetic → +, -, *, /, %
• Relational → ==, !=, >, <, >=, <=
• Logical → &&, ||, !
• Assignment → =, +=, -=
• Unary → ++, --

7. Control Statements
Conditional:
if (a > b) {
...
} else if (a == b) {
...
} else {
...
}

Switch:
switch(day) {
case 1: System.out.println("Mon"); break;
case 2: System.out.println("Tue"); break;
default: System.out.println("Invalid");
}

Loops:

• for → for(int i=0; i<5; i++)


• while → while(i<5)
• do-while → executes at least once
8. OOPs Concepts
1. Class → blueprint
2. Object → instance of a class
3. Inheritance → acquiring properties (extends)
4. Polymorphism → method overloading/overriding
5. Encapsulation → data hiding using private
6. Abstraction → abstract classes & interfaces

9. Methods
int add(int a, int b) {
return a + b;
}

• Method Overloading → same name, different parameters.


• Method Overriding → child class redefines parent method.

10. Constructors
class Student {
Student() { // default constructor
System.out.println("Student created");
}
}

• Default (no arguments)


• Parameterized (arguments given)
• Constructor Overloading supported.

11. Arrays
int[] arr = {10, 20, 30};
for(int i : arr) {
System.out.println(i);
}

• Single Dimensional → int[] arr = new int[5];


• Multi-Dimensional → int[][] matrix = new int[3][3];

12. Strings
String s = "Java";
System.out.println(s.length());
System.out.println(s.toUpperCase());

• Immutable → cannot be changed.


• Use StringBuilder/StringBuffer for mutable strings.

13. Exception Handling


try {
int x = 10/0;
} catch(Exception e) {
System.out.println(e);
} finally {
System.out.println("Always executed");
}

• Checked Exception → compile-time (IOException).


• Unchecked Exception → runtime (ArithmeticException).

14. Collections Framework


• List → ArrayList, LinkedList
• Set → HashSet, TreeSet
• Map → HashMap, TreeMap

15. Multithreading
class MyThread extends Thread {
public void run() {
System.out.println("Thread running");
}
}
MyThread t = new MyThread();
t.start();

• Thread creation → extends Thread / implements Runnable


• Methods: start(), run(), sleep(), join().

16. File Handling


import java.io.*;
class FileDemo {
public static void main(String[] args) throws IOException {
FileWriter fw = new FileWriter("test.txt");
fw.write("Hello Java");
fw.close();
}
}

17. Java Keywords


• abstract, break, class, continue, do, else, final, for, if, import, new, package,
private, protected, public, return, static, super, switch, this, try, while, void,
volatile, synchronized etc.

18. Java Versions (Highlights)


• Java 5 → Generics, Enum, Autoboxing.
• Java 8 → Lambda expressions, Streams, Default methods.
• Java 11+ → var keyword, new HTTP Client, Records.

You might also like