Advanced Java
Topics Covered in Adv Java:
✓ JDBC
✓ Servlets
✓ JSP
Pre-requisites:
✓ Core Java(in-depth)
o variables & Data types
o Arrays
o Methods
o Strings
o Classes & Objects
o OOPS Concets
✓ SQL(DDL, DML, DQL, DCL & CRUD Operations)
✓ Basic HTML
Project Architecture/Layered Architecture:
Every project will have 3 layers
1. Presentation layer
2. Business layer
3. Database layer
Backend
Frontend
database
Web Business Persistance
User Layer Logic Layer Layer
Interface(UI)
JSP Servlets Core Logic JDBC
1. JDBC → Hibernate → JPA
2. Servlets → Spring MVC
3. JSP → Angular / React JS
Education is the most powerful weapon, which you can use to change the world.
-Nelson Mandela
[1]
For Java:
JDBC: Java Database Conntecivity
For .Net:
ADO.NET: Active x Data Object
Database:
Software application which stores data permentaly
Ex: MySql, Oracle, SQLServer etc
Persistance Layer:
It Contains the Logic to communicate with Database
Ex: Java Program ------JDBC------> Database
Business Logic Layer:
It Contains the Business Logic of the Project.
Ex: Sending OTP, Ticket Booking, Searching for Flights etc
Ex: https://www.makemytrip.com/
Note: Actual Core Java is Required for Writing the Business logic of the Project.
Java – Core Java
Ms.NET – C#.NET
*** Business Logic will Change from Scren to Screen and Project to Project
Web Layer:
Contains the Logic which takes request from the user and gives back response to
the user.
Ex: Servlets
Java – Servlets
.Net – ASP
Presentation Layer:
UI/UX: User Interface and User Experience.
✓ HTML & CSS
✓ Java Script
✓ Bootstrap
✓ JSP(Java Server Pages)
✓ Angular/React JS
HTML – Static Web Page
JSP – Dynamic Web Page
Education is the most powerful weapon, which you can use to change the world.
-Nelson Mandela
[2]
Full Stack Technologies:
Java Full Stack .Net Full Stack
Language Core Java C#
DB Connection JDBC ADO.NET
Web Layer Servlets ASP
Servers:
Apache Tomcat, JBOSS Server etc.
Core Java Basic Concepts:
Java API, Jars, Path, classpath
Web Application Project Layers(Any Technology):
1. Presentation Layer
2. Web Layer
3. Business Layer
4. Presistance Layer
Order of Project Creation
Creation of Database Tables → Persistance Layer → Business Logic Layer → Web
Layer → Presentation Layer.
What is Software Project?
✓ Collection of Programs is known as a software project
✓ Software Development is a Team Work
In Industry there are 3 types of Projects:
1. Scratch Development(Brand New Project)
2. Maintenance/Support Projects
3. Migration Projects
Note:
Startups may have New Projects, But where as MNC’s will Have Mostly Support
& Migration Projects only.
How Many Lines of Code we can Write in one Java Class?
✓ It is Recommended not to write more than 2000 lines of code in one class
for maintenance purposes.
Education is the most powerful weapon, which you can use to change the world.
-Nelson Mandela
[3]
Types of Applications and How Java Applications are Delivered to the Client?
1. Standalone applications
a. Eclipse, Notepad, Calculator etc.
b. Delivered as Jar files (Java Archive)
i. Collection of .class files →
c. To run Java Project we need JRE
d. .java files → .class → .jar
e. Note: Create a jar file of any of your java project using eclipse IDE
2. Web Application ( Customer to Business)
a. atishjain.in, courses.atishjain.in etc
b. Deployed as War files (Web Archive)
i. Collection of .class files along web assets(.html, images,
videos etc)
c. To Run Web Applications we Need Server(Tomcat, JBOSS etc)
d. .java files+web app(.htm,.js,images,videos) flies → .class+web
resources → .war
3. Enterprise Applications (Customer to Business to Business)
a. Enterprise Applications(Distributed Applications) are Delivered as
.ear files
i. .ear - Enterprise Archive
b. Ex: makemytrip, amazon, bookmyshow,irctc, etc
How to Create Create .jar file from command prompt
Create User.java file in e:\advjava folder
File name: User.java
public class User
{
public static void main(String[] args)
{
System.out.println("Hi I am Atish Jain!");
}
}
Education is the most powerful weapon, which you can use to change the world.
-Nelson Mandela
[4]
Worknig with jar command:
Syntax:
> jar cvfe <jar-file name> <main class> *.class
Ex:
> jar cvfe app.jar User *.class
✓ jar is the command to create jar files
✓ c – create
✓ v – verbose (Displays the process in console)
✓ f – file
✓ e – entry point to run the application(main method class name)
✓ main class – main method class name
✓ *.class – packaing all the .class in the current working directory
Executing jar file:
> java -jar app.jar
To Extract the jar file:
> jar -xvf app.jar
Using .class files of .jar files in our Projects:
User.java
public class User
{
public void speak()
{
System.out.println("Heyy My Self Atish Jain");
}
}
Demo.java
public class Demo
{
public static void main(String[] args)
{
User u=new User();
u.speak();
}
}
Education is the most powerful weapon, which you can use to change the world.
-Nelson Mandela
[5]
Create non Runnable jar files using User.class
> jar cvf app.jar User.class
Note: Delete User.java and User.class and Execute the Demo.java
✓ If we want to use .class files of jar in our project then we have to set
CLASSPATH Variable.
✓ CLASSPATH is used to load the .class files
✓ Set CLASSPATH=app.jar.;.;
Note:
✓ CLASSPATH setup from Command Prompt is Temporary
✓ CLASSPATH setup in Environments Variables Is Perment
Jar files are divided into two types:
1. Executable Jar file/Runnable Jar File(Contains main method)
2. Non-Executable Jar file
Difference between PATH & CLASSPATH:
✓ PATH – To Locate executable files (ex: javac.exe, java.exe etc)
✓ CLASSPATH – To Locate .class files / .jar files
Assignment:
✓ Create Student.java(just empty class), Employee.java(just empty class)
and compile it to generate Student.class and Employee class
✓ Package Student.class & Employee.class in app.jar and delete all the files
(Student.java and Student.class, Employee.java and Employee.class)
✓ Create ProjectDemo.java with main method and display hashcode of the
Student and Employee Objects.
Java API:
✓ API Stands for Application Programming Interface, Java is API s Just Like a
User Manual of a Product/Service.
✓ API Contains set of Classes & Interfaces
✓ Sun Microsystems Provided Java SE and Java EE API
✓ Java SE API Contains Set of Classes & Interfaces to build Standalone
Applications
✓ Java EE API Contains set of Classes & Interfaces to build Web Applications
and Enterprise Applications.
Education is the most powerful weapon, which you can use to change the world.
-Nelson Mandela
[6]
Java SE API: https://docs.oracle.com/en/java/javase/21/docs/api/index.html
Java EE API: https://docs.oracle.com/javaee/7/api/toc.htm
Java SE API Java EE API
java.lang javax.servlet
java.io javax.servlet.jsp
java.sql javax.persistance
java.util javax.transaction
………….. …………..
Comments in Java:
✓ Single Line Comments
✓ Multi Line Comments
✓ Documentation Comments
Note: Documentation Comments are used to Generate Documentation for Java
Projects.
How to Generate Documentation for our Java Classes
✓ Javadoc creates metadata of our source code(classes, variables,
constructors, methods and interfaces).
Create User.java File
https://github.com/atishjain9/Adv-Java/blob/main/User.Java
> javadoc -d myapi User.java
-d – create a directory
myapi – folder name
User.java - File name (user *.java for all files)
Note: Java Class and Methods Must be public
> javac User.java
> javap User
Javap – Java profile, ie to see contents of .class file
Education is the most powerful weapon, which you can use to change the world.
-Nelson Mandela
[7]
Working with IDE:
Download and Extract STS – Spring Tool Suite
https://spring.io/tools/
How to Setup CLASSPTH using IDE’s:
✓ In Java development, both "classpath" and "build path" are terminologies
related to managing dependencies and resources in a Java project.
✓ They are often used in different contexts, primarily associated with
different Java development environments.
✓ The distinction lies in their association with different Java development
environments.
✓ The classpath is configured for command-line compilation, while the build
path is configured in IDEs.
Example:
App1 App2
User.java Test.java
Start STS IDE:
File → new → Java Project
Name: App1
→ Next → Finish
Create User.java class
public class User {
int id;
String name;
public User()
{}
public User(int id,String name)
{
this.id=id;
this.name=name;
}
public void display()
{
System.out.println("Hi, My Self "+name);
}
}
Education is the most powerful weapon, which you can use to change the world.
-Nelson Mandela
[8]
Create .jar File
Right Click on the Project → Export → Jar →
Choose the Destination
Name: app1.jar
Next→ Next → Finish
Close the Project App1
Note:
Jar files also known as libraries
App2:
File → new → Java Project
Name: App2
→ Next → Finish
Create Test.java class
Add the External Jar app1.jar
Right Click on App2 Project → Build Path → Configure Build Path → Libraries →
Add External Jars.. →Select the Required jar file → Apply → Apply & Close
File Name: Test.java
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
User u=new User(101,"Raj");
u.display();
}
}
Java Decompiler:
A Java decompiler is a tool that converts Java bytecode into readable Java source
code, helping to understand and analyze code when the original source is not
available.
Download and extract:
https://java-decompiler.github.io/
Note: We can Decompile .class files and .jar files also
Education is the most powerful weapon, which you can use to change the world.
-Nelson Mandela
[9]