0% found this document useful (0 votes)
9 views11 pages

U1 - Advance Java

The document outlines the curriculum for Advanced Java in BCA Semester V at CPJ Institute of Management & Technology, covering key topics such as web development, networking, and database interaction. It includes details on application types, the importance of Core Java, common Java programs, popular projects, and installation of Java IDEs. Additionally, it discusses Java GUI programming, servlet lifecycle, JDBC, JSP, session management, and introduces the Spring framework.
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)
9 views11 pages

U1 - Advance Java

The document outlines the curriculum for Advanced Java in BCA Semester V at CPJ Institute of Management & Technology, covering key topics such as web development, networking, and database interaction. It includes details on application types, the importance of Core Java, common Java programs, popular projects, and installation of Java IDEs. Additionally, it discusses Java GUI programming, servlet lifecycle, JDBC, JSP, session management, and introduces the Spring framework.
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

CPJ Institute of Management & Technology

(A PART OF CPJ GROUP OF INSTITUTIONS)


E-NOTES

Class & Semester : BCA Semester


Semester-V

Subject Name : Advance Java

Subject Code : BCA301C

Faculty Name : Ms
Ms. Divya C.M

UNIT-I

1. Understanding Advanced Java

Advanced Java extends Core Java and focuses on:

 Web development
 Networking
 Database interaction
 Enterprise applications

It is not a separate language but an advanced skill set built on Core Java.

Core Components:

 JDBC – Database Connectivity


 Servlets – Request handling on the server
 JSP – Java-based
based dynamic web content
 Networking – Socket programming, RMI
 Multithreading & Concurrency
 JavaBeans, EJB – Enterprise-level
level architecture

2. Application Types: Console vs GUI vvs Web

GUI Application Web Application


Feature Console Application
(Swing/AWT) (Servlets/JSP)
Interface Text-based
based (Terminal) Graphical (Buttons, Windows) Browser-based
Browser (Forms, Pages)
JSP, Servlets, JDBC,
Technologies Core Java AWT, Swing
Frameworks
Execution
Local machine Local/Desktop Server-hosted
hosted
Environment
Calculator, File
Example Notepad clone, Inventory tool E-commerce,
commerce, Online Banking
Readers

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)

3. Why Core Java is Essential for Advanced Java

Object-Oriented
Oriented Programming (OOP)

 Inheritance, Polymorphism, Encapsulation, Abstraction


 Required for building reusable, modular applications.

Exception Handling

 try-catch-finally, throw, throws


 Mandatory for error management in JDBC, Servlets, Threads, etc.
 Collections Framework

 List, Set, Map, Queue interfaces


 Backbone of data manipulation in enterprise applications.

File I/O and Streams

 Used in data logging, configuration reading, file storage.

Multithreading

 Used in parallel processing, GUI responsiveness, server request handling.

JDBC

 Understanding interfaces, classes, and exceptions is crucial for database programming.

Foundation for Frameworks

 Frameworks like Spring, Hibernate are built on Core Java concepts.

4. Common Java Programs (Basics)

Hello World
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello,
"Hello, World!"
World!");
}
}
Sum of Two Numbers
import [Link];

public class Sum {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
([Link]);
int a = [Link]();

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)
int b = [Link]();
[Link]("Sum = " + (a + b));
[Link]();
}
}
Even or Odd
public class EvenOdd {
public static void main(String[] args) {
int num = new Scanner([Link]).nextInt();
([Link]).nextInt();
[Link](num % 2 == 0 ? "Even" : "Odd");
}
}
Factorial
public class Factorial {
public static void main(String[] args) {
int n = new Scanner([Link]).nextInt();
([Link]).nextInt();
int fact = 1;
for (int i = 1; i <= n; i++) fact *= i;
[Link]("Factorial: " + fact);
}
}

Fibonacci Series
public class Fibonacci {
public static void main(String[] args) {
int n = new Scanner([Link]).nextInt();
([Link]).nextInt();
int a = 0, b = 1;
for (int i = 1; i <= n; i++) {
[Link](a + " ");
int next = a + b;
a = b; b = next;
}
}
}

Prime Check
public class PrimeCheck {
public static void main(String[] args) {
int num = new Scanner([Link]).nextInt();
([Link]).nextInt();
boolean isPrime = num > 1;
for (int i = 2;; i <= [Link](num); i++) {
if (num % i == 0) {
isPrime = false; break;
}
}
[Link](isPrime ? "Prime" : "Not Prime");

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)
}
}

5. Popular Advanced Java Projects

 Online Ticket Booking System


 E-commerce Website
 Student or Library Management System
 Online Banking System
 Chat/Messaging Application
 Hospital/Clinic Management
 Online Quiz or Exam Portal

6. Installing Java, NetBeans, Eclipse

Java JDK:

 Download from Oracle


 Set JAVA_HOME and update PATH
 IDEs:

IDE Features
NetBeans Built-in GUI designer (Swing/AWT)
Eclipse Lightweight and extensible
IntelliJ Professional, productivity features (optional)

7. JAR Files in Java

A JAR (Java Archive) file is a compressed collection of .class, .properties,, and resource files.

Key Benefits:

 ✔ Easy application packaging (java


java -jar [Link])
 ✔ Dependency management (mysql [Link])
 ✔ Easier distribution of libraries and tools
 ✔ Supports digital signing for integrity and trust
 ✔ Reduces file size and clutter Commands:

javac [Link]
jar cf [Link] [Link]
java -jar [Link]

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)
8. Java GUI Programming with Swing

AWT vs Swing

Feature AWT (Abstract Window Toolkit) Swing


Platform Native OS-based Pure Java (Platform-independent)
Type Heavyweight Lightweight
UI Richness Limited Rich components
Common Swing Components
Component Description
JButton Clickable button
JLabel Display label text
JTextField Single-line input
JTextArea Multi-line input
JCheckBox Select multiple options
JRadioButton Select one from multiple options
JComboBox Dropdown menu
JList List with selection
JTable Table for structured data

Container Classes
Container Use
JFrame Main window
JPanel Sub-container
container (nested components)
JDialog Popup dialog
JScrollPane Scrollable view
JApplet Browser-embedded
embedded Java program

Example: Simple Swing App


import [Link].*;

public class MyGUI {


public static void main(String[] args) {
JFrame frame = new JFrame("Demo"
"Demo");
JButton button = new JButton("Click
"Click Me"
Me");

[Link](e ->
> [Link](
[Link](null, "Button Clicked!"));
Clicked!"

[Link](button);
[Link](300, 200);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](true);
}

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)
}

Event Handling in Swing

 Uses Event Listeners like ActionListener


ActionListener, MouseListener, KeyListener.
 Lambda expressions simplify listener implementation.

[Link](e ->
> [Link](
[Link]("Clicked!"));

Creating GUI in NetBeans or Eclipse

 In NetBeans:
o Create a Java Desktop project
o Use "JFrame Form" to drag and drop components
o Double-click
click to add event handlers
 In Eclipse:
o Write GUI code manually
o Optionally use plugins (e.g., WindowBuilder)

Conclusion

Advanced Java equips you to build powerful,


werful, scalable, and real
real-world
world applications such as:

 Web portals
 Desktop GUI apps
 Server-side components
 Enterprise systems

Master Core Java first to fully understand and apply Advanced Java technologies like Servlets, JSP, JDBC,
and frameworks (Spring, Hibernate, etc.).

Servlet Lifecycle and Architecture

Servlets are server-side


side Java programs that handle requests and responses in web applications.

Servlet Lifecycle Phases:


1. Loading & Instantiation
o Handled by the servlet container (e.g., Tomcat).

2. Initialization (init() method)


o Called once when the servlet is first loaded.

3. Request Handling (service() method)


o Called for every HTTP request.
o Delegates to doGet(), doPost() etc.

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)
4. Destruction (destroy() method)
o Called once when the servlet is unloaded.

Servlet API Classes:

 HttpServlet
 HttpServletRequest
 HttpServletResponse
 ServletContext, ServletConfig

Example:
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest
(HttpServletRequest req, HttpServletResponse res) throws IOException {
[Link]().println("Hello
"Hello from Servlet!"
Servlet!");
}
}

2. Introduction to JavaBeans

JavaBeans are reusable software components for Java that follow a specific design pattern.

Features:

 Serializable (can be saved/loaded)


 Have no-arg constructor
 Use getter/setter methods for property access

Syntax Example:
public class StudentBean implements Serializable {
private String name;
public StudentBean() {}
public String getName() { return name; }
public void setName(String name) { this
[Link] = name; }
}
Use in JSP:
<jsp:useBean id="stu" class="StudentBean"
"StudentBean" />
<jsp:setProperty name="stu" property="name"
"name" value="John" />
<jsp:getProperty name="stu" property="name"
"name" />

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)
3. MVC Architecture in Java Web Applications

MVC (Model-View-Controller) is a design pattern used to separate business logic, user interface, and control
flow.

Component Responsibility Technology Used


Model Business logic, data handling Java classes, JDBC
View Presentation (UI) JSP, HTML, CSS
Controller Handles user requests, updates model/view Servlet

Benefits:

 Cleaner, maintainable code


 Loose coupling
 Easier testing and debugging

Example Flow:

1. User submits form (View)


2. Servlet handles request (Controller)
3. Servlet updates/queries data (Model)
4. Result is displayed using JSP (View)

4. Introduction to JDBC (Java Database Connectivity)

JDBC allows Java applications to interact with relational databases like MySQL, Oracle, etc.

Steps in JDBC:

1. Load Driver:
[Link]("[Link]");
2. Establish Connection:
Connection con = [Link](url, user, pass);
3. Create Statement:
Statement stmt = [Link]();
4. Execute Query:
ResultSet rs = [Link]("SELECT * FROM students");
5. Process Result:
while([Link]()) { [Link]([Link]("name")); }
6. Close Resources

Types of Statements:

 Statement
 PreparedStatement (for dynamic queries)
 CallableStatement (for stored procedures)

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)

5. JavaServer Pages (JSP)


JSP is a technology used to create dynamic web content using HTML and embedded Java code.

Features:

 Extension of Servlet technology


 Easier to write HTML + Java
 Supports tag libraries (JSTL)

Lifecycle:

1. Translation – JSP P is converted to Servlet.


2. Compilation – Servlet is compiled.
3. Initialization (jspInit)
4. Execution (_jspService)
5. Destruction (jspDestroy)

JSP Tags:
Tag Type Example
Scriptlet <% int a = 10; %>
Expression <%= a %>
Declaration <%! int x; %>
Directive <%@ page import="[Link].*" %>
Action Tag <jsp:include>, <jsp:useBean>

6. Session Management in Java Web Applications

Maintaining user state across multiple requests is critical in web development.

Techniques:
1. Cookies
o Small text files stored in browser
o [Link]()

2. URL Rewriting
o Appends data to URL
o [Link]?user=John

3. Hidden Form Fields


o <input type="hidden" name="user" value="John">

4. HttpSession (Most used)

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)
HttpSession session = [Link]();
[Link]("user", "John");
String name = (String) [Link](
[Link]("user");
Session Invalidation:
[Link](); // logs out user

7. Servlet Filters and Listeners


Filters

 Intercepts requests/responses before reaching servlet/JSP.


 Used for logging, authentication, compression.

Example:
WebFilter("/secure/*")
public class AuthFilter implements Filter {
public void doFilter(...) {
// check if user is logged in
}
}
Listeners

 Detect lifecycle events (application start, session create, etc.)

Example:
WebListener
public class MyAppListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent
(ServletContextEvent e) {
[Link]("App started");
}
}

8. Introduction to Spring Framework (Optional but Important)

Spring is a powerful enterprise-level


level framework built on Java.

Core Concepts:

 IoC (Inversion of Control) using Dependency Injection


 AOP (Aspect-Oriented
Oriented Programming)
 Spring MVC for web apps
 Spring Boot for rapid development
 Spring Data JPA for database interact
interaction

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]
CPJ Institute of Management & Technology
(A PART OF CPJ GROUP OF INSTITUTIONS)

Spring Modules:
Module Use Case
Spring Core Dependency Injection (IoC)
Spring MVC Web development
Spring ORM Hibernate/JPA Integration
Spring Boot Auto-configuration
configuration + REST APIs
Spring Security Authentication & Authorization

Sd-
Ms. Divya C.M

Campus: Plot No. 25/20/2, Rajiv Colony, Narela. Delhi - 110040


Email: [Link]@[Link] | Website: [Link]

You might also like