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

Java Notes Units 1 To 5

The document provides an overview of Object-Oriented Programming (OOP) concepts, including definitions of objects, classes, abstraction, encapsulation, and information hiding, along with the merits of OOP such as modularity and reusability. It also covers Java features, syntax, data types, control statements, inheritance, polymorphism, exception handling, multithreading, and Java I/O operations. Additionally, it discusses applet life cycles and event handling in Java.

Uploaded by

j3136341
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)
62 views5 pages

Java Notes Units 1 To 5

The document provides an overview of Object-Oriented Programming (OOP) concepts, including definitions of objects, classes, abstraction, encapsulation, and information hiding, along with the merits of OOP such as modularity and reusability. It also covers Java features, syntax, data types, control statements, inheritance, polymorphism, exception handling, multithreading, and Java I/O operations. Additionally, it discusses applet life cycles and event handling in Java.

Uploaded by

j3136341
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

UNIT I - Introduction to OOP

Object-Oriented Concepts
Object: Real-world entity with state (data) and behavior (methods).
Class: Blueprint/template from which objects are created.
Abstraction: Showing only essential features, hiding details.
Encapsulation: Wrapping data and methods into a single unit.
Information Hiding: Restricting access to internal details.

Merits of OOP
Modularity, Reusability, Scalability, Security, Flexibility.

Object Model
Definition, State, Behavior, Identity, Messages.

Constructors
Special method to initialize objects. Constructor overloading allows multiple constructors.
class Student {
String name; int age;
Student() { name = "Unknown"; age = 0; }
Student(String n, int a) { name = n; age = a; }
}

Access Modifiers
public: Accessible everywhere. private: Within class. protected: Package + subclass. default:
Package only.
UNIT II - Java Classes & Objects
Java Features
Simple, Platform Independent, Object-Oriented, Robust, Secure, Multithreaded, Distributed,
Dynamic.

Java Syntax & Data Types


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

Data Type Conversions


Implicit (Widening) and Explicit (Narrowing) conversions.

Control Statements
Selection: if, if-else, switch. Iteration: for, while, do-while. Jump: break, continue, return.

String Handling
String s1 = "Hello";
String s2 = new String("World");

Wrapper Classes
Integer a = 5; // autoboxing
int b = a; // unboxing

Arrays & Vectors


int[] arr = {1, 2, 3};
Vector v = new Vector<>();
v.add(10);
UNIT III - Inheritance & Polymorphism
Inheritance
Single, Multilevel, Hierarchical inheritance types. Merits: reusability. Demerits: complexity.

Polymorphism
class A { void show() { System.out.println("A"); } }
class B extends A { void show() { System.out.println("B"); } }
A obj = new B();
obj.show(); // Output: B

Abstract Classes
abstract class Shape {
abstract void draw();
}

Interfaces
interface Printable { void print(); }

Packages
Built-in: java.util, java.io, java.lang. User-defined: package mypack;
UNIT IV - Exception Handling & Multithreading
Exception Handling
try {
// code
} catch(Exception e) {
System.out.println(e);
} finally {
// always executes
}

Custom Exceptions
class MyException extends Exception {
MyException(String msg) { super(msg); }
}

Multithreading
Create threads by extending Thread or implementing Runnable.
synchronized void display() { ... }
UNIT V - Java I/O, Applets & Event Handling
Java I/O
FileWriter fw = new FileWriter("test.txt");
fw.write("Hello");
fw.close();

Applets Life Cycle


init(), start(), paint(), stop(), destroy().

Event Handling
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Button Clicked");
}
});

You might also like