1) Why Java?
-->1)Platform Independent
2)Open Source
3)Secure
2)JDK:1)Use For Compilation(Java Devlopmaent Kit)
2)Use For Running a Program it has many [Link]
3)Datatypes:There are primative datatype and non-primitive type.
Primative- default value size
byte 0 1
short 0 2
int 0 4
float 0.0 4
long 0 8
double 0.0 8
boolean false 1
char blank 2
Non-Primitive:All Classes Are under Non-Primitive
-built-in
-custom
4)OOPS:Object-oriented program
Java Has object oriented concept which follow inheritance, encapulsation,
polymorphism, Abstration.
i)Encapulation:1)Binding a data into single entity.
2)To achive good encapsulation in java we need to make our
varible as private and access that variable through
getter and setter method.
ex:class Student{
private String name;
//getter method
public String getName(){
return name;
}
//setter method
public void setName(String name){
[Link]=name
}
}
ii)polymorphism:1)one entity behaves differently at different time.
2)we can achive polymorphism by two ways:i)method overloding
ii)method overiding
i)method overloding: within same class having same method
name but different parameter.
a) if we want to add any feature then we are using
method overloding.
b)access specifier can be anything.
c)Return type can be anything.
d)it is also call as compile time polymorphism.
ii)method overriding :multiple method with same class
and same argument with in super class and sub class.
a)if we want to do any modification then we are using
method overriding.
b)return type should be same.
c)access specifiers of subclass method should be
bigger or same than super class.
iii)Abstraction:a)Abstraction is a process of hiding detalis about
implementation. which means exposing only required things is known as
abstraction.
b)Abstraction can be done in two ways:i)abstact class
ii)interface
i)Abstract class:a)declare with abstract keyword,
b)it extends one class and implement number of
interface.
c)it consist of abstract menthod and non-abstract
method.
d)it has constructor but does not create object.
e)paritial abstraction can be done by abstract
class.
ii)interface:a)declare with extend keyword.
b)it extend number of classes and number of interfaces.
c)it consist only abstract method.
d)fully abstraction can be done by abstract class.
----- Interface can extend interface.
-----overriding is combination of polymorsphism and inhertance.
iv)Inheritance:a)Acquiring all the properties of super class into sub class.
b)by extends keyword we can achieve inheritance.
c)super class is also known as parent class and sub class is also
known as child class.
d)constructor and private thing cannot be inherite.
e)use of inheritance is code reusability.
*if we make our constructor as a private then make all method static and call it by
class name.
Keywords:
a)static: i)static means single copy storage which gives always latest value.
ii)we can make our global variable, method and block as a static.
iii)static goes in memory before object creation.
iv)we can call static things by two ways:a)by object creation b)by
class name
v)static to non static is not possible but nin static to staic is
possible.
.
public class x{
int a=10;
static int b=20;
p.s.v.m(string args[]){
x xx=new xx();
[Link](x.a);
[Link](x.b);
}
}
this keyword:
i)Its a keyword in java
ii)it is used to save memory.
iii)it is exactly replacement of object creation.
iv)it is used to invoke current class object.
private keyword: it is keyword in java
ii)we can make global variable,method and constructor as a private.
iii)for proper encapsulation we are making our variable as a
private.
iv)if we make our constructor as a private make all method as a
static and call it by class name.
final keyword: i)it is keyword in java
ii)final means fixed.
iii)we can make our class, variable, and method as a private.
iv)if we make our class as a final then we can't extend it.
v)if we make our variable as a final then we can't change the
value.
vi)if we make our method as a final then we can't overide it.
singleton in java
In object oriented programming, a java singleton class is a class that can have
only one object at a time.
JPA Repository:
java persistence API Specific extension of [Link] contain API for basic
curd operation and also api for pagination and sorting.
SYNTAX: public interface jpaRepository<t,ID> extends Paging and sorting
Repository(<t,Id>) QueryByExampleExecutor<T>
T:Entity /Model
ID: Type of Id that Repository Managed.
API: i)Api stands for application programming interface.
ii)Api include classes, interfaces and user interfaces.
iii)Programmer can make use of various api tools to make their programmer
easier.
iv)Example i)Web API ii)Local API iii)Program API
Rest API: i)Rest stands for Representational state Transfer.
ii) It define set of Function(Get,put,post,delete).
iii)get(retrive a data)
put(update a data)
post(create a data)
delete(delete a data)
WEB API: i)web api is simply an api for web.
ii)it can accessed using HTTP Protocol.
Group By and Order By :i)Group by Statement is used to group the rows that have
same value.
ii)order by statement sort the result-set either in
ascending or descending order
Example: select*from product
Order by Price DESC;
Offset: Offset clause is used to skip a specified no. of rows before begnining to
return the rows from query.
It is used in conjuction with "LIMIT".
--Query to find 3 highest marks from student.
select Distinct marks ex: 90,85,95,92,85,90,88
from student i)95,92,90,88,85(unique marks)
order by marks desc ii)95,92,90,88,85(asc order)
Limit 1 Offset 2; iii)skip the first two and get next
one
Get 90(which is 3 highest)
--Apply Filter add no from list using Stream API.
import [Link];
import [Link];
import [Link]
public class filterEventNo{
Public static void main(String args[])
List<Integer>numbers=[Link](1,2,3,4,5,6,7,8,9,10)
List<Integer>evenNumbers=[Link]().filter(n-->n
%2==0).collect([Link]()); //convert list to stream,filter even [Link]
collect back tolist
[Link](evennumber);
}
}
Spring: i) The spring framework is open source framework that can be used to
develop java application .
ii)It is Framework in java.
iii)The Spring Framework is divided into three categories:
a)Spring IOC(Inversion of controller)
b)Spring AOP(Aspect oriented Programming)
c)Spring MVC(Model-view-controller)
IOC(Inversion of Control):i)it's most often used in the context of object-oriented
programming.
IOC Annotation: i)@Autowired=>This annotation is used whenever we want spring to
automatically create object of class.
ii)@component=>This annotation allows spring to detect classes
for creation of object.
iii)@value=>This annotation is used to inject primitive and
string values from properties files.
iv)@Bean=>it is replacement of @component with some extra
features.
v)@Qualifier=>if we create one or more bean of same type & want
to wire only one of them with a property.
vi)@componentScan=>in this we are telling spring to look beyond
current package for autowiring and creating object.
ex:
import [Link];
import [Link];
import [Link];
import [Link];
@RestController
public class StudentController {
@Autowired
@Qualifier("test1")
Student ss;
@Value("${portnumber}")
int port;
@RequestMapping("IOC")
public String testCallIOC() {
[Link]("Test IOC");
[Link](port);
return [Link]();
public class Student {
public String nameIOC() {
return "Hello @Bean,@Qualifier and CS";
}
--SPRING AOP(ASPECT ORIENTED PROGRAMMING):i)One of the key component of spring is
the AOP Framework. While Spring IOC does not depend on AOP,AOP is extra Features
for Spring IOC to provide a very capable middleware solution.
@Aspect:Aspect is associated with a pointcut expression and runs at any join point
matched by the pointcut.
ex: import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Aspect
@Component
public class Student {
@Before("excution (*
[Link]())")
public void msg1() {
[Link]("Project Start");
}
@After("excution (*
[Link]())")
public void msg2() {
[Link]("Project End");
}
@Around("excution (*
[Link]())")
public void msg3() {
[Link]("Project Submission");
import [Link];
import [Link];
@RestController
public class StudentController {
@RequestMapping("AOP")
public String advice() {
[Link]("EMS Project");
return"Advice AOp";
Springboot: i)SpringBoot is am open-source freamwork.
ii)It is framework developed on exisiting Spring framework
iii)It have inbuilt classes, method, interfaces, packages.
iv)In Springboot their are curd operation a)GetMapping-Read--To get the
data from DB.
b)PostMapping-create--to
insert the data
c)putMapping-update---to
update the data
d)DeleteMapping-Delete----to
delete the data
@Pathvariable==>If data passes through API in postman.
@RequestMapping==>If data passes through Body in Postman.
JDBC
i)Jdbc is a technology injava language.
ii)Jdbc is technology in java language.
iii)JDBC it is use to transfer a data in database
iv)Data Store Permantantly.
v)communicate between server to database.
public void insert() throws Exception{
[Link]("[Link]");
Connection c =
[Link]("jdbc:mysql://localhost:3306/batch146", "root",
"root");
Statement s=[Link]();
insert: [Link]("insert into student values(101,'shrau')");
[Link]("recored insert");
}
Update: [Link]("update student set name='raj' where id=101");
[Link]("recored update");
Delete: [Link]("delete from student where id=101");
[Link]("recored delete");
ResultSet: To Fetch the multiple data from database
ResultSet rs=[Link](select *from Student)
while([Link]){
[Link]([Link](1)+" "+[Link](2));
PreparedStatement: Use to store multiple values in single object creation.
It is Interface.
Parameter Method
Driver load single time.
PreparedStatement p=[Link]("insert into Values(?,?");
[Link](1,id);
[Link](2,name);
[Link]();
[Link]("Record Inserted...");
}
p.s.v.m(String args[])throws Exception {
A aa=new A();
[Link](103,"sss");
}
}
PreparedStatement p=[Link]("update Student set name="?" where
id="?")into Values(?,?");
[Link](2,id);
[Link](1,name);
[Link]();
[Link]("Record updated...");
PreparedStatement p=[Link]("delete from student where id=?)");
[Link](1,333);
[Link]();
[Link]("Record deleted...");
Hibernate
i)Hibernate is ORM Framework in Java Language.
ii)It is alternative of JDBC.
iii)It is ORM Tool[OBJECT RELETIONAL MAPPING]
iv)Hibernate generates queries automatically as per database.
v)Hibernate is use to transfer a data in database.
SessionFactory: Is responsible for creating session object.
Session:To perform CRUD Operation on database.
public static void main(String[] args) {
Configuration cfg = new Configuration();
[Link]([Link]).configure();
SessionFactory sf = [Link]();
Session ss = [Link]();
Transaction t = [Link]();// I/U/D
Employee ee = new Employee(101, "Java");
[Link](ee);
//[Link](ee);
//[Link](ee);
[Link](ee);
[Link]("Record Inserted...");
[Link]();
[Link]();
Inbuilt Classes in Hibernate :Configuration: class
SessionFactory: Interface
Transition:Interface
Inbuilt Method in Hibernate: i)get()==>get the single record.
ii)load()==>get the single record.
iii)save()==>save the record.
iv)update()==>update the record.
v)delete()==>delete the record.
load: i) To fetch a single record in a database.
ii)Exception will create objectNotFoundException.//This exception typically
occurs in programming when your code attempts to access or manipulate an object
that doesn't exist
get: i)To fetch a single record in a database.
ii)Exception will create null.
Query Interface we can use multiple operation like
save(),update(),dalete(),get(),load() and more.
Criteria interface we can check multiple conditions like
greaterthan(),lessthan(),like().ilkie().
ORM Mapping: i)one to entity is associated with a single instance of
other entity.
ii)one to many==>one row in table can be mapped to multiple row in
another table.
iii)many to entity is associated with a single instance of
other entity.
iv)many to many==>many entity is associated with a many instance of
other entity.
@RestController:to control the class.
@restMapping:is use to map with server.
ANONYMOUS INNEAR CLASS: It can extend exactly one class or implement exactly one
interface.
superclass f=new subclass(){}
SQL
i)SQL Stands for structured query language.
ii)it is used for storing and managening data in relational database management
system(RDBMS)
iii)SQL is not case sensitive.
iv)Advantages: a) High speed
b)No cooding Needed.
c)Multiple Data View.
TYPES OF SQL COMMANDS:
i)There are five types of SQL command
1)DDL(Data Definiition Language)
-It is use to change the structure of table like creating a table deleting a
table, alterning a table...
-Here are some Commands that are used under DDL
a)Drop: It is used to delete both the structured and record stored in table.
SYNTAX: Drop database student;
b)create: It is used to create a database.
SYNTAX: create table student(Name varchar(20),Email varchar(100),DOB date);
c)Alter: It issue to add another column in a table.
SYNTAX: Alter table Student add int rollno;
d)Truncate: It is use to delete all rows from the table.
SYNTAX: Truncate table student;
2)DML(Data Manipulation Language): It is use to modify the database.
Here are some command that are under dml.
a)Insert: It is use to insert a record in table.
SYNTAX: Insert into student("shrau","shravnigavli279@[Link]",2 sep 2002);
b)Update: It is use to update a record in table.
SYNTAX: Update student set name="tau" where id=1;
3)DCL(Data Control Language):i)it is used to implement security on database
objects.
Here are some command that are under DCL
a)Grant: It is used to give user access privileges to database.
SYNTAX:GRANT SELECT, INSERT, UPDATE ON employees TO john_doe;
b)Revoke: It is used to take back permission.
SYNTAX:REVOKE SELECT, INSERT, UPDATE ON employees FROM john_doe;
4)TCL(Transaction Control Language):i)It is use with DML command like insert,
delete, update.
Here are some Command that are under TCL.
a)commit: It is use to save transaction.
Syntax: commit;
b)Rollback: Undo the transaction that have be unsaved.
Syntax: Rollback;
c)savepoint:It is use to roll the transaction back to certain point without
rolling back the entire transaction.
SYNTAX:INSERT INTO employees (name, position, salary) VALUES ('Jane Doe',
'Manager', 80000);SAVEPOINT sp2;UPDATE employees SET salary = salary * 1.1 WHERE
position = 'Developer SAVEPOINT sp3;
-- Roll back to savepoint sp2
ROLLBACK TO SAVEPOINT sp2;
== and ===:i)The == operator compares the values of two variables after performing
type conversion if necessary. On the other hand, the === operator compares the
values of two variables without performing type conversion.
Using the toString() method of the Integer class
Using the valueOf() method of the String class
collection
-to store multiple elements we use collection framework.
-It extends three interface)List ii)set iii)queue
list-List is an interface that is available in the [Link] package.
--Homogenous collection of element.
---Duplicates are allow in list.
--order is maintain.
--List interface has three concrete subclasses:
ArrayList
LinkedList
Vector
ArrayList:--Duplicate elements are allowed.
--maintain insertion order.
--The arraylist extends the AbstractList and implement list interface.
--It is slower than array.
--It is use if we want to add or remove elements from program.
LinkedList:--LinkedList implement list interface.
--It is not Synchronised.
--It has node Representation.
--It access element through iterator and listIterator.
Vector:--Vector implement list interface
--All methods are synchronised.
--It is slower than an Arraylist.
--Vector is thread-safe.
Set--Homogenous collection of element.
--Duplicates are not allow in set.
--There are four classes which implement Set interface:
HashSet
LinkedHashSet
TreeSet
SortedSet - It uses hash table to store elements. Duplicates are not allowed.
HashSet:--Duplicate are not allowed
--It is unoredered
--it access element through iterator.
--HashSet is not thread-safe.
LinkedHashSet:--Duplicate are not allowed.
--It maintain insertion order.
--it access element through iterator.
--LinkedList is not thread-safe.
TreeSet:---Duplicate are not allowed.
---It maintain sorting order.
--- --it access element through iterator.
---treeset is not thread-safe.
Map:--It is heterogenous collection of element.
--A map is used to store the key-value pair.
--It doesn't allow duplicate keys but duplicate values are allowed.
--It has the following concrete subclasses:
HashMap
LinkedHashMap
TreeMap
HashTable
HashMap:--A HashMap is class which implements the Map interface
---It stores values based on key
---It may have null key-null value
---we use the put method to add element in hashmap.
---Return type of put method is Object.
LinkedHashMap:--linked list is implementation of the map interface,
---It stores values based on key
---It maintain insertion order.
TreeMap:-- TreeMap is a class which implements map interface.
--It stores values based on key
---Keys should be unique.
---It is ordered but in an Ascending manner
HashTable:--Hashtable is a class which implements Map interface
---It stores values based on key
---key should be unique
--slower than hashmap.
Iterator:-i)Iterator can be used to access the element of six subclasses of
collection interface.
ArrayList,LinkedList,LinkedHashedSet,Treeset and hashset
ii)using iterator method hasNext() and next(),you can access element of
collection.
iii)you cannot add the element.
iv)using iterator you can remove the element of collection.
v)you cannot replace the existing elements with new element.
ListIterator:--Using ListIterator we can access the element in forward direction
using hasNext() and next() method and in reverse direction using hasprevious() and
previous() method.
---you can add element in collection.
--You can replace the exisiting element with new element.
hasnext():Returns true if the iteration has more element.
next():returns the next element.
Enumeration: Enumeration can be used for accessing element of vector only.
Angular:--- Angular is open source java script framework.
---It is completely written in typescript.
---It is used to build single page application.
---It is designed for web ,desktop and mobile platforms.
Component:-- are the basic building blocks of angular application.
--Every component is associated with a template and it is subset of
directive.
There are three types of directive i)Component directive==> this type
of directive has a template.
II)Structural Directive==>This type of directive is used to make
changes in the layout of the DOM .
iii)Attribute directive
TypeScript:--Angular is written in typescript.
--TypeScript is a superset of JavaScript.
--TypeScript code compiles down to JavaScript that can run efficiently
in any environment.
data binding:--It allow to move data from javascript to view.
--It uses dynamic HTML and does not require programming.
-- We use data binding in web pages that contain interactive
components such as forms, calculators, tutorials, and games.
Single-page:--Single-page applications are web applications that load once with new
features.
-- It does not load new HTML pages to display the new page's.
decorators:---Decorators are a design pattern or functions that define how Angular
features work.
--- Angular supports four types of decorators, they are:
Class Decorators
Property Decorators
Method Decorators
Parameter Decorators
Directives: Directives are attributes that allow the user to write new HTML
syntax specific to their applications.
Angular supports three types of directives.
Component Directives
Structural Directives
Attribute Directives
AOT compilation: The Ahead-of-time (AOT) compiler converts the Angular HTML and
TypeScript code into JavaScript code d
Pipes:--Pipes are simple function designed to accept an input value, process, and
return as an output.
-- Angular supports several built-in pipes.
i) Pure Pipes==>These pipes are pipes that use pure functions.
A single instance of the pure pipe is used throughout
all components.
ii) Impure Pipes==> pipes that execute when it detects an impure change
in the input value.
filters: Filters are used to format an expression and present it to the user.
They can be used in view templates, controllers, or services.
date - Format a date to a specified format.
filter - Select a subset of items from an array.
Json - Format an object to a JSON string.
advantages of Angular: i)MVC Architecture.
ii)Modules: Angular consists of different design patterns
like components, directives, pipes, and services, which help in the smooth creation
of applications.
iii)clean and maintainable code,
iv) unit testing
v)data binding
ngModule: It takes a metadata object that tells Angular how to compile and run
module code.
Templates in Angular: Angular Templates are written with HTML that contains
Angular-specific elements and attributes.
Annotations in Angular: Annotations in Angular are used for creating an annotation
array. They are the metadata set on the class that is used to reflect the Metadata
library.
Wrapper Classes: which convert primitive data type into object and object into
primitive.
Primitive Data Type Wrapper Class
byte Byte
short Short
int Integer
long Long
float Float
double Double
boolean Boolean
char Character
Autoboxing :convert primitive to object
unautoboxing: convert object to primitive
CONVERT INTEGER TO STRING
class GFG {
// Main driver method
public static void main(String args[])
{
// Custom integer input
int c = 1234;
// Converting above integer to string
// using valueOf() Method
String str3 = [Link](c);
// Printing the integer stored in above string
[Link]("String str3 = " + str3);
}
}
CONVERT STRING TO INTEGER:
public class StringToIntExample1{
public static void main(String args[]){
//Declaring String variable
String s="200";
//Converting String into int using [Link]()
int i=[Link](s);
//Printing value of i
[Link](i);
}}
Repository: A repository is nothing but a class defined for an entity, with all the
possible database operations.
Service: Service Components are the class file which contains @Service annotation.
These class files are used to write business logic in a different
layer, separated from @RestController class file.
Controller :We re writing different API and different web service,
@RequestMapping("myHome")
public String home() {
return "home";
}
@RequestMapping("CAccount")
public String save() {
return "save";
}
@PostMapping("save")
public String saveDataBase(Student student) {
Session s=[Link]();
Transaction t=[Link]();
[Link](student);
[Link]();
var,let,const :var==> declaring variables in JavaScript because they have more
predictable behavior.
"const" ==>for constant variables that you don't expect to change,
"let"==> for variables that you expect to change
Access modifiers:
Public
private
protected
default
Non-access modifiers
static
final
abstract
synchronized
Prgrams
i)Equal of two number
import [Link].*;
import [Link].*;
public class Equals {
double width,height,length;
Equals(double w,double h,double l)
{
width=w;
height=h;
length=l;
}
}
class Demo
{
public static void main(String[] args) {
Equals e1=new Equals(10,11,12);
Equals e2=new Equals(10,11,12);
[Link](e1==e2);
[Link]([Link](e2));
Fibonacci Series:
public class FibonaccSeries {
public static void main(String[] args) {
int n1=0,n2=1,n3,count=10;
[Link](n1+" "+n2);
for(int i=2;i<count;i++)
{
n3=n1+n2;
[Link](n3);
n1=n2;
n2=n3;
}
}
}
StringPalindrone:
public class Stringpalidrone {
public static void main(String[] args) {
String original, reverse = ""; // Objects of String class
Scanner in = new Scanner([Link]);
[Link]("Enter a string");
original = [Link]();
int length = [Link]();
for ( int i = length - 1; i >= 0; i-- )
reverse = reverse + [Link](i);
if ([Link](reverse))
[Link]("Entered string is a palindrome.");
else
[Link]("Entered string isn't a palindrome.");
}
}
Armstrong no:
public static void main(String args[])
{
int n = 0,r,sum=0;
[Link]("enter a number");
Scanner scanner = new Scanner([Link]);
int number = [Link]();
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(sum==n)
{
[Link]("number is armstrong");
}
else
{
[Link]("number is not armstrong");
Array:
public class Array {
public static void main(String[] args) {
int a[]= {3,4,5,6};
for(int i=0;i<[Link];i++)
{
[Link](a[i]);
}
Prime Number:
public class primenumber {
static int i, n;
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number");
n = [Link]();
for (i = 2; i < n; i++) {
if (n % i == 0) {
break;
}
}
if (i == n) {
[Link]("Number is Prime");
} else {
[Link]("Number is not prime");
}
}