0% found this document useful (0 votes)
7 views7 pages

Java Shorts

This document provides a comprehensive overview of Java, covering its introduction, features, architecture, basic syntax, data types, operators, control statements, and object-oriented programming concepts. It also discusses advanced topics such as inheritance, polymorphism, abstraction, exception handling, multithreading, and the collections framework. Additionally, it highlights important keywords and concepts like static, final, and JDBC for database connections.

Uploaded by

saha.arghaq
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)
7 views7 pages

Java Shorts

This document provides a comprehensive overview of Java, covering its introduction, features, architecture, basic syntax, data types, operators, control statements, and object-oriented programming concepts. It also discusses advanced topics such as inheritance, polymorphism, abstraction, exception handling, multithreading, and the collections framework. Additionally, it highlights important keywords and concepts like static, final, and JDBC for database connections.

Uploaded by

saha.arghaq
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/ 7

JAVA NOTES

1. Introduction to Java

• Java is an object-oriented, platform-independent, and secure programming


language developed by James Gosling at Sun Microsystems (1995).

• JVM (Java Virtual Machine): Executes Java bytecode.

• JRE (Java Runtime Environment): Provides libraries + JVM.

• JDK (Java Development Kit): Contains compiler (javac), JRE, and tools.

2. Features of Java

1. Simple and easy to learn

2. Object-Oriented

3. Platform Independent (Write Once, Run Anywhere)

4. Secure (no pointers, bytecode verification)

5. Robust (exception handling, garbage collection)

6. Multithreaded

7. High Performance (JIT compiler)

8. Distributed

9. Dynamic and Portable

3. Java Architecture

• Source Code → Compiler → Bytecode → JVM → Machine Code

• JVM Components:

o Class Loader

o Memory Areas (Heap, Stack, Method Area)

o Execution Engine (Interpreter + JIT)

o Garbage Collector
4. Basic Syntax

class Hello {

public static void main(String args[]) {

System.out.println("Hello, World!");

Compile: javac Hello.java


Run: java Hello

5. Data Types

Type Size Example

byte 1 byte byte a = 10;

short 2 bytes short s = 200;

int 4 bytes int x = 1000;

long 8 bytes long l = 12345L;

float 4 bytes float f = 10.5f;

double 8 bytes double d = 99.99;

char 2 bytes char c = 'A';

boolean 1 bit boolean flag = true;

6. Operators

• Arithmetic: +, -, *, /, %

• Relational: ==, !=, <, >, <=, >=

• Logical: &&, ||, !

• Assignment: =, +=, -=

• Increment/Decrement: ++, --

• Ternary: condition ? a : b
7. Control Statements

• If-else

• Switch

• Loops: for, while, do-while

• Jump: break, continue, return

8. Object-Oriented Programming (OOP)

Main Concepts:

1. Class: Blueprint for objects.

2. Object: Instance of a class.

3. Encapsulation: Binding data and methods.

4. Inheritance: Reuse of properties (using extends).

5. Polymorphism: One name, many forms (method overloading/overriding).

6. Abstraction: Hiding details using abstract classes or interface.

9. Constructors

• Special method used to initialize objects.

class Student {

int id;

String name;

Student(int i, String n) {

id = i; name = n;

• Default, Parameterized, Copy Constructor

10. Inheritance
class A {

void display() { System.out.println("A"); }

class B extends A {

void show() { System.out.println("B"); }

Types: Single, Multilevel, Hierarchical


(No multiple inheritance with classes — use interfaces)

11. Polymorphism

• Compile-time (Overloading)

• Runtime (Overriding)

class A {

void show() { System.out.println("A"); }

class B extends A {

void show() { System.out.println("B"); }

12. Abstraction

• Abstract class: abstract keyword, may have abstract methods.

• Interface: Fully abstract (all methods public & abstract).

interface Animal {

void sound();

class Dog implements Animal {

public void sound() { System.out.println("Bark"); }

}
13. Packages

• Group of related classes.

package mypack;

import java.util.*;

14. Exception Handling

Keywords: try, catch, finally, throw, throws

try {

int a = 5 / 0;

} catch (ArithmeticException e) {

System.out.println(e);

} finally {

System.out.println("Always executes");

15. File Handling (java.io)

• FileReader, FileWriter, BufferedReader, PrintWriter

FileWriter fw = new FileWriter("data.txt");

fw.write("Hello Java");

fw.close();

16. Multithreading

class MyThread extends Thread {

public void run() {

System.out.println("Thread running...");

}
MyThread t1 = new MyThread();

t1.start();

• Thread lifecycle: New → Runnable → Running → Waiting → Terminated

17. Collections Framework

Interface Implementation

List ArrayList, LinkedList

Set HashSet, TreeSet

Map HashMap, TreeMap

Queue PriorityQueue

18. Strings

String s = "Java";

System.out.println(s.length());

System.out.println(s.toUpperCase());

System.out.println(s.equals("JAVA"));

• StringBuffer and StringBuilder are mutable.

19. Java Input/Output

import java.util.Scanner;

Scanner sc = new Scanner(System.in);

System.out.println("Enter name:");

String name = sc.nextLine();

20. Important Topics Summary

• Static Keyword

• Final Keyword
• this and super keywords

• Wrapper Classes (Integer, Double, etc.)

• Garbage Collection

• Inner Classes

• JDBC (for database connection)

You might also like