Java Last min
Features:
● Platform Independence - WORA
● OOP
● Simple and familiar - no pointers
● Security - restriction and encryption
● Robustness - error and exception handling
● Multithreading
● High performance - JIT compiler
● Distributed computing - networking capabilities cloud storage and online gaming
● Rich APIs - Comprehensive libraries
● Scalability
● Garbage collection - automatic memory management
● Community support and open source
Flavors:
● Java Standard Edition (SE)
○ General purpose
○ Standalone desktop applications and simple client server applications
○ Core libraries like [Link], [Link], [Link], etc
○ OOP
○ JVM
○ Tools like JDK and JRE
● Java Enterprise Edition (EE) / Jakarta EE
○ Large scale, distributed and secure
○ Builds on SE and adds APIs for web services, distributed computing, large
scale data handling
○ Support Java Server Pages(JSP), Enterprise Java Beans(EJB)
○ Database Connectivity (JDBC, JPA)
○ Supports Multi tier architecture ( presentation, business, data layers)
○ Security and transaction management features
● Java Micro Edition (ME)
○ Lightweight version
○ Designed for mobile devices, embedded systems, IoT
○ Optimized and resource constrained environments
○ Small devices with limited memory and processing power
○ APIs for mobile UI dev, networking and security
○ Supports Connected Limited Device Configuration(CLDC) and Mobile
Information Device Profile(MIDP)
History and Java:
● Dev by James Gosling and his team at Sun Microsystems in 1991
● Project Oak later renamed to java
● Aim - dev a programming lang for smart home appliances like tv and rc
Importance of Java
● Platform independence
● Web dev
● Network Programming
● Security
● Development of Applets
● Mobile application development
● Enterprise application
● Cloud computing
● IoT application
● Key features supporting Internet Development
○ Multithreading
○ Garbage collection
Access modifiers:
● Public
● Private
● Default - same package
● Protected
Types of inheritance
● Single
● Multilevel
● Multiple
● Hierarchical
● Hybrid
Types of packages
● Built in
● User defined
Uses of this keyword
● Current class instance variables
● Current class constructor
● Return current class instance
● Method parameter
● Invoke current class method
● An argument in the constructor call
Types of exceptions:
● User defined
● Built in
○ Checked - compile time
■ ClassNotFoundException
■ InterruptedException
■ IOException
■ InstantiationException
■ SQLException
■ FileNotFoundException
○ Unchecked - runtime
■ ArithmeticException
■ ClassCastException
■ NullPointerException
■ ArrayIndexOutOfBoundsException
■ ArrayStoreException
■ IllegalThreadStateException
Multitasking
● Process Based
○ Different processes run simultaneously ex facebook & music app
● Thread based
○ Same process having threads that run simultaneously ex text editor’s edit and
print
Methods of creating threads:
● Using thread class
● Using runnable interface
Applet:
● Local applet
● Remote applet
Applet life cycle
● Born or initialize state
● Running state
● Idle state
● Dead or destroyed state
Paint() method is used to perform output operation
Steps to create java applet
1. Building an applet code(.java file)
2. Creating an executable applet (.class file)
3. Designing a web page using HTML tags
4. Preparing <APPLET> tag
a. <APPLET code = “[Link]” height = “a”,width = “b”>
5. Incorporating <APPLET> tag into the web page
6. Creating HTML file
7. Testing the applet code
2 ways to run an applet:
● By HTML file
● By appletviewer
2 sets of JAVA APIs for graphics programming
● Abstract Windowing Tool (AWT)
● Swing
Core AWT classes in [Link]
● GUI component class (Button, TextField, Label)
● GUI container class (Frame, Panel, Dialog, ScrollPane)
● Layout managers (FlowLayout, BorderLayout, GridLayout)
● Custom graphic classes (Graphics, Color, Font)
Concepts of event handling
● Event source
● Event listeners
● Event objects
● Adapter classes
Common Event Listener Interfaces
1. ActionListener: Handles action events (like button clicks).
2. ItemListener: Handles item selection events (checkbox, choice, etc.).
3. AdjustmentListener: Handles scrollbar adjustment events.
4. MouseListener: Handles mouse click, press, release, enter, exit.
5. MouseMotionListener: Handles mouse move and drag.
6. KeyListener: Handles key press, release, and typing.
7. WindowListener: Handles window open, close, minimize, etc.
8. FocusListener: Handles focus gained and lost events.
9. TextListener: Handles changes in text fields or areas.
Commonly Used Event Classes
1. ActionEvent: Generated when a button is clicked.
2. ItemEvent: Generated when an item is selected or deselected.
3. AdjustmentEvent: Occurs on scrollbars when the value is changed.
4. MouseEvent: Occurs on mouse actions (click, press, release, move, drag).
5. KeyEvent: Generated when a key is pressed, released, or typed.
6. WindowEvent: Occurs when a window is opened, closed, activated, etc.
7. FocusEvent: Occurs when a component gains or loses keyboard focus.
8. TextEvent: Occurs when the value of a text component changes.
· JDBC Architecture:
· 1. Application Layer – Your Java program.
· 2. JDBC API – Interfaces and classes such as Connection, Statement, ResultSet.
· 3. JDBC Driver – Translates JDBC API calls into database-specific calls.
· 4. Database – Stores the actual data.
Connecting to the Database
Steps to connect Java with a database using JDBC:
1. Load the JDBC Driver - [Link](“[Link]”)
2. Establish a Connection using DriverManager -
a. Connection con = null;
b. con =
[Link](“jdbc:mysql://localhost:3306/database”,”userna
me”, “password”);
3. Create a Statement or PreparedStatement object - Statement stmt =
[Link]();
4. Execute SQL query - Result rs = [Link](“”);
5. Process the result (if any) -
a. while([Link]()){
i. [Link]([Link](1));
b. }
6. Close the Connection - [Link]();
Types of drivers in jdbc:
● JDBC - ODBC:
○ Universal
○ Written in c
○ Not portable
○ Less security
○ Built in
○ Database independent
● Native-API driver
● Network Protocol driver
● Thin Driver - best
Type Name Speed Platform Extra Common
Independent Software? Today?
1 JDBC-ODBC ❌ Slow ❌ No ✅ Yes ❌ No
Bridge (Removed)
2 Native API ✅ Fast ❌ No ✅ Yes ❌ Rare
3 Network ✅ Good ✅ Yes ✅ Yes ❌ Rare
Protocol (Middleware)
4 Thin Driver ✅✅ ✅ Yes ❌ No ✅✅ Yes
(Pure Java) Fastest