JAVA NOTES
Multithreading: An Introduction
1. Multithreading kya hai? - Multithreading ek technique hai
jisme ek hi program ke multiple threads simultaneously
execute hote hain. Har thread apna independent task perform
karta hai.
2. Benefits of Multithreading - Multithreading se CPU ka
utilization better hota hai, application responsiveness badhti
hai, aur program complexity reduce hoti hai.
3. Threading in Java - Java mein multithreading ke liye
java.lang.Thread class aur java.lang.Runnable
interface ka use hota hai.
4. Thread Lifecycle - Ek thread ke lifecycle mein states hote
hain: New, Runnable, Running, Blocked, aur Terminated.
5. Thread Methods - Java mein kuch common thread methods
hain: start(), run(), sleep(), join(), aur
interrupt().
The Main Thread
1. Definition - Main thread wo primary thread hai jo JVM dwara
har Java application ko execute karne ke liye automatically
create hota hai.
2. Main Method - public static void main(String[]
args) method ko main thread execute karta hai.
3. Importance - Main thread ke bina koi bhi standalone Java
application start nahi ho sakta.
4. Control - Main thread doosre threads ko create aur control
kar sakta hai.
5. Termination - Jab main method return hoti hai, toh main
thread terminate ho jata hai, unless doosre non-daemon
threads run kar rahe ho.
Java Thread Model
1. Preemptive Multitasking - Java thread model preemptive
multitasking use karta hai, jisme thread scheduler decide
karta hai ki kaun sa thread kab run hoga.
2. Thread Priority - Har thread ki ek priority hoti hai jo scheduler
ko batati hai kis thread ko pehle run karna hai.
3. Synchronization - Java mein synchronization ek mechanism
hai jo threads ko safe access allow karta hai shared resources
ka.
4. Thread Safety - Proper synchronization se thread safety
ensure hoti hai, data inconsistency aur race conditions avoid
hote hain.
5. Context Switching - Java mein context switching ek process
hai jisme CPU ek thread se dusre thread par switch karta hai.
Thread Priorities
1. Priority Range - Java mein thread priorities 1
(MIN_PRIORITY) se 10 (MAX_PRIORITY) tak hoti hain, default
priority 5 (NORM_PRIORITY) hoti hai.
2. Setting Priority - Thread ki priority setPriority(int
priority) method se set ki ja sakti hai.
3. Impact of Priority - Higher priority threads ko scheduler
pehle run karne ki koshish karta hai, lekin priority sirf ek
suggestion hai.
4. Priority Inheritance - Lower priority threads higher priority
threads ke resources lock karke indirectly unki priority inherit
kar sakte hain.
5. Priority Pitfalls - Incorrect priority management se starvation
aur poor performance issues ho sakte hain.
Synchronization in Java
1. Why Synchronization? - Synchronization is required to
prevent thread interference aur memory consistency errors
jab multiple threads shared resources access karte hain.
2. Synchronized Methods - synchronized keyword se
methods ko synchronize kiya jata hai taaki ek time par sirf ek
thread us method ko access kar sake.
3. Synchronized Blocks - Specific blocks of code ko synchronize
karne ke liye synchronized blocks ka use hota hai.
4. Lock Concept - Synchronization ka base concept lock hai, jo
ek resource ko ek time par sirf ek thread ko access karne deta
hai.
5. Deadlock - Synchronization ka improper use deadlock
situations create kar sakta hai jisme do ya zyada threads
indefinitely block ho jate hain.
Interthread Communication
1. Purpose - Interthread communication threads ko interact aur
data share karne ka mechanism provide karta hai.
2. Methods Used - wait(), notify(), aur notifyAll()
methods interthread communication ke liye use hote hain.
3. Monitor Concept - Interthread communication ek monitor
concept par based hoti hai jo synchronization provide karta
hai.
4. Wait and Notify - wait() method thread ko wait state mein
dalta hai aur notify() thread ko notify karta hai taaki wo
resume kar sake.
5. Usage Scenarios - Common usage scenarios include
producer-consumer problems jahan threads coordination ki
zarurat hoti hai.
I/O Basics
1. Definition - Input/Output (I/O) operations data ko read aur
write karte hain, typically between a program and an external
source like files or networks.
2. I/O Streams - Java I/O streams data flow ko abstract karte
hain aur unhe read/write operations ke through handle karte
hain.
3. Types of Streams - Byte streams aur character streams do
primary types hain, jinka use data ko read aur write karne ke
liye kiya jata hai.
4. Classes and Interfaces - Java mein multiple classes aur
interfaces hain jo I/O operations perform karne mein madad
karte hain, jaise InputStream, OutputStream, Reader, aur
Writer.
5. Exception Handling - I/O operations mein exceptions handle
karna zaroori hota hai, kyunki hardware ya file system issues
occur kar sakte hain.
Streams and Stream Classes
1. Definition - Streams sequential data ka flow handle karte
hain aur I/O operations ko simplify karte hain.
2. Byte Streams - Byte streams 8-bit bytes data ko handle karte
hain aur InputStream aur OutputStream classes ko
extend karte hain.
3. Character Streams - Character streams 16-bit Unicode
characters data ko handle karte hain aur Reader aur Writer
classes ko extend karte hain.
4. Abstract Classes - InputStream aur OutputStream
abstract classes hain jo byte stream operations ke liye base
classes provide karte hain.
5. Filter Streams - Filter streams additional functionalities
provide karte hain jaise buffering aur data filtering.
Byte Stream Classes
1. Definition - Byte stream classes data ko 8-bit bytes ke form
mein read aur write karti hain.
2. InputStream - InputStream class data ko source se
byte-by-byte read karne ke liye use hoti hai.
3. OutputStream - OutputStream class data ko destination
par byte-by-byte write karne ke liye use hoti hai.
4. FileInputStream - FileInputStream file se byte data ko
read karne ke liye use hoti hai.
5. FileOutputStream - FileOutputStream file mein byte data
ko write karne ke liye use hoti hai.
Character Stream Classes
1. Definition - Character stream classes data ko 16-bit Unicode
characters ke form mein read aur write karti hain.
2. Reader - Reader class data ko source se
character-by-character read karne ke liye use hoti hai.
3. Writer - Writer class data ko destination par
character-by-character write karne ke liye use hoti hai.
4. FileReader - FileReader file se character data ko read
karne ke liye use hoti hai.
5. FileWriter - FileWriter file mein character data ko write
karne ke liye use hoti hai.
The Predefined Streams
1. System.in - System.in pre-defined input stream hai jo
typically keyboard se input data read karta hai.
2. System.out - System.out pre-defined output stream hai jo
typically console par data display karta hai.
3. System.err - System.err pre-defined error stream hai jo
typically console par error messages display karta hai.
4. Usage - System.out.println() aur
System.err.println() commonly used methods hain jo
console par data aur errors display karte hain.
5. Redirection - Predefined streams ko files ya other devices par
redirect kiya ja sakta hai for advanced I/O operations.
Reading from, and Writing to, Console
1. Console Input - Console se input read karne ke liye
System.in ka use hota hai, typically Scanner class ke
through.
2. Scanner Class - Scanner class convenient methods provide
karti hai console se data read karne ke liye.
3. Console Output - Console par output display karne ke liye
System.out ka use hota hai.
4. PrintStream - PrintStream class output display karne ke
liye methods provide karti hai jaise print() aur println().
5. Formatted Output - Console par formatted output display
karne ke liye System.out.printf() method ka use hota
hai.
Reading and Writing Files
1. FileReader and FileWriter - FileReader aur FileWriter
classes files se characters read aur write karne ke liye use hoti
hain.
2. BufferedReader and BufferedWriter - Buffered I/O ke liye
BufferedReader aur BufferedWriter use hote hain jo
performance improve karte hain.
3. FileInputStream and FileOutputStream - Byte data ke liye
FileInputStream aur FileOutputStream use hote hain.
4. File Class - File class file aur directory ke properties aur
attributes handle karne ke liye use hoti hai.
5. Exception Handling - File operations ke during
IOException handle karna zaroori hota hai.
The Transient and Volatile Modifiers
1. Transient Modifier - transient keyword variables ko mark
karta hai jo serialization process ke during skip kiye jate hain.
2. Usage - Transient variables typically sensitive data ko mark
karne ke liye use hote hain jo persistent nahi hona chahiye.
3. Volatile Modifier - volatile keyword variables ko mark
karta hai jo multi-threaded programming mein thread-safe
read/write ensure karta hai.
4. Memory Visibility - Volatile variables directly main memory
se read aur write hote hain, ensuring visibility across threads.
5. Performance - Volatile modifier performance ko impact kar
sakta hai due to frequent memory access, lekin
synchronization ke comparison mein lightweight hai.
Using Instance of Native Methods
1. Native Methods - Native methods wo methods hain jo Java
ke alawa kisi aur language (like C/C++) mein likhe hote hain
aur JNI (Java Native Interface) ke through call kiye jate hain.
2. Purpose - Native methods ko high-performance operations ya
existing non-Java libraries ko integrate karne ke liye use kiya
jata hai.
3. Declaration - Native methods native keyword se declare
kiye jate hain.
4. Implementation - Native methods ka implementation
typically shared libraries (DLLs in Windows, SO files in Unix)
mein hota hai.
5. Security - Native methods use karte waqt security
considerations important hote hain kyunki ye JVM ke memory
space aur resources ko directly access kar sakte hain.
Java I/O Classes and Interfaces
1. Definition - Java I/O classes aur interfaces data read/write
operations ko handle karne ke liye use hote hain.
2. Core Interfaces - Closeable aur Flushable interfaces core
I/O functionalities define karte hain.
3. I/O Streams - Input aur output streams sequential data
read/write operations perform karte hain.
4. Readers and Writers - Readers aur writers character data ko
handle karte hain, byte data ko nahi.
5. Decorators - I/O decorators jaise BufferedReader,
BufferedWriter, DataInputStream, aur
DataOutputStream additional functionality provide karte
hain.
I/O Stream Classes
1. InputStream and OutputStream - Ye abstract classes byte
data streams ko handle karne ke liye base classes provide
karte hain.
2. File Streams - FileInputStream aur FileOutputStream
classes file se byte data read/write karne ke liye use hoti hain.
3. Buffered Streams - Buffered streams (e.g.,
BufferedInputStream, BufferedOutputStream) data ko
buffer mein store karte hain aur performance improve karte
hain.
4. Data Streams - Data streams (e.g., DataInputStream,
DataOutputStream) primitive data types ko read/write
karne ke liye use hoti hain.
5. Filter Streams - Filter streams base streams ko wrap karke
additional functionalities provide karte hain, jaise data
filtering aur transformation.
Input Stream and Output Stream Hierarchy
1. Base Classes - InputStream aur OutputStream byte
streams ke base classes hain.
2. Subclasses - FileInputStream,
ByteArrayInputStream, BufferedInputStream etc.
InputStream ke subclasses hain, aur FileOutputStream,
ByteArrayOutputStream, BufferedOutputStream etc.
OutputStream ke subclasses hain.
3. Decorators - FilterInputStream aur
FilterOutputStream classes decorators hain jo base
streams ko wrap karke additional functionalities provide karte
hain.
4. Data Streams - DataInputStream aur
DataOutputStream primitive data types ko handle karne ke
liye base classes ko extend karte hain.
5. Piped Streams - PipedInputStream aur
PipedOutputStream interconnected streams hain jo
inter-thread communication ko support karte hain.
Text Streams
1. Character Data - Text streams character data ko read aur
write karte hain, unlike byte streams jo raw byte data handle
karte hain.
2. Reader and Writer Classes - Reader aur Writer base
classes hain text streams ke liye.
3. BufferedReader and BufferedWriter - Ye classes text data ko
buffer karte hain aur performance improve karte hain.
4. Input from File - FileReader class file se text data read
karne ke liye use hoti hai.
5. Output to File - FileWriter class file mein text data write
karne ke liye use hoti hai.
Stream Tokenizer
1. Definition - Stream tokenizer input stream ko tokens
(smallest units of meaning) mein break karta hai.
2. Class - StreamTokenizer class tokenization functionality
provide karti hai.
3. Token Types - Common token types hain numbers, words, aur
quoted strings.
4. Usage - StreamTokenizer ko parsers aur lexical analyzers
mein use kiya jata hai.
5. Configuration - StreamTokenizer ko customize kiya ja
sakta hai kis type ke tokens recognize karne hain aur kaise
handle karne hain.
Serialization
1. Definition - Serialization process hai jisme object state ko
byte stream mein convert kiya jata hai taaki usse file ya
network par transmit kiya ja sake.
2. Serializable Interface - Object ko serializable banane ke liye
Serializable interface implement karna padta hai.
3. transient Keyword - transient keyword use hota hai un
fields ko mark karne ke liye jo serialization ke during exclude
ki jati hain.
4. Deserialization - Deserialization process hai jisme byte
stream ko wapas original object state mein convert kiya jata
hai.
5. Security - Serialization ke during object data encryption aur
secure handling ensure karna important hai.
Buffered Stream
1. Definition - Buffered streams data ko buffer mein store karte
hain aur read/write operations ko efficient banate hain.
2. BufferedInputStream - BufferedInputStream class input
stream se data ko buffer karke read karti hai.
3. BufferedOutputStream - BufferedOutputStream class
output stream mein data ko buffer karke write karti hai.
4. Performance - Buffered streams performance improve karte
hain kyunki multiple small read/write operations ek large
read/write operation mein combine ho jate hain.
5. Usage - Buffered streams ko frequently access hone wale
data aur large file operations mein use kiya jata hai.
Print Stream
1. Definition - PrintStream class output stream ko text aur
other data print karne ki functionality provide karti hai.
2. Methods - print() aur println() methods data ko
console ya file par print karne ke liye use hote hain.
3. Automatic Flushing - PrintStream automatic flushing
support karta hai jab new line character encounter hota hai.
4. Formatted Output - printf() method formatted output
provide karta hai jaise C language ke printf function jaisa.
5. Error Handling - PrintStream methods errors ko throw
nahi karte, instead error state ko set kar dete hain jo
checkError() method se check kiya ja sakta hai.
Random Access File
1. Definition - RandomAccessFile class file ko read aur write
karne ki capability provide karti hai kisi bhi position se.
2. File Pointer - RandomAccessFile ka ek file pointer hota hai
jo file ke kisi specific position ko indicate karta hai.
3. Read/Write Operations - RandomAccessFile methods
read(), write(), seek() use karke data ko read aur write
kar sakti hai specific positions se.
4. Mode - RandomAccessFile ko read (r) ya read-write (rw)
mode mein open kiya ja sakta hai.
5. Usage - RandomAccessFile typically large files aur
applications jahan random access zaroori hai (jaise databases)
mein use hota hai.
Package
1. Definition - Package ek namespace provide karta hai jisme
related classes aur interfaces ko group kiya jata hai.
2. Benefits - Packages class name conflicts ko avoid karte hain
aur code organization aur maintainability improve karte hain.
3. Package Declaration - Package ko declare karne ke liye
package keyword ka use hota hai source file ke top par.
4. Naming Conventions - Package names typically lowercase
letters use karte hain aur reverse domain name conventions
follow karte hain.
5. Access Control - Packages access control mechanisms
provide karte hain jaise package-private access jisse classes
aur members within the same package access kiye ja sakte
hain.
CLASSPATH
1. Definition - CLASSPATH environment variable hai jo JVM ko
batata hai ki Java classes ko kaha search karna hai.
2. Setting CLASSPATH - CLASSPATH ko environment variable
ke through ya command-line option (-cp ya -classpath) ke
through set kiya jata sakta hai.
3. Multiple Paths - CLASSPATH multiple directories aur JAR
files ko colon (:) ya semicolon (;) se separate karke specify
kar sakta hai.
4. Default CLASSPATH - Agar CLASSPATH set nahi hai to JVM
current directory ko default CLASSPATH maanti hai.
5. Importance - Correct CLASSPATH settings ensure karte hain
ki application runtime par required classes aur libraries mil
jayein.
Package Naming
1. Conventions - Package names typically lowercase letters aur
dots (.) use karke hierarchical structure mein likhe jate hain.
2. Reverse Domain - Common practice hai reverse domain name
conventions use karna (e.g., com.example.project) to
ensure uniqueness.
3. Sub-packages - Dots (.) use karke sub-packages create kiye
jate hain jo specific functionalities ko encapsulate karte hain.
4. Consistency - Package naming mein consistency maintain
karna zaroori hai for better code readability aur maintenance.
5. Avoid Conflicts - Proper naming conventions classes aur
packages ke name conflicts ko avoid karte hain, especially in
large projects.
Accessibility of Packages
1. Public Classes - Public classes aur interfaces packages ke
outside accessible hote hain.
2. Package-Private - Default (no modifier) classes aur members
sirf within the same package accessible hote hain.
3. Protected Members - Protected members subclasses aur
same package ke classes ke through accessible hote hain.
4. Private Members - Private members sirf within the same
class accessible hote hain aur packages ko directly affect nahi
karte.
5. Access Control - Proper access control mechanisms sensitive
data aur implementation details ko encapsulate aur protect
karte hain.
Using Package Members
1. Import Statement - Package members ko access karne ke liye
import statement ka use hota hai.
2. Single Type Import - Specific class ya interface ko import
karne ke liye import package.ClassName; use hota hai.
3. On-Demand Import - Package ke sabhi public classes aur
interfaces ko import karne ke liye import package.*; use
hota hai.
4. Fully Qualified Name - Directly package members ko access
karne ke liye fully qualified name (e.g.,
package.ClassName) use kiya ja sakta hai.
5. Static Import - Static members ko directly access karne ke
liye import static package.ClassName.memberName;
use hota hai.
Interfaces
1. Definition - Interface ek reference type hai jo abstract
methods ka collection hoti hai jinko implementing class define
karti hai.
2. Declaration - Interfaces interface keyword use karke
declare ki jati hain.
3. Implementation - Classes interfaces ko implements
keyword use karke implement karti hain aur sabhi abstract
methods ko define karti hain.
4. Multiple Inheritance - Interfaces multiple inheritance ko
support karte hain, ek class multiple interfaces implement kar
sakti hai.
5. Default Methods - Java 8 se, interfaces default methods
define kar sakti hain jo implementation provide karte hain,
allowing backward compatibility.
Implementing Interfaces
1. Syntax - Interface ko implement karne ke liye class
declaration mein implements keyword use hota hai followed
by interface name.
2. Abstract Methods - Implementing class ko sabhi abstract
methods ko provide karna hota hai jo interface mein declared
hain.
3. Multiple Interfaces - Class multiple interfaces ko implement
kar sakti hai by separating interface names with commas.
4. Polymorphism - Interfaces polymorphism ko enable karte
hain, ek object multiple types ka ho sakta hai (interface types).
5. Code Reusability - Interfaces code reusability aur flexibility
ko increase karte hain by decoupling method definitions from
their implementations.
Interface and Abstract Classes
1. Interfaces vs Abstract Classes - Interfaces fully abstract
hain, sirf method declarations contain karti hain; abstract
classes methods aur fields ko include kar sakti hain.
2. Multiple Inheritance - Interfaces multiple inheritance support
karti hain, lekin abstract classes single inheritance allow karti
hain.
3. Default Methods - Interfaces default methods provide kar
sakti hain, lekin abstract classes concrete methods provide kar
sakti hain.
4. Fields - Interfaces sirf static final fields contain kar sakti hain,
jabki abstract classes instance fields contain kar sakti hain.
5. Use Cases - Interfaces ko use kiya jata hai jab multiple
implementations expected ho; abstract classes ko use kiya
jata hai jab base class functionality share karni ho.
Extends and Implements Together
1. Syntax - Ek class simultaneously ek class ko extends aur ek
ya zyada interfaces ko implements kar sakti hai.
2. Example - class MyClass extends ParentClass
implements Interface1, Interface2 { ... }
3. Hierarchy - Class hierarchy mein ek class sirf ek parent class
ko extend kar sakti hai, lekin multiple interfaces ko implement
kar sakti hai.
4. Flexibility - Extends aur implements ka combination
flexibility aur functionality extend karta hai, complex
behaviors ko encapsulate karta hai.
5. Design Patterns - Ye combination commonly used hai various
design patterns mein jaise Adapter, Proxy, aur Decorator
patterns.
The Applet Class
1. Definition - Applet class ek Java class hai jo web browser
mein run hone ke liye design ki gayi hoti hai.
2. Inheritance - Applets java.applet.Applet class ko
extend karti hain ya javax.swing.JApplet for
Swing-based applets.
3. Life Cycle Methods - Applets ke life cycle methods hain:
init(), start(), stop(), aur destroy().
4. Security Restrictions - Applets browser ke sandbox
environment mein run hoti hain, jaha unke actions restricted
hote hain for security reasons.
5. HTML Integration - Applets ko HTML pages mein <applet>
tag ya <object> tag use karke embed kiya jata hai.
Applet Architecture
1. Life Cycle - Applet life cycle methods init(), start(),
stop(), aur destroy() define karte hain ki applet kaise
load, start, pause, aur terminate hota hai.
2. Initialization - init() method applet ke initial setup ke liye
call hota hai jab applet first load hoti hai.
3. Starting - start() method applet ke start ya resume hone
par call hota hai, usually jab user page par navigate karta hai.
4. Stopping - stop() method applet ke pause hone par call
hota hai, usually jab user page se navigate karta hai.
5. Destruction - destroy() method applet ke resources free
karne aur cleanup ke liye call hota hai jab applet permanently
unload hoti hai.
An Applet Skeleton: Initialization and Termination
1. Initialization - Applet ke init() method mein initial setup
aur resources allocate kiye jate hain.
2. Starting - start() method mein applet ke interactive aur
dynamic behavior initialize kiya jata hai.
3. Stopping - stop() method mein applet ko temporarily halt
kiya jata hai aur running processes ko pause kiya jata hai.
4. Termination - destroy() method mein applet ke resources
release kiye jate hain aur final cleanup operations perform
kiye jate hain.
5. Template - Har applet ke liye ek basic template follow kiya
jata hai jisme ye lifecycle methods include hote hain for
proper initialization aur termination.
Handling Events
1. Event Handling - Event handling mechanism applets ko user
actions (mouse clicks, key presses, etc.) respond karne ki
capability deta hai.
2. Listeners - Event listeners interfaces ko implement karte hain
aur applet ke event handling code ko define karte hain.
3. Event Sources - Components jaise buttons, text fields, etc.,
event sources hain jo user interactions ko trigger karte hain.
4. Delegation Model - Java event delegation model mein event
sources event objects ko generate karte hain aur listeners ko
delegate karte hain.
5. Example - ActionListener interface button clicks ko
handle karta hai aur MouseListener interface mouse events
ko handle karta hai.
HTML Applet Tag
1. Syntax - HTML <applet> tag applet ko web page mein
embed karne ke liye use hota hai, lekin modern HTML mein
<object> ya <embed> tag preferred hai.
2. Attributes - <applet> tag ke common attributes hain code
(class name), width, height, aur archive (JAR file).
3. Example - <applet code="MyApplet.class"
width="300" height="200"></applet>
4. Compatibility - <applet> tag ko modern browsers mein
support nahi milta, use karna discouraged hai in favor of
newer techniques.
5. Alternatives - <object> aur <embed> tags more flexible aur
compatible hain for embedding applets aur other multimedia
content.
Graphics Contexts and Graphics Objects
1. Graphics Context - Graphics context Graphics object hai jo
drawing operations ko encapsulate karta hai.
2. Obtaining Graphics Object - Graphics object ko
getGraphics() method se obtain kiya jata hai aur custom
painting ke liye use hota hai.
3. Drawing Methods - Graphics object methods jaise
drawLine(), drawRect(), drawOval(), aur
drawString() provide karta hai for drawing shapes aur text.
4. Coordinate System - Graphics context 2D coordinate system
use karta hai jisme origin (0,0) top-left corner hota hai.
5. Advanced Graphics - Advanced graphics operations ke liye
Graphics2D class use hoti hai jo Graphics class ko extend
karti hai.
Color Control
1. Color Class - Color class colors ko represent karti hai aur
pre-defined colors aur custom RGB values provide karti hai.
2. Setting Color - setColor(Color c) method graphics
context ke current drawing color ko set karta hai.
3. Predefined Colors - Color class mein common predefined
colors hain jaise Color.RED, Color.BLUE, Color.GREEN.
4. Custom Colors - Custom colors ko RGB values use karke
create kiya jata hai, e.g., new Color(255, 0, 0) red color
create karta hai.
5. Usage - Colors graphical elements jaise shapes, text, aur
backgrounds ko visually distinguishable banane ke liye use
hote hain.
Fonts
1. Font Class - Font class text ke font style, size, aur typeface
ko define karti hai.
2. Creating Fonts - New font create karne ke liye Font(String
name, int style, int size) constructor use hota hai.
3. Font Styles - Common font styles hain Font.PLAIN,
Font.BOLD, aur Font.ITALIC.
4. Setting Font - setFont(Font f) method graphics context
ka current font set karta hai.
5. Font Metrics - FontMetrics class font ke properties jaise
height, ascent, descent, aur string width ko measure karne ke
liye use hoti hai.
Coordinate System
1. 2D Coordinates - Java graphics context 2D coordinate system
use karta hai jisme origin (0,0) top-left corner hota hai.
2. X and Y Coordinates - Horizontal axis X-coordinate represent
karta hai aur vertical axis Y-coordinate represent karta hai.
3. Positive Directions - X-coordinate positive direction right side
hota hai aur Y-coordinate positive direction downwards hota
hai.
4. Drawing Origin - Graphics context mein sabhi drawing
operations origin point se relative hoti hain.
5. Custom Coordinates - Custom coordinate systems implement
kiye ja sakte hain using translation aur transformation
methods in Graphics2D.
Drawing Lines
1. Method - drawLine(int x1, int y1, int x2, int
y2) method line ko draw karta hai given start aur end
coordinates.
2. Parameters - Method parameters start point (x1, y1) aur
end point (x2, y2) specify karte hain.
3. Usage - Line drawing commonly graphical shapes, charts, aur
diagrams create karne ke liye use hoti hai.
4. Thickness - Default line thickness 1 pixel hota hai, advanced
graphics mein Graphics2D se line thickness customize kiya
ja sakta hai.
5. Color - Line color ko setColor(Color c) method se set
kiya jata hai before drawing.
Drawing Rectangles
1. Method - drawRect(int x, int y, int width, int
height) method rectangle ko draw karta hai given top-left
corner aur dimensions.
2. Filled Rectangle - fillRect(int x, int y, int
width, int height) method filled rectangle draw karta
hai.
3. Parameters - Method parameters top-left corner (x, y) aur
rectangle ke width aur height specify karte hain.
4. Usage - Rectangles commonly UI components, frames, aur
bounding boxes draw karne ke liye use hote hain.
5. Color - Rectangle color ko setColor(Color c) method se
set kiya jata hai before drawing.
Drawing Ovals and Circles
1. Method - drawOval(int x, int y, int width, int
height) method oval ko draw karta hai given bounding
rectangle.
2. Filled Oval - fillOval(int x, int y, int width,
int height) method filled oval draw karta hai.
3. Circle Drawing - Circle draw karne ke liye oval method use
kiya jata hai jaha width aur height equal hote hain.
4. Parameters - Method parameters bounding rectangle ka
top-left corner (x, y) aur width aur height specify karte
hain.
5. Usage - Ovals aur circles commonly graphical elements, UI
components, aur charts create karne ke liye use hote hain.
Drawing Polygons
1. Method - drawPolygon(int[] xPoints, int[]
yPoints, int nPoints) method polygon draw karta hai
given vertices ke arrays.
2. Filled Polygon - fillPolygon(int[] xPoints, int[]
yPoints, int nPoints) method filled polygon draw
karta hai.
3. Parameters - Method parameters arrays of X aur Y
coordinates specify karte hain polygon ke vertices aur number
of points.
4. Custom Shapes - Polygons custom shapes aur complex
graphical elements draw karne ke liye use hote hain.
5. Usage - Polygons commonly maps, charts, aur custom UI
components create karne ke liye use hote hain.
User Interface Components
1. AWT Components - AWT (Abstract Window Toolkit)
components jaise Button, Label, TextField, aur
TextArea provide karta hai.
2. Swing Components - Swing advanced UI components jaise
JButton, JLabel, JTextField, aur JTextArea provide
karta hai.
3. Event Handling - UI components event handling mechanisms
support karte hain for user interactions.
4. Layout Managers - UI components ko arrange karne ke liye
layout managers use hote hain jaise BorderLayout,
FlowLayout, aur GridLayout.
5. Customization - UI components ko customize kiya ja sakta hai
properties jaise size, color, font, aur behavior set karke.
Building User Interface with AWT
1. AWT Basics - AWT (Abstract Window Toolkit) basic UI
components aur containers provide karta hai for building
graphical applications.
2. Components - AWT components include Button, Label,
TextField, TextArea, Checkbox, aur List.
3. Containers - AWT containers jaise Frame, Panel, aur
Applet other components ko hold aur manage karte hain.
4. Event Handling - AWT event handling model listener
interfaces aur event objects use karta hai user interactions ko
handle karne ke liye.
5. Layout Managers - AWT layout managers jaise
FlowLayout, BorderLayout, aur GridLayout components
ko organize karte hain within containers.
Swing-based GUI
1. Swing Framework - Swing AWT ka extension hai jo more
powerful aur flexible UI components provide karta hai.
2. Components - Swing components include JButton, JLabel,
JTextField, JTextArea, JCheckBox, aur JComboBox.
3. Lightweight Components - Swing components lightweight
hote hain aur pure Java mein implemented hote hain, unlike
AWT components jo native peer components use karte hain.
4. Pluggable Look and Feel - Swing pluggable look-and-feel
support karta hai jisme UI ka appearance dynamically change
kiya ja sakta hai.
5. Event Handling - Swing event handling AWT ke similar hota
hai lekin more powerful aur flexible features provide karta hai.
Layouts and Layout Manager
1. Purpose - Layout managers UI components ko container mein
arrange karne ke liye use hote hain based on specific rules aur
algorithms.
2. Common Managers - Common layout managers hain
FlowLayout, BorderLayout, GridLayout, CardLayout,
aur GridBagLayout.
3. FlowLayout - FlowLayout components ko left-to-right aur
top-to-bottom arrange karta hai.
4. BorderLayout - BorderLayout components ko five regions
mein arrange karta hai: North, South, East, West, aur Center.
5. GridLayout - GridLayout components ko equal-sized grid
mein arrange karta hai.
Container
1. Definition - Container ek component hai jo other components
ko hold aur manage karta hai.
2. Types - Common containers hain Frame, Panel, Applet, aur
Dialog.
3. Hierarchy - Containers ek hierarchical structure mein organize
hote hain jisme parent containers child components ko hold
karte hain.
4. Adding Components - Components ko container mein
add(Component comp) method use karke add kiya jata hai.
5. Layout Managers - Containers layout managers use karte
hain components ko arrange karne ke liye within themselves.
Socket Overview
1. Definition - Sockets network communication endpoints hain
jo data exchange karte hain between machines over a
network.
2. Types - Common socket types hain Stream Sockets (TCP)
aur Datagram Sockets (UDP).
3. Java Sockets - Java mein sockets java.net.Socket aur
java.net.ServerSocket classes use karke implement kiye
jate hain.
4. Client-Server Model - Sockets client-server model follow
karte hain jisme client socket server socket se connect hota
hai.
5. Data Transmission - Sockets data transmission ke liye input
aur output streams use karte hain.
Reserved Parts and Proxy Servers
1. Reserved Ports - Reserved ports 0 se 1023 tak hote hain aur
well-known services jaise HTTP (port 80) aur FTP (port 21)
ke liye allocate kiye jate hain.
2. Dynamic Ports - Dynamic ports 1024 se 65535 tak hote hain
aur temporary connections ke liye allocate hote hain.
3. Proxy Servers - Proxy servers clients aur servers ke beech
intermediaries hote hain jo requests ko forward karte hain.
4. Functions - Proxy servers caching, filtering, load balancing,
aur anonymity provide karte hain.
5. Types - Common proxy types hain HTTP Proxy, SOCKS Proxy,
aur Transparent Proxy.
Internet Addressing: Domain Naming Services (DNS)
1. DNS Definition - DNS (Domain Name System) ek hierarchical
naming system hai jo domain names ko IP addresses mein
translate karta hai.
2. DNS Structure - DNS structure mein root, top-level domains
(TLDs), second-level domains, aur subdomains hote hain.
3. DNS Servers - DNS servers domain name queries ko resolve
karte hain by providing corresponding IP addresses.
4. Name Resolution - DNS name resolution process client query
ko DNS server tak forward karta hai jo response mein IP
address return karta hai.
5. Caching - DNS servers aur clients queries ko cache karte hain
taaki future requests fast aur efficient ho sakein.
JAVA and the Net: URL
1. URL Definition - URL (Uniform Resource Locator) ek
reference hai jo web resource ke location aur access method
ko specify karta hai.
2. Components - URL components hain protocol (http, https),
host (www.example.com), port (optional), path
(/path/resource), aur query parameters (?key=value).
3. Java URL Class - Java java.net.URL class URLs ko
represent karti hai aur network resources se interact karne ke
methods provide karti hai.
4. Opening Connections - URL connections ko
openConnection() method se open kiya jata hai jo
URLConnection object return karta hai.
5. Reading Data - URL se data read karne ke liye input stream
ko open kiya jata hai aur data ko stream se read kiya jata hai.
TCP/IP Sockets
1. TCP Definition - TCP (Transmission Control Protocol) reliable,
connection-oriented protocol hai jo data ko ordered aur
error-checked manner mein transmit karta hai.
2. TCP Sockets - Java mein TCP sockets Socket aur
ServerSocket classes use karke implement kiye jate hain.
3. Client-Server Communication - TCP sockets client-server
communication ko enable karte hain jahan client Socket
server ke ServerSocket se connect hota hai.
4. Streams - TCP sockets data transmission ke liye input aur
output streams use karte hain.
5. Reliability - TCP packet loss, duplication, aur errors ko handle
karta hai, ensuring data delivery.
Datagrams
1. UDP Definition - UDP (User Datagram Protocol)
connectionless protocol hai jo data packets ko transmit karta
hai without guarantee of delivery.
2. Datagram Sockets - Java mein datagram sockets
DatagramSocket aur DatagramPacket classes use karke
implement kiye jate hain.
3. Packet Transmission - Datagram sockets packets ko
independent units ke form mein transmit karte hain.
4. Use Cases - UDP real-time applications jaise video streaming
aur online gaming ke liye suitable hai due to low latency.
5. No Reliability - UDP mein packets ka loss, duplication, aur
order mismatch possible hai kyunki ye reliability ensure nahi
karta.
Java Database Connectivity
1. JDBC Definition - JDBC (Java Database Connectivity) API hai
jo Java applications ko relational databases se connect karne
ke liye use hoti hai.
2. Driver - JDBC driver database ke specific protocol ko handle
karta hai aur Java application ko database se interact karne
deta hai.
3. Establishing Connection - Database connection establish
karne ke liye DriverManager.getConnection(url,
user, password) method use hota hai.
4. Executing Queries - SQL queries ko execute karne ke liye
Statement aur PreparedStatement classes use hoti hain.
5. ResultSet - Query results ko ResultSet object mein store
kiya jata hai jo data ko retrieve aur process karne ke methods
provide karta hai.
Establishing A Connection
1. Driver Loading - JDBC driver ko load karne ke liye
Class.forName(driverClassName) method use hota hai.
2. Connection URL - Connection URL database location aur
connection parameters ko specify karta hai, e.g.,
jdbc:mysql://localhost:3306/mydatabase.
3. DriverManager - DriverManager class connection establish
karne ke liye getConnection() method provide karti hai.
4. Authentication - Connection establish karte waqt username
aur password provide kiya jata hai for database
authentication.
5. Connection Object - Successful connection ke baad
Connection object return hota hai jo further database
operations ke liye use hota hai.
Transactions with Database
1. Definition - Transaction ek set of database operations hai jo
atomic, consistent, isolated, aur durable (ACID properties)
hote hain.
2. Auto-commit Mode - By default, JDBC auto-commit mode on
hota hai jisme har individual statement automatically commit
hoti hai.
3. Manual Transactions - Manual transactions ko handle karne
ke liye setAutoCommit(false) method use hota hai aur
commit() aur rollback() methods transaction control
karte hain.
4. Commit - commit() method transaction ko finalize aur save
karta hai database mein.
5. Rollback - rollback() method transaction ko undo karta
hai aur database ko previous consistent state mein restore
karta hai.
An Overview of RMI Applications
1. RMI Definition - RMI (Remote Method Invocation) Java API
hai jo remote objects ke methods ko invoke karne ki capability
deti hai.
2. Architecture - RMI architecture client-server model par based
hai jahan remote objects server par reside karte hain aur client
unhe invoke kar sakta hai.
3. Stubs and Skeletons - RMI stub client-side proxy hai jo
remote object ko represent karta hai, aur skeleton server-side
entity hai jo client requests ko handle karti hai (Java 2
onwards, skeletons are not required).
4. Remote Interface - Remote interface methods ko declare
karta hai jo remote objects implement karte hain.
5. RMI Registry - RMI registry ek naming service hai jo remote
objects ko bind aur lookup karne ke liye use hoti hai.
Remote Classes and Interfaces
1. Remote Interface - Remote interface java.rmi.Remote ko
extend karti hai aur remote methods ko declare karti hai jo
client invoke kar sakta hai.
2. Remote Methods - Remote methods must throw
java.rmi.RemoteException to handle network-related
exceptions.
3. Implementing Class - Remote interface ko implement karne
wali class UnicastRemoteObject ko extend karti hai aur
remote methods ko define karti hai.
4. Binding Objects - Remote objects ko RMI registry mein bind
karne ke liye Naming.rebind(name, object) method use
hota hai.
5. Lookup - Clients remote objects ko RMI registry se lookup
karne ke liye Naming.lookup(name) method use karte hain.
RMI Architecture
1. Client-Side - Client-side mein RMI stub remote object ko
represent karta hai aur remote methods ko invoke karta hai.
2. Server-Side - Server-side mein RMI skeleton (pre-Java 2) aur
remote object server par reside karte hain jo client requests ko
process karte hain.
3. RMI Registry - RMI registry remote objects ko register aur
lookup karne ke liye naming service provide karti hai.
4. Communication - RMI communication TCP/IP protocol use
karke client aur server ke beech data transfer karti hai.
5. Dynamic Class Loading - RMI dynamic class loading support
karti hai jisse client aur server dynamically required classes ko
load kar sakte hain.
RMI Object Hierarchy
1. Remote Interface - Remote interface java.rmi.Remote ko
extend karti hai aur remote methods ko declare karti hai.
2. Remote Class - Remote class remote interface ko implement
karti hai aur remote methods ko define karti hai.
3. UnicastRemoteObject - UnicastRemoteObject remote
object ko unicast (single client connection) remote object
banane ke liye use hota hai.
4. Registry - RMI registry remote objects ko register aur lookup
karne ke liye naming service provide karti hai.
5. Client Stub - Client stub remote object ka proxy hota hai jo
client-side par reside karta hai aur remote method calls ko
server par forward karta hai.
Security
1. RMI Security Manager - RMI applications security manager
use karti hain to enforce security policies aur restrict
unauthorized operations.
2. Permissions - RMI security policies different permissions
define karti hain jaise socket connections aur file access.
3. Policy File - Policy file security policies ko specify karti hai jo
JVM enforce karti hai during runtime.
4. SSL/TLS - RMI secure communication ke liye SSL/TLS
protocols support karti hai.
5. Authentication - RMI authentication mechanisms support
karti hai to verify client aur server identities aur ensure secure
communication.
Java Servlets
1. Servlet Definition - Servlet ek Java class hai jo web requests
ko process karti hai aur dynamic web content generate karti
hai.
2. Servlet API - Servlet API classes aur interfaces provide karti
hai for developing web applications, jaise HttpServlet,
ServletRequest, aur ServletResponse.
3. Lifecycle Methods - Servlet lifecycle methods hain init(),
service(), aur destroy().
4. Deployment - Servlets web servers mein deploy hoti hain aur
web.xml file ya annotations se configured hoti hain.
5. Advantages - Servlets high performance, platform
independence, aur secure web applications development ke
liye suitable hain.
Servlet Life Cycle
1. Initialization - init() method servlet ko initialize karta hai
jab servlet first load hoti hai server par.
2. Request Handling - service() method har incoming
request ko handle karta hai aur appropriate response
generate karta hai.
3. Destruction - destroy() method servlet ko destroy karta
hai jab server shutdown hota hai ya servlet unload hoti hai.
4. Single Instance - Typically, ek servlet ka single instance
create hota hai jo multiple requests ko handle karta hai.
5. Thread Safety - Servlets multithreaded environment mein
run hoti hain, ensuring thread safety is important for shared
resources.
Get and Post Methods
1. GET Method - doGet() method HTTP GET requests ko
handle karta hai jo typically data retrieval ke liye use hote
hain.
2. POST Method - doPost() method HTTP POST requests ko
handle karta hai jo typically data submission ke liye use hote
hain.
3. Request Parameters - GET method parameters URL mein
append hote hain, jabki POST method parameters request
body mein send hote hain.
4. Data Length - GET requests typically limited data length
support karte hain, jabki POST requests large data handle kar
sakte hain.
5. Usage Scenarios - GET method safe aur idempotent
operations ke liye use hota hai, jabki POST method
non-idempotent operations ke liye use hota hai.
Session Handling
1. Session Definition - Session ek user ke multiple requests ko
track aur manage karne ka mechanism hai during a web
session.
2. Session Tracking - Session tracking techniques include
cookies, URL rewriting, aur hidden form fields.
3. HttpSession Interface - HttpSession interface session ko
create, access, aur manage karne ke methods provide karta
hai.
4. Session Attributes - Sessions attributes key-value pairs hote
hain jo session ke state ko store karte hain.
5. Session Timeout - Sessions idle timeout period ke baad
automatically invalidate ho jate hain, default value server
configuration se set hoti hai.
Java Beans
1. JavaBean Definition - JavaBean ek reusable software
component hai jo encapsulated properties, events, aur
methods provide karta hai.
2. Properties - JavaBean properties private fields hoti hain jo
public getter aur setter methods ke through access hoti hain.
3. Events - JavaBeans event model support karte hain jo
components ke interactions ko handle karte hain.
4. Serialization - JavaBeans Serializable interface
implement karte hain taaki unhe byte stream mein convert
karke save aur transmit kiya ja sake.
5. Customization - JavaBeans customization aur configuration
support karte hain via property editors aur customizers in
development tools.