JAVA FULL STACK DEVELOPMENT
JAVA FULL STACK DEVELOPMENT
DEVELOPMENT
CO-1
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
HIBERNATE
----------
1)Introduction
2)Why Hibernate
3)Advantages of Hibernate
4)Architecture
5)POJO Class
6)Mapping File (xml file)
7)Configuration File (xml file)
8)Hibernate Examples (CRUD Operations)
9)Hibernate Query Language (HQL)
10)Hibernate Criteria Query Language
11)Inheritance Mapping
1) Introduction :
----------------------
Hibernate is a Java program developed by Gavin King
It is a Framework which simplifies the development of java application to interact
with a database
It is an Open Source, light weight and works based on ORM Tool
- ORM Tool:
Object Relational Mapping
ORM is a technique for converting data b/w Java objects & Relational
Databases (Tables)
ORM implements the responsibility of mapping java object to Relational
database
JAVA Application--------ORM(Hibernate)--------Database
hibernate
hyBetis
myBetis
TopLik,etc
2) Why Hibernate
-----------------------
Simplifies database interaction
Cross Database portability
3) Advantages of Hibernate
----------------------------
- Open source & Light weight
- Fast Performance
- Database independent query
- Auto table creation
- Exception Handling
4) Hibernate Architecture
---------------------------
Hibernate Architecture consists of 3 layers
Application Layer - java application
Hibernate Layer - mapping & configuration
Database Layer - Oracle, MySQL
Refer to Diagram
5)POJO Class
--------------
POJO stands for Plain Old Java Object
POJO is nothing but a Java Bean
Hibernate allows only POJO classes
POJO class consists only Setters & Getters
Example:
--------
Class Employee{
private int eid;
private String ename;
getEid(){
}
setEid(){
}
getEname(){
}
setEname(){
}
Configuration File:
--------------------
- The purpose of configuration file is to define the properties of database.
- Configuration file can be defined in 2 ways.
- It will be either in xml or using annotations (xml)
- The Configuration file has to be denoted by hibernate.cfg.xml (save)
- Configuration file is loaded into hibernate application
- The configuration file must contain following information
- Connection properties
- Hibernate properties
- mapping file resources
Note:
Number of configuration = No of databases
Syntax:
hibernate.cfg.xml
-----------------
<hibernate-configuration>
<session-factory>
<!connection properies>
<property name="connection.driver_class">Load Drivers</property>
<property name="connection.url">Connection URL</property>
<property name="connection.username">Username</property>
<property name="connection.password">Password</property>
<!hibernate properties>
<property name="show_sql">true/false</property>
<property name="dialect">database name</property>
<property name="hbm2ddl.auto">create</property>
<!mapping file>
<mapping resource="filename(mapping)"/>
<mapping resource="filename(mapping)"/>
<mapping resource="filename(mapping)"/>
</session-factory>
</hibernate-configuration>
Example: Oracle
<hibernate-configuration>
<session-factory>
<!connection properies>
<property
name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property
name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="connection.username">system</property>
<property name="connection.password">admin</property>
<!hibernate properties>
<property name="show_sql">true</property>
<property name="dialect">oracle</property>
<property name="hbm2ddl.auto">create</property>
<!mapping file>
<mapping resource="employee1.hbm.xml"/>
<mapping resource="employee2.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Example: MySQL
<hibernate-configuration>
<!connection properies>
<property
name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property
name="connection.url">jdbc:mysql://localhost:3306/</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!hibernate properties>
<property name="show_sql">true</property>
<property name="dialect">mysql</property>
<property name="hbm2ddl.auto">create</property>
<!mapping file>
<mapping resource="employee1.hbm.xml"/>
<mapping resource="employee2.hbm.xml"/>
</hibernate-configuration>
Mapping File:
--------------
- It is a part of Hibernate Application
- Mapping file will be denoted either in xml
- Mapping file will be implemented either in xml or annotations (xml recommended)
Every Orm is a
-It is a mechanism of placing object properties (java object) to the specific
column of a table (DB)
- This mapping file contains how a mapping can be done from a POJO class to db name
and from class properties to column names
POJO class -> table name
prop1 -> column1
prop2 -> column2
- While creating mapping file, we can create one or multiple no. of mapping files
based on application requirement
Note:
java Object -> table
Syntax: filename.hbm.xml
------------------
<hibernate-mapping>
<class name="POJO class name" table="table name in DB"/>
<id name="class-property" column="col name in table"/>
<property name="class-property" column="col name in table"/>
</hibernate-mapping>
Example: employee.hbm.xml
------------------
<hibernate-mapping>
<class name="Employee" table="emp"/>
<id name="eid" column="tid"/>
<property name="ename" column="tname"/>
</hibernate-mapping>
- table is created by user with table name as emp and col names as tid and
tname
Note: Significance of Hibernate
(Table MUST be created automatically)
Syntax: filename.hbm.xml
------------------
<hibernate-mapping>
<class name="POJO class name"/>
<id name="class-property"/>
<property name="class-property"/>
</hibernate-mapping>
Example : employee1.hbm.xml
------------------
<hibernate-mapping>
<class name="Employee"/>
<id name="eid"/>
<property name="ename"/>
</hibernate-mapping>
HQL :-
---
Query Interface :-
-------------
Example - 1 :-
-------
HQL Example
(To retrieve all the records)
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
Transaction t = s.beginTransaction();
List<employee> l = q.list();
for(employee X:l)
System.out.println(X.getEname());
}
}
}
Example -2 :- HQLRetItr:-
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
Transaction t = s.beginTransaction();
List<employee> l = q.list();
Iterator<employee> i = l.iterator();
while(i.hasNext()) {
employee e = i.next();
System.out.println(e.getEsal());
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
Transaction t = s.beginTransaction();
q.setFirstResult(5);
q.setMaxResult(15);
List<employee> l = q.list();
Iterator<employee> i = l.iterator();
while(i.hasNext()) {
employee e = i.next();
System.out.println(e.getEsal());
Example-3:-
---------
Example-4:-
---------
HQL-> update
q.setParameter(n,"XYZ");
q.setparameter(i,111);
Example-5:-
-------
Example-6:
------
Example-7:-
------
Hql Example(retrieve all records with partial no.of columns)
Iterator i = l.iterator();
while(i.hasNext()){
Object ob[] = (object[])i.next();
System.out.println(ob[0]+" " + ob[1]);
Example-8:-
-------
HQL example(to retrieve all records with single column)
Iterator i = l.iterator();
while(i.hasNext()){
Object ob = (object)i.next();
System.out.println(ob);
Example-9:-
--------
HCQL
-----
- Hibernate Criteria Query Language
- Using HCQL I can retrieve records with all the records at a time
- In order to implement HCQL in hibernate application, I need to use criteria
interface
Criteria Interface:
Criteria interface object can be obtained by calling createCriteria()
method to a session object
Criteria cr = s.createCriteria();
Restriction Class
------------------
this is a class which consists of many methods
to add restriction/condition/criteria on HQL query
- The methods of Restrictions class are
a.lt()
b.le()
c.gt()
d.ge()
e.eq()
f.ne()
Order Class
------------
- This calss consists of many methods
- In order to retreive or display data from db tabe either in ascending or
descending order
- The methods are
a. asc()
b. des()
Example 1 : HCQL Example
Inheritance Mapping:
---------------------
Inheritance:
-------------
- Aquire the properties from Base Class to Derived Class refers to Inheritance
- Inheritances are 5 types (OOP)
1. Single Inheritance
A
|
|
B
2. Multiple Inheritance
A B C
| | |
| | |
-----------------
|
|
D
4. Hierarchial Inheritance
A
|
|
-----------------
| | |
| | |
B C D
5. Hybrid Inheritance
- Combination of Multiple Inheritance + Hierarchial Inheritance
A
|
|
-----------------
| | |
| | |
B C D
| | |
| | |
-----------------
|
|
E
Note :
Java doesn't support Multiple Inheritance
Mapping:
- Mapping refers to the relationship between different tables in your Database
- Different types of mappings are
1. IS-A (Inheritance)
2. HAS-A (Association)
Scenario:
Payment Person
| |
| -------------------------
---------------- | |
| | Student Employee
Card Cheque
POJO Class:
--------------
class Payment{
int pid;
double pamount;
Class Card{
String cardType;
class Cheque{
String chequeType;
Configuration File:
---------------------
<property name="cardType"/>
</subclass>
</class>
</hibernate-mapping>
class TablePerClass{
Transaction t = s.beginTransaction();
c.setPid(101);
c.setPamount(1,45,000);
c.setCardType("Credit Card");
cq.setPid(201);
c.setPamount(1,40,000);
c.setChequeType("RTGS");
s.save(c);
s.save(cq);
t.commit();
s.close();
sf.close();
DB:
Payment
pid pamount cardType ChequeType
101 1,45,000 Credit
Example-2 : TablePerSubclass
POJO Class:
------------
same as previous
Configuration File
-------------------
<hibernate-mapping>
<class name="com.klu.JFSDS25_IMTC.Payment" >
</class>
</hibernate-mapping>
Logic File
-------------
same as previous
Card Cheque
pid pamount cardType pid pamount chequeType
101 1,45,000 Credit 201 1,40,000 RTGS
3.
Mapping
--------
<hibernate-mapping>
<class name="com.klu.JFSDS25_IMTC.Payment" >
</class>
</hibernate-mapping>
Logic
------
same
DB -> Table per Concrete Class
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
CO - 2
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
1) Introduction
2) Why Spring
3) Advantages of Spring
4) Spring architecture
5) Dependency Injection (DI)
6) Inversion of control (IOC)
7) Primitive and non Primitive datatypes
8) Spring DAO ( Data Access Objects) using JDBC
9) Spring DAO ( Data Access Objects) using Hibernate
10) Spring MVC using hibernate
Introduction:
--------------
- Spring is a java framework which was developed by Roe Johnson
- This framework is used to build Java application at Enterprise level(We can
build console apps and applications and web application, This framework, This
framework provides that the user is able to interact with console and web
application)
- It is light weight Framework i.e., Application design using spring frame work
execute faster.
- The core principle is to simplify the java development process and promote good
design practices
Why Spring?
--------------
- Using Hibernate , we can build only console applications whereas using Spring
framework, we can able to build applications console to web
- Hibernate is a ORM Framework primarily focussed on Data Persistence where as
Spring is a comprehensive framework that provides wide array of features
- Spring can be used with various ORM Frameworks including Hibernate ( Spring is
called as Master Framework / Mother Framework )
Advantages of Spring
---------------------
- Lightweight
- Fast Performance
- Eay to test and maintain
- Allows Loosely Coupled
- It provides pre defined templates
Spring Architecture
---------------------
- Spring Architecture consists of several modules such as IOC,DAO,ORM,Web MVC,
AOP,etc.
- All these modules are grouped into Test , Spring Core Container, DAO, Web MVC
( Refer to diagram - internet )
class Test{
public static void main(String[] args){
ApplicationContext ac = new
ClassPathXmlApplicationContext("applicationContext.xml");
dao.insertEmployee(e);
}
}
- MVC is one of the popular and standard design pattern / architecture which will
be used by most of the developers to build web application
- Spring MVC is a java framework which is used to design web applications
- Spring MVC includes all the basic core components of Spring like DI ( Dependency
Injection ) & IOC ( Inversion of Control )
- Spring framework provides ans elegant solution to build web application following
MVC architechture using DispatcherServlet (Class name)
- DispatcherServlet is a class in spring framework that receives an http request
and maps the right resources such as model, view, and controller
- The architechture of Spring MVC is
Refer to Internet
Steps involved in Spring MVC
1. Http Request
2. Dispatcher Servlet
3. Handler Mapping
4. Controller (model and View)
5. ViewResolver
6. View (Http Response)
Explanation:
- This architecture follows sequence of events corresponding to an incominbg
HttpRequest to dispatcher servlet
- After Receiving HttpRequest, dispatcherServet consults handlermapping to
call the appropriate controller
- The controller will take the request and call the appropriaaaaate servic3
method uwing GET and POST
- Then DispatcehrSevlet will ake the help of ViewResolver to pick up a right
view based on httpRequest
- Finally, the viewnwhich got picked by ViewResolver will be HttpResponse
Web Application
(Bus Reservation System)
Http Request
HttpRequest
(Httpe://www.abhibus.com) ---------------->
Web Page
(Abhi
Bus)
(Web Server)
(AWS)
REACT
Introduction
Why React
Adv of React
Features of React
Pro and Cons of React
React js vs angular js
React Native vs React js
React JSX
React Components ***
React State
React props
React props validation
React state vs props
React Constructor
React Components API
React Components Lifecyle
React Forms
Conditional Rendering
React Lists
React Keys
React Fragments
React Router
React CSS
React Map
React Table
React Animation
React Higher Order Components
React Code Splitting
React Context
React Hooks
React Flux
React Redux
React Axios
React Portal
Introduction:
-------------
Why React
----------
To develop UI to increase speed of application
Using React, and application can be splitted into several components
The Flow of Data in React is Uni Directional
Advantages of React:
--------------------
Virual DOM
Faster Rendering
Reusable
Cross Platform Development
Search Engine Optimization
Features of React:
-------------------
JSX
Component based Architecture
One way Data Binding
Application Performance
Dynamic Routing ( Static vs Dynamic Routing )
@imasheshk (https://t.me/imasheshk)
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
CO3 - SPRING BOOT
Introduction
Why SpringBoot
Features of Spring Boot
Advantages of Spring Boot
Spring Boot Architecture
Working with Spring Boot (3 ways)
Spring Initializr
SAS Tool (IDE)
CLI (Command Line interface)
Spring Boot examples (SI)
Thymeleaf and views(html/jsp) rendering
Spring Starters (web)
Spring Boot web MVC(CRUD)
Spring Boot Security
Note : Spring Boot -> No configuration files
Default server--
INTRODUCTION
-------------
Spring Boot is a Spring Module which provides rapid development
It is used to create spring based applications with minimal configuration
Spring Boot is a combination of Spring & HTTP services (GET, POST, PUT, DELETE)
Latest version of spring Boot is 5.x
Developed by Dave Syer
Spring Boot is a java framework which is used to build applications(web) .
It provides an easier and faster way to setup configuration and run both simple
and web application
Why Spring Boot:--
It reduces the development time & cost
It provides powerful database transaction management
It simplifies the integration of other java frameworks like hibernate , Spring,
filters, struts etc
Features of Spring Boot:------
Data access is easy
Testing automatically
Auto Configuration
Spring Boot starters (Web)
Embedded servers
Security
--
Spring Boot Initializr
Advantages of Spring Boot:
It offers a lot of plugins--
It offers CLI (command line interface) for developing and testing Spring Boot
Application
It increases the productivity as it decreases the development time
Spring Boot Architecture:--
1.
It represents View or User Interface
Consists of 4 layers
Each layer with have a communication or interaction with other layers in both ways
The layers are :
Presentation Layer:
Presentation Layer------------->(Bidirectional)
Business Layer------------->(Bidirectional)
Persistence layer------------->(Bidirectional)
Database Layer
It handles the HTTP request received from the user and transfers the same to
business logic
2.
It handles the Business Logic of your application
3.
It handles the storage logic
4.--
Business Layer:
Persistence Layer:
Database Layer:
It handles the database and performs crud operations
Working with Spring Boot:
We can start working with SB using 3 different ways
1 Spring Initializr(recommended)
2 STS Tool (Spring Tool Suite - IDE)
3 CLI
1. Spring Initializr :
---------------------------
1. Open https://start.spring.io/
2. project --> maven
3. Language --> Java
4. Spring BooT --> 3.2.10
5. Project Metadata
Group
Artifact
Name
6. Dependencies
--> Spring Web
--> Spring Security
--> Spring Boot DEV Tools
--> Thymeleaf
7. Generate --> Project will be downloaded which is Boiler Plate Code
Note:
To return a String on Browser Controller must be annotated with @RestController
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class Controller2 {
@GetMapping("index")
public String method2() {
return "index";
}
}
Note:
------
Spring Boot Application / Project Components
----------------------------------------------
1. application properties
- It is a component which defines all the properties of a SpringBoot
Application
- src/main/resources
application.properties
Ex: spring.application.name = projectname
server.port = 2004
spring.mvc.view.prefix = /views/
spring.mvc.view.suffix = .jsp
2. Annotations
- Annotation is a form of data about application , every application
represents some form of data
i. @Required
- This is method level annotation
- This annotation is used for method which is mandatory to
execute
ii. @ComponentScan
- This is class level annotation
- It is used to scan a package for beans
iii. @Bean
- This is method level annotation
- It is infact an alternative to XML file
- It tells the method to produce a bean managed by Spring
container
iv. @Component
- It is a class level annotation
- It is used to make a java class as a bean
v. @Service
- This is a class level annotation
- It is used for a class where the business logic of the
application is defined
vi. @Repository
- This is class level annotation
- It is used for a class where DAO implements
i. @SpringBootApplication
- This is class level annotation
- The purpose is, it defines starting point of your application
- This annotation is a combination of 3 annotations
a. @EnableAutoConfiguration
b. @ComponentScane
c. @Configuration
ii. @RestController
- This is class level annotation
- It is used to implement REST Services
iii. @RequestMapping
- This is method level annotation
- It is used for any kind of HTTP request
iv. @GetMapping
- This is method level annotation
- It maps an HTTP GET request
v. @PostMapping
- This is method level annotation
- It maps an HTTP POST request
vi. @PutMapping
- This is method level annotation
- It maps an HTTP PUT request
vii. @DeleteMapping
- This is method level annotation
- It maps an HTTP DELETE request
viii. @Controller
- This is class level annotation
- It is used for class where the methods are defined to render
view
3. Dependencies Management
- It manages all the dependencies for maven project ( using SI )
- The Dependencies will be managed in pom.xml file
4. Webapp
- It manages all the views to be rendered
- It must be created by developer
5. Spring Starters
- It will be discussed as our next topic
Example - 5:
Render a form using JSP
application.properties
Example - 6:
Render a form and When you click on Submit button display message on brows as
"Details Submitted Successfully"
Example - 7:
Render a form & when you click on Submit button display the details entered
in the form on a webpage4
Example - 8:
Provide the pathname in url & display the same on webpage
O/P:
Name:
Mobile:
9. Spring Starters
--------------------
- It is a collection of dependencies which simplifies the development process
of springboot application
- The different Spring Starters are
1. Spring Web
2. Spring Parent
3. Spring Actuator
4. Spring Test
5. Spring JPA
6. Spring Security
7. Spring Thymeleaf
8. Spring DevTools , etc
1. Spring Web:
----------------
- To act as a Web Application
4
5. application.properties
server.port=2004
spring.datasource.url = jdbc:mysql://localhost:3306/klu
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.ddl-auto = update
6. Entity Class
Class Employee{
@Id
private int eid;
private String ename;
private double esal;
8. Implementation Class
EntityManager em;
@Override
public void insertEmployee(Employee employee) {
em.persist(employee);
}
EmployeeDAO edao;
@Override
public void run(String... args) throws Exception {
Employee e = new Employee();
e.setEid(111);
e.setEname("Kowsik");
e.setEsal(50000);
edao.insertEmployee(e);
}
}
- JFSDS25-SBS
sr/main/java
com.klu
ControllerSecurity
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
CO 4
------------------
------
Spring Cloud and Microservices
Introduction
Why Spring Cloud
Features of Spring Cloud
Advantages of Spring Cloud
Architecture
Spring Cloud Components
Main Projects of Spring Cloud
Spring Boot vs Spring Cloud *
Microservices
--------------
Introductiion
Why Micro Services
Features
Advantages of micro Services
Architecture
Creating a simple microservice
Working with microservices
Features:
---------
To build Cloud Applicaiton
Centralization