0% found this document useful (0 votes)
2 views2 pages

Java Unit1 Ipad Notes 1

The document provides comprehensive notes on Object-Oriented Programming (OOP) with Java, covering its history, data types, core concepts, and key features. It includes explanations of the Java Virtual Machine (JVM), Java Runtime Environment (JRE), and Java Development Kit (JDK), as well as code examples demonstrating various OOP principles like encapsulation, inheritance, and polymorphism. Additionally, it outlines control flow, operators, and the use of packages in Java programming.

Uploaded by

rajgahoi01
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)
2 views2 pages

Java Unit1 Ipad Notes 1

The document provides comprehensive notes on Object-Oriented Programming (OOP) with Java, covering its history, data types, core concepts, and key features. It includes explanations of the Java Virtual Machine (JVM), Java Runtime Environment (JRE), and Java Development Kit (JDK), as well as code examples demonstrating various OOP principles like encapsulation, inheritance, and polymorphism. Additionally, it outlines control flow, operators, and the use of packages in Java programming.

Uploaded by

rajgahoi01
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

■ OOP WITH JAVA — BCS 403 | UNIT 1 COMPLETE NOTES Notes by Raj Gahoi

BCS-403 | KCC ITM | 2026


History · JVM/JRE/JDK · Data Types · OOP Concepts · Packages · Code Examples

■ HISTORY OF JAVA ■ DATA TYPES & VARIABLES ■ ACCESS SPECIFIERS


● 1991 — Green Team @ Sun Microsystems Type Size Default Note Modifier Class Package Subclass World
● Members: James Gosling, Mike Sheridan, Patrick Naughton
boolean 1 bit false true/false private ■ ■ ■ ■
● Goal: Software for consumer electronics
● C++ rejected — complex, platform-dependent char 2B \u0000 Unicode default ■ ■ ■ ■
● GreenTalk → Oak → Java (1995)
byte 1B 0 -128 to 127 protected ■ ■ ■ ■
● "Oak" trademarked → renamed to Java (coffee!)
● 1995: Netscape + Java → Applets famous short 2B 0 2 bytes public ■ ■ ■ ■
● 2010: Oracle acquired Sun Microsystems int 4B 0 Default int ■ private < default < protected < public
■ Memory: GO → Oak → Java → Oracle
long 8B 0L Suffix: L
Ver Year What
■ OOP CORE CONCEPTS
float 4B 0.0f Suffix: f
JDK 1.0 1996 First release ■ Encapsulation
double 8B 0.0d Default decimal ● private fields + public getters/setters. Data hiding. Bind
Java 2 1998 J2SE data+methods.
Non-Primitive: String | Array | Class | Interface
Java 8 2014 Lambdas ■ Inheritance
Type Where Stored Init?
● extends keyword. Child gets parent properties. Code reuse.
Java 9 2017 Modules
Local In method Stack Manual ■ Polymorphism
17/21 LTS Enterprise ● One name many forms. Overloading (compile) + Overriding
Instance In class Heap Auto
(runtime).
■ 9 JAVA FEATURES (BUZZWORDS) Static static kw Method Area Auto, shared ■ Abstraction
● Hide impl details. via abstract class OR interface.
Feature Why? ■ OPERATORS
Type Structure Java?
■ Platform Indep WORA — Bytecode runs on any OS via JVM
Type Symbol Example Single A→B ■
■ Object-Oriented Encap, Inherit, Poly, Abstraction
Arithmetic +-*/% a+b, a%b Multilevel A→B→C ■
■ Simple No pointers, no op-overloading, no multiple inherit
Relational == != > < a==b → bool Hierarchical A→B,A→C ■
■ Robust Auto GC + Exception Handling + type-checking
Logical && || ! Short-circuit Multiple(class) A,B→C ■
■ Secure No pointers, JVM Sandbox, Bytecode Verifier
Bitwise &|^~ Bit-level ops Multiple(iface) impl A,B ■
■ Multithreaded Thread class + Runnable interface
Left Shift n<<k n×2^k 10<<2=40 Hybrid Mixed ■
■ Distributed RMI + EJB support
Right Shift n>>k n÷2^k 10>>2=2 ■ Overloading = same name, diff params (compile-time)
■■ Dynamic Dynamic class loading + JIT
Unsigned n>>>k Fills 0s ■ Overriding = same name+params, diff class (runtime)
■ High Performance JIT: bytecode → native machine code ■ Upcasting: Animal a = new Dog();
Ternary (c)?t:f Inline if-else
■ Memory: POSS-MDYH (Platform, OOP, Simple, Secure,
■ ABSTRACT CLASS VS INTERFACE
Multithreaded, Distributed, Dynamic, High-perf) ■ CONTROL FLOW
Abstract Class Interface
■■ JVM | JRE | JDK Selection: if-else | switch (int, char, String, enum)
Loops: Keyword abstract class interface
JVM = ClassLoader + RuntimeAreas + ExecutionEngine ● for(init;cond;incr) — when count is known All abstract (Java8: default/static
JRE = JVM + Library Classes ([Link]) ● while — entry-controlled, checks first Methods Abstract+Concrete
ok)
JDK = JRE + Dev Tools → JDK ⊃ JRE ⊃ JVM ● do-while — exit-controlled, runs at least once
Variables Any type public static final
Component Purpose ● for-each: for(Type v : array) — collections
Jump: break (exit loop) | continue (skip iter) | return (exit method) Inherit Extend ONE Implement MULTIPLE
Class Loader Bootstrap→Extension→App. Loads .class
Constructor ■ Yes ■ No
Method Area Class info, static vars, bytecode ■ ARRAYS & STRINGS
Use when Partial impl Contract/Multiple inherit
Heap All objects live here (GC works here) 1D: int[] arr = new int[5]; or {10,20,30}
Stack Local vars, method call frames 2D: int[][] arr = new int[3][3];
■ PACKAGES
Jagged: rows with different column counts
PC Register Tracks current instruction Purpose: Group related classes. Avoid naming conflicts. Modular
StringBuffer StringBuilder
JIT Compiler Hot bytecode → native machine code code.
Sync ■ Thread-safe ■ Not safe Declare: package mypack; (1st line) Import: import mypack.A;
Garbage Collector Auto reclaims unused objects
Speed Slower Faster Compile: javac -d . [Link] | Run: java B
Tool Does What?
Since Java 1.0 Java 1.5 Package Key Classes
javac Compiles .java → .class
Use Multi-thread Single-thread [Link] System, String, Math (auto-imported)
java Runs .class (JVM launcher)
String Methods: length() | charAt(i) | substring(i) | equals(s) | [Link] Scanner, ArrayList, HashMap
javadoc Generates HTML docs equalsIgnoreCase(s) | concat(s) | toUpperCase() | indexOf(c) [Link] FileReader, BufferedReader
jar Packages .class into .jar ■ String = Immutable | StringBuffer/Builder = Mutable [Link] Socket, URL, ServerSocket
jdb Debugger
■■ CLASSES, METHODS & CONSTRUCTORS [Link] Frame, Button (GUI)
Key: JVM is Platform Dependent but Bytecode is Platform Independent
[Link] Connection, Statement (DB)
Constructor Method
■ SOURCE FILE & MAIN() CLASSPATH: Env var → tells JVM where .class files are
Purpose Initialize object Define behavior
JAR: jar -cf [Link] *.class (compress + distribute)
Order in .java file: Name = Class name Any name Static Import: import static [Link].*; → use sqrt() directly
● ① Documentation (optional)
● ② package statement (1st exec line) Return None (not void) Must specify
● ③ import statements Called Implicit (new) Explicit
● ④ interface definition
Inherit ■ No ■ Yes
● ⑤ class definition (MANDATORY)
Rule: Only ONE public class per file. Filename = public class name. Default Compiler gives None

Keyword Why Needed? class Rect { int l,w;


Rect(int l,int w){this.l=l;this.w=w;}
public JVM accesses from outside int area(){ return l*w; } }
static No object needed to call

void Returns nothing

String[] args Command-line arguments


.java→[javac]→.class→[JVM]→Machine Code→OS

Page 1 of 2 · BCS-403 Unit 1 · Notes by Raj Gahoi · All topics covered Pg 1


■ OOP WITH JAVA — BCS 403 | UNIT 1 COMPLETE NOTES Notes by Raj Gahoi
BCS-403 | KCC ITM | 2026
History · JVM/JRE/JDK · Data Types · OOP Concepts · Packages · Code Examples

■ KEY CODE EXAMPLES ■ STRING & ARRAY CODE ■■ QUICK REFERENCE — KEYWORDS
Hello World String Methods Demo Keyword Purpose
class Hello{ String s1="Hello", s2="World"; extends Inherit from class
public static void main(String[] a){ [Link]() → 5
[Link]("Hello World"); [Link](1) → e implements Use interface
} [Link](s2) → HelloWorld
abstract Abstract class/method
} [Link]("hello")→ false
[Link]("hello") → true interface Define interface
Type Casting StringBuffer sb=new StringBuffer("Hello");
int x=10; double y=x; //Widening (auto) static Class-level member
[Link](" Java"); // Hello Java (mutable!)
double d=10.5; int i=(int)d; //Narrowing String s3=new String("Hello"); final Constant/no-override/no-inherit
// i = 10 (decimal truncated) s1==s3 → false (reference)
super Call parent constructor/method
Bitwise Operators [Link](s3) → true (content)
this Refers to current object
int a=5, b=1; //a=0101 b=0001 Array Demo
a & b → 0001 = 1 a | b → 0101 = 5 int[] arr={10,20,30,40}; new Create object
10 << 2 → 40 10 >> 2 → 2 int sum=0;
package Declare package
Reverse a Number for(int x:arr) sum+=x; // for-each
// 2D Matrix Addition import Import class or package
int n=1234, rev=0;
int a[][]={{1,2},{3,4}};
while(n!=0){ void No return value
int b[][]={{1,1},{1,1}};
rev = rev*10 + n%10;
c[i][j]=a[i][j]+b[i][j]; instanceof Check object type at runtime
n /= 10;
} // rev = 4321 @Override Mark method as override
■ STATIC VS NON-STATIC
■ OOP CODE EXAMPLES Static Non-Static ■ KEY FORMULAS TO REMEMBER
Encapsulation Belongs Class Object JVM = ClassLoader + MemAreas + ExecEngine
class Person { Call via ClassName.m() obj.m() JRE = JVM + LibraryClasses ([Link])
private String name; JDK = JRE + DevTools
public String getName(){return name;} Memory Once (class load) Per object JDK ⊃ JRE ⊃ JVM
public void setName(String n){name=n;}
Access Static only Both .java →[javac]→ .class →[JVM]→ Output
}
this ■ ■ Left Shift: n << k = n × 2^k
Inheritance + Runtime Polymorphism 10 << 2 = 40
class Bank{ int getRate(){return 0;} } Override ■ Hidden ■ Runtime Right Shift: n >> k = n / 2^k
class SBI extends Bank{ class Ex { 10 >> 2 = 2
int getRate(){return 8;} }//Override static int count=0;
Bank b = new SBI(); //Upcasting static void show(){ //no object needed ■ MIND MAP SUMMARY
[Link](); // → 8 (SBI version!) [Link](count);
} ■ History GreenTalk→Oak→Java | Gosling | Oracle
Interface (Multiple Inheritance)
}
interface Printable{void print();} [Link](); // Direct class call ■ Features WORA, OOP, Secure, Robust, Multi-thread
interface Showable {void show(); }
class Doc implements Printable,Showable{ ■■ JVM/JRE/JDK JDK⊃JRE⊃JVM | ClassLoader | JIT | GC
■ PACKAGE & STATIC IMPORT CODE
public void print(){[Link]("Print");}
public void show() {[Link]("Show"); } // [Link] ■ Data Types 8 primitive types + Non-Primitive
} package pack;
■ Control Flow if/switch | 4 loops | break/continue
public class A {
public void msg(){ ■■ OOP Encap | Inherit | Poly | Abstract
[Link]("Hello Package");
} ■ Interfaces Multiple inherit | Contract | No constructor
}
// Compile: javac -d . [Link] [Link] auto | CLASSPATH | JAR | static
// [Link] ■ Packages import
import pack.A;
class B { ■ MEMORY TRICKS
public static void main(String a[]){
■ Java Name: GO → Oak → Java (GO = Gosling+Oak)
new A().msg(); }}
// Run: java B ■ 9 Features: POSS-MDYH →
// Static Import Platform,OOP,Simple,Secure,Multi,Dist,Dynamic,Y=High-Perf
import static [Link].*; ■ Access: private→default→protected→public (least→most)
import static [Link]; ■ Loops: FWDf = For, While, Do-while, for-each
[Link](sqrt(16)); // 4.0 ■ String: String=Frozen | Buffer=Safe | Builder=Fast
[Link](pow(2,10)); // 1024.0
■ Shift: << = ×2 | >> = ÷2

Page 1 of 2 · BCS-403 Unit 1 · Notes by Raj Gahoi · All topics covered Pg 1

You might also like