EDu Induction
EDu Induction
====================
java comes from diffrent vendors with different folder structure.
below are the types of java softwares.
1)Open JDK---this is from redhat company
2)Oracle JDK---this is from Oracle
3)JRocket kit----This is from Oracle weblogic
Example: msoffice
>>>>>>>>>>>>>>>>>>>>>>>>>>
Java
------
>>java supports big data/AI.
>>if i had a new PC with O/s,will i have java in that machine?
ans) JRE
javac Hellow.java
java Hellow
Open notepad
write the codesave the file with "classname.java"
save it
>using decompiler tool,we can convert class file(byte code) to source code.
Note: decompilers are not allowed in all organizations.
Decompiler tool is not part of jdk,it is 3rd part tool.
windows--all windows o/s will work on windows architecture (win32 api calls)
Linux---all linux flavours used kernel mode and linux architecture
mac---macintosh arch
Sunsolaris....etc
bytecode--can run on
In java,if any thing starts with "native" that indicates that function/class is
written in other language ie c or C++.
java doent support Garbage values.Java doesnt support pointers explicitly.It uses
internally for memory allocation..
C and C++ there is Garbage value concept,because it supports pointers.
=====================================
winzip----compress files and folders.
like above
2,3--integer
3.12---float
srinivaskolaparthi---varchar
+---operator
any thing which you declare within a block is called AS LOCAL and it can be
accessible only within that block.
{
}---unnamed Block
add()
{
//idf we
}----named block
datatype variablename;
always within a block local variables will have more priority than global.
comments:
2.345
------------>Rules
1)In a single java program we can have any no of classes.
2)In a single java program we can have only one public class.
3)Alwyas filename and public class name shld be same.
4)i can have class with in a class ie nested classes.
5)we cannt use static in front of a class.only public ,abstract and final are
allowed for a class.
6)A class casn be private and static only in the case of inner classes.
7)A public class shld have main method for sure
8) We shld not write the code outside the class.
i/p:Java Fullstack
expected o/p: jAVA fULLSTACK
Always we recommend you to use predefined API.because these are tested and proved.
>>In java main accepts some parameters which are of type string array
if we want to pass some input to main method ,we can do it via command line
arguments.
>>>>Static:
-Static is no way releated to Objects.
-static contents are loaded first and then non static.
-Always main method shld be static.
static contents are loaded first--VVIP
Non static are loaded when you creat Object,otherwise not--economy
Character:
char e = 'w';
2 types of castings.
1)Implicit: jvm will do convertion to another type on backend.
2)Explicit: developer shld write necessary logic to do conversion.
=======================================
>>Wrapper classes:wrapper classes provides a mechanism to convert primitive to
object and vice versa.
1.5 version
Observations
=============
1)USe getNumericValue() method maily for unicode characters
2)BAsed on the given data,wisely choose which wrapper class suports us to perform
casting.
>,<,>=,<=,||,&&,%,/
Conditional Statements:
=========================
if--
if-else
Switch:
--------
>switch can have any no of cases.No limit
>recommend to add default for every switch case.
>Every case shld have break.break will instruct JVM to come out of switch statement
when it reaches end of the case..
>from java 1.8 ,we can use strings even in switch.Only int values, strings or enum
variables are permitted.
>Switch within switch is possible.
>>Strings cannt be compared using ==.In javascript for deep comparision,we are
having === operator.But in java we dont.Instead we can use equals method.
We can concatinate 2 strings using "concat" function.else we can also use "+"
symbol.
Stringbuffer stringbuilder
Every Object in java will have unique no for identification like aadhar no for us.
Loops:
======
if any duplicate code is a found by sonarqube,it will not allow your code move to
next phase,then ultimetly code will fail.
>>>
break: it will break exceution of the loop ie it will come out of the loop.
continue:it will not come out of the loop,but it will skip the exceution of the
block for given condition.
>Nested Loop:
loop with in loop is called as Nested Loops.
Return
=======
>return is used for returning some values to called environment.
>return also will return control back to called environment.
>if we add retrun in main,u are passing controll to JVM.
Java Beans(POJO)
================
>>pojos are mainly used in Spring ,Springboot and JPA frameworks.
>pojo stands for plain old java object.
>Pojo means a class with below rules and regulation.
-------
1)Pojo classses will not have main method.
2)Property shld be private and methods shld be public.
3)pojo classes shld have setters and getters for each property.
4)Pojo classes shld not implement interfaces.
5)We shld not write business or db logic in pojo.
6)Pojo classes will not have any abstract method.
7)It shld have no argument constructor.
8)static is not allowed in pojo.
9)Always pojo classes shld be in a sperate package.never keep pojo in default.
In oops,
.-entire concept is based on Object.
Class:
======
>A class is a combination of State and behaviour.
state---properties that we define in a class
behaviour--means functionality
>Electrical switch---Object
>If we are having Object ,then as per OOPS,class shld also exist.
CAR(class)----->Sports Car ---->Normal Car(Breeza,Zen,...etc)
Normal car belongs to CAR.
>ON/OFF---Properties
if ON--then switch shld work
if OFF--Power supply shld stop
>>Class comes to existence /life if we create Object in OOPS.
>>Security:
3 types of securitie levels.
1)Code level security-----private public protected.---developer
2)App level security-------DEVOPS/IT team with developers
3)Server level Security----------DEVOPS/IT team/Hosting team
>>>When ever JVM encounters "new" in the code,that indicates it shld allocate
memory for the object.
Abstraction:
=============
>>Abstraction is a process of hiding the implementation details and showing only
functionalty to the end user.
To achieve abstraction in java
1)Interfaces
2)Abstract classes
Abstract method:
=================
Method without body/logic is called as abstract method.
Concrete Class: class with only concrete methods is called as Concret Class.
Abstract Class:
=================
>>class with only abstract methods is called as pure Abstract Class.
>>>>class with only abstract method and concrete methods is called as partial
Abstract Class.
>>we are use the keyword "abstract".
>>As there is no body for abstract methods,we cannot create Object.
>>In reality,always abstract classes shld be in a seprate package.
>IF we want to implement logic for abstract methods then we need to extend that
abstract class.
>>In pure abstract classes,dont add any constructor.
>>Constructor:
==============
>A constrcutor is a member function whose name is same as Class name but without
return type.
>constrcutor wont return anything.
>constrcutor are mainly used for intilializing class level variables.
>Even void is not alloweed for Constructor.
>if we are not adding any constructor,then JVM will add default constructor at
runtime.
Overloading: Overloading means using same name multiple times but with difrrent
parameters.
>Overloading occurs within a class,not outside the class.
Rule:
While overloading makesure no 2 functions/constructor has same method signature.
Overiding: If subclass has same method as declared in Parent class ,it is called as
Overiding.
Interfaces:
========
An interface is similar like a class but with only abstract methods.
Rules:
>Any method that we declare in a class is by default abstract.
>Any variable that we declare in interface is by default public static final.
for impl,
<interfacename>Impl
Inheritance:
============
>proces of inheriting properties and behaviour from base class to child class is
called as Inheitance.
>Advantage is Code resuability.
>>IN multiple inheritance,We will come across "Diamond Problem".TO overcome that we
need to use "interfaces" in java.
OOPS inheritance is called as IS-A relationship.
rules:
1)Constructors are not inherited.
2)We cannt inherit private members.
3)Java doent support Multiple inheritance directly.
4)Static variable are not inherited.
>try
{
}
catch()
{
}
finally
{
}
try--catch--finally
try--finally
try---catch
>If we know that code might throw the exact exception,ten never use Excception
object in catch block.
String a = "Srini";
Integer.parseInt(a);-----NumberFormatException
how do JVM recognize which exception was throwed from which class,method,lineno?
Use throws if you dont want to handle exception manually thru try and catch.
finally
{
}
>>If a variable can hold only single value ,then it is called as Scalar type.
Arrays.copy
Arrays cannot grow., because if size is fixed.We cannt add diffrent trypes of
value.
Advanatges
--------------
>collectionsara similar like array but it can grow and shrink.
>In collections we can store diffrent types of values.
>java provides diffrent collection interfaces.
List--ArrayList and Vector
Map
Set
Req:
I want to store multiple values with no limit.while inserting it shld allows even
duplicates.
wherever u see any colletion with tree,that indicates will display elements in
ascending order and null is not allowed.
>>>Clone might throw and exception.So,based the logic which we are writing,some
time we need to surrender the code with try-catch.
Hashtable:
===========
>doesnt allow null key or value.
>default initial capacity (11) and load factor (0.75).
>It is thread safe.
HashMap:
=========
>>>default initial capacity (11) and load factor (0.75).
>It is not thread safe.
>allows null values.
>>can have only 1 null key and 1 null value.
ComputeIFpresent/absent-----Java8 lambda ,Functional interfaces and Stream API
TreeMap:
=========
>>maintains ascending order.
>It is not thread safe.
>no null keys and values.If inserted it will throw NULLPOINTER Exception.
>>Treemap uses Navigablemap for sorting the elements in collections.So try to avoid
null in collections.
>In treemap,always makesure all keys are of similar types.Otherwise
it will lead to ClassCastException.
Note: As null leads to more issues in projects,it may lead to app crash also.To get
ride of these problems,Oracle had released "Optional" feature in java8.
Optional class will check whether object is empty or not.
Indian Army---->Dbase2---->Dbase3---->Access
Java Program------------------------------->Database
directly?No
disadvantage:
We need to install native driver in each machine.
--->
Large Object datatypes:
DELIMITER &&
>>CREATE or replace PROCEDURE myprocedure()
BEGIN
SELECT * FROM employee WHERE empid=101;
END &&
>>In the above example procedure is just returning single string not a resultset,so
it is execute method returns false.
======================================
MultiThreading
---------------
>>Multithreading means ability to perform multiple jobs/tasks at a time
simultaneously.
>Job means a task that we need to complete.
>Parents they perfom multitasking.
O/s----Parent Process
JVM---Child Process
Programs that we are run are ---Threads
>>To create a Thread ,first we need to have process.
Without process,we cannt create Thread.
>Threads uses the memory of Process.
Parent---->Process
Child------>Thread
>Java supports only multithreading but not multiprocessing.
>If you want to work on multiprocessing,we can go with Python.
Thread.sleep:
===============
>>if we want to hault the threadfor some given time then sleep is used.
>if the time is completed then it will continue from where it left.
Thread.sleep(long mls)
>if one thread completes then only another thread shld start?
ans) LOcking mechanism
mutex
semaphores
notify(): The notify() method wakes up one of the waiting threads on the same
object. If multiple threads are waiting, it is not specified which one will be
awakened. The awakened thread will then compete for the lock on the object.
---------------
The general syntax of using the wait() method for synchronization is shown below.
synchronized(object)
{
while(condition is false)
{
object.wait();
when we deal with os threds and server threads we will use daemon threads.
Transaction?
int a= 1;
a++;
Shared variable/resource:if multiple threads are trying to access same variable and
trying to perform some operations,then that resource is called shared resource.
Synchronized blocks.
====================
Syntax:
Synchronize(resourcename){
}
The above issues that we stated above can be handled via ld Synchronize block.
>Synchronize shld be used as combination with wait and notify.
>Synchronize block make sure only one thread is accessing the resoiurce at same
time.If another thread tries to modify then it will not allow because Synchronize
block will have a lock mechanism.
ATM
5 Threads---tx
t1 t2 t3 t4 t5
t1 after the operation he will notify t2.
t2 after the tx ,he will notify t3.
if t1 is doing tx,then t2t3t4t5 shld be in waitiing state.
Rules:
@FunctionalInterface //annotation
interface SamExample1 {
void display();
}
When we work on Big data,we need to work on structured and unstructured data.Some
time we need to perform some computations.
drawback: No readability
For small operations dont use lambda.
56 new features
Advanced java or Microservices
==================================================================
Spring
========
prereq:
===========
Java: jdk1.8
Eclipse for Spring
Springboot: Jdk1.8,Eclipse/Spring STS
Apache Maven/Gradle is mandetory
>mainly developer shld know what is configuration files?
Maven:
=======
Before Maven there is a tool called as "ANT"
ANT>>>>MAven>>>>>Gradle(faster)
>>Gradle is new to market.Already majority companys are using maven from last 8
years.
>>Gradle internallyy uses maven repo.
>Maven is a build tool.
>in maven dependency means a jar file.
Advantages:
1)we can build the project.
2)It can handle dependencies.
3)Handle transtive dependencies.
4)we can perform packaging of project into jar/ear/war.
5)Can install plugins that are required for Project.
......etc
Any 3rd party dependencies that are needed for the project can be handled by
MAVEN.Maven after reading pom.xml files,it will start downloding the dependencies
from internet.
>>Maven first checks local repository before downloading the dependency from
internet.Assume dependency is not available in local repo,then it will download
dependencies from public repo.
Local repo: repo that was created and available in our PC.
local repo name is ".m2".
Public repo: repo that is on cloud for public use.Anybody can access public repos.
Corporate repo: repo that were created for an organization for development ;for
internal use is called as Corporate repo.
>To create a corporate we need to use below tool.
Jfrog artifactory,Sonatype Nexus
>>Always corporate repo are more secure.
----i/p---->Maven
pom.xml
>When we run the maven project,maven wwill first read pom.xml file.
>we shld have only 1 pom.xml file per a normal project.
>Only in the case of Multi-module projects we can have multiple pom.xml
files.
>Multi-module projects are used only for Microservices Development.
>>
settings.xml file is used for entire workspace.
Pom.xml file used for Project.
worskpace--30 project----30
In setting.xml we are going to configure below
1)Local repo path
2)Proxy server details.
3)Corporate repo data.these are more secure.
4)profiling will also be handled
5)Plugin management
>Corporate repo will be created by Devops team.
>>Who will create .m2?
ans)Maven
Transitive dependencies:
======================== means whenever parent dependencies are loaded then child
dependencies shld be loaded,if not loaded project build will fail.
>MAven will take necessary care to get of child dependency issues in maven.
>Maven can also create a project from scracth.this feature is called as
SCAFFOLDING.
>Some time maven settings are good,and pom.xml is free from errors.
But still i am getting errors?
sol)do force update
===============================================
Spring:
https://spring.io/
>>Spring is an application framework and IOC container for Java.
>Spring is a group of projects or modules.
>Out of these modules to design any app using Spring,we shld be clear in
fundamentals of "Dependency injection" basics.
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Spring is mainy used to reduce tight coupling between the classes or code.
Spring 3.x,5.x,6.x
>>Spring MVC
-------------
>>MVC--model view controller
>>Spring mVC is used for designing web apps.
>>JSP andn servlets are server side technologies to design webapps.
In MVC we are having 2 types of architectures.
MVC1---JSP acts as controller
MVC2---Servlet will acta as controller
>As soon as we run any spring MVC app,it will automatically load/run startup file
which is index.jsp.
The Controller takes the request, calls the appropriate method, and builds the
model and returns the view page name to the DispatcherServlet.
The DispatcherServlet will then take help from the ViewResolver to pick up the
defined view page for the request.
Once the view is finalized, the DispatcherServlet passes the model data to the
view, which is finally rendered on the browser.
Hpw do IOC knows the location of contrroller ie which package and its address?
sol) thru component-scanning
Component-scanning will scann the entire code and will identify controllers.
>>
Component Scanning
Annotation
5 to6 years back ago,we need to write huge xml files for sharing meta data with
server or JVM.
To overcome these problems,Oracle had released Annotations into the market.
SpringMVC
==========================
Spring AOP and validations
------>
Springboot
==========
>>IDE: Spring STS---heavy weight than eclipse
Eclipse--lightweight when we compare with STS
>>Spring STS--4.x--3.x---wont support 8.x version.
Theia IDE
>>>https://spring.io/quickstart
Drawbacks of Spring:
==================
1)One of the Common Maven problem is Dispatcher servlet not found issue.--can be
overcomed using Autoconfig feature in springboot
2)Writing more config files.---very less config files
3)we need to configure server ie tomcat.---Embedded/inbuilt server
4)If we use spring for deisgning Cloud and Microservices app,code size will
drastically increase.---less no of lines of code
5)writing huge xml files.---no xml file except pom.xml
6)Profling is a manually approach.---using @Profile we can complete
7)Learning curve is very high.----less learning
8)No developer tools like autorestart/reload----Springboot has inbuilt tools
----------
Springboot 3.x version
>>TO design springboot app,we can go with the below ways.
1)Springboot CLI
2)Spring STS/Eclipse
3)MAven/Gradle
4)Using Spring initializer.https://start.spring.io/
application.properties or application.yaml
com.hughes
.hughes.controller
Port rule:
Suggested is 8
Get----@GetMApping
put----@PutMApping
Post---@PostMapping
delete---@DeleteMapping
or
@RequestMapping
@Controller
@SpringBootApplication
>>>>>
Observations:
web.xml is not created
spring-servlet.xml--not created
we just added springstarter web dependency.
We didnt added spring core and spring web separetly.
>>Why wee added jasper separetly in pom.xml?
to run servlet we need Catalina jar
to run jsp programs we need Jasper jar.
>>Here tomcat is inbuilt.We dint configured anything for tomcat.
Note:tomcat is embedded.
what if i want weblogic server in my springboot?Is it inbuilt?
ans)No.weblogic not inbuilt.
Only tomcat,jetty,netty,undertow
Also commercial servers are not inbuilt in springboot.
...Example: Pramathi server...
=====================================================
@SpringBootApplication:
-----------------------
How do springboot recognize your controller/Service/Repository? it will scan the
entire project,component:scan
How spring spring is config dispatcher servlet?
who loaded beans into IOC container?
In Spring,@Controller,@Service,@Repository,@Component are called as Stereotype
annotations/types.
>>We didnt configured dispatcher servlet in any file in springboot.In the case of
springboot beacuse of "AutoConfiguration" feature,based on the starter it will
recognize the type of dependency and will perfrom necssary actions with developer
involvement.
DAO: DAO stands for data access Object.A DAO class is a class with only CRUD
operations.
>DAO is also a design pattern.
redis server---->Spring-boot-starter-redis
mongo----Spring-boot-starter-mongo`
>>Commandline runner:
=======================
SpringApplication.run===command line runner.
The main use of the above command is
1)it will start the Application
2)Initializes and configures beans,properties and app context.
3)Commandline runner methods will be executed.
4)After 1,2,3 steps the app will start working.
---------------------------------------------------------
6-MArch-2024
SpringBoot AOP
Spring Security
Unit testing in Spring
mappings in springboot
=========================
SpringBoot JDBC
WebServices Introduction
Springboot Restfull services
Connection Pooling and Datasources
JPA Introduction and Sample App
------------------------>>>
Springboot Layered Architecture+JDBC(connection pooling)
Spring JDBC vs SpringBoot JDBC:
1)In spring JDbc we need to write more xml files and config files,but in springboot
jdbc no xml files.
2)in spring jdbc we need to add multiple dependencies,but in springbootjdbc,we need
to add only one starter Spring-boot-starter-jdbc.
We are opening the connection and we are closing connection in jdbc.but if we go
with Spring boot/spring jdbc,no need to close connection manually.There is
autoclosing feature.
>>It can exceptions automatically.
>>Springboot JDBC uses "Connection pooling mechanism",but normal jdbc wont use the
same.
>>springboot jdbc is built on JDBC.
If we want to perform CRUD operations on Db using Spring boot,below are the ways.
1)Springboot JDbc
2)Springboot + ORM
3)Springboot + Hibernate
4)AOP
Shubham: Bhuvaneswar----Vizg
Thru car?
is there any rule that shubham shld purchasee new car to go to vizag
or will he hire a car
rent:u will get a car on hourly basic---rent
car---db object
car garrage/car agency------database
After his travel he will handover car to that car agency--amount
Note:Connection pooling feature will be dependent on the type of database that you
were using.
Case 2: if requester is not using the db object for some time,that db object will
be automatically handed back to db.
srinivas is loosing.srinivas got suggestion from Rahul.y dont u give to ola or uber
for rent.so that u can generate money.
In connection Pool ,we are going to have pool of readymade db objects.
how many db objects?
ans)it depends on available memory on server,Database and Processor
Connection pool mechanism can be achieved using below 3rd party library.
1)DBCP
2)C3PO
3)Hikari connection Pooling---market
leader(https://github.com/brettwooldridge/HikariCP)
4)Server side connection pooling---Webserver/App server
CommandlineRunner :
======================
>Commandlinerunner is an interface in spring boot.
>It has only one abstract method "run".
>When a class implements this interface,springboot will automatically call run
method.
>>This interface is used for db initlialization at starting of the app,or if u want
to perform startup activities then we are going to use this.
>>This commandline runner will run ur code after springbootbeans intilializing and
loading is completed.
SpringBoot rest+Reactjs
reactjs/Angular---consumer
Producer----Springboot rest
SOAP---SOapUI tool for consuming
>>A consumer can be an app,webservice,browser.
3rd party agents: postman/rest IDE
@Controller-----MVC
Springboot rest----
@RestController-----Restfull services
@RequestMapping
@Post---@PostMapping
@Get----@GetMApping
@delete---@DeleteMapping
>>Springboot gives one inbuilt database called as h2.
h2 shld be used for training and POC purpose.Dont use this production
environements.
mem--datasource name/inmemory
jdbc:h2:mem:training
>>>>>>>>>>>JPA----Java Persistance API
Springboot+JDBC
Springboot+ JPA
@RequestBody
@ResponseBody
anything that we get from server is called as response.
JPA repository
>>JPA advantages
Vendors---Hibernate is implementor of JPA
ORM---object relation Mapping
>>>Springboot JDBC
aadhar no
citizen name
citizen mobileno
Addresss
Income
State
CRUD Operations
==========================================================
try {
connection = DriverManager.getConnection(jdbcURL, username, password);
connection.close();
====================
Springboot development tools:
=============================
n>LiveReload-- to use live reload on browser we need to install live relaod plugin
on browser.
Drawback with live reload: Browser wil crash most frequently.
https://chromewebstore.google.com/detail/livereload/
jnihajbhpnppcggbcgedagnkighmdlei?pli=1
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
to springboot Projects pom.xml file.
>>Remote debugging
>Remote Update or restart
===========================================
Testing:
-----------------
Junit+Mockito
Versions: Junit4 and Junit5
>>>I want to test a functionality whether the function is executing with in 1000ms.
>>how do test whether dbconnection is established with in lesstime in jdbc?
>>If we want to make junti to ignore a particular test case from running,simply use
@Ignore.
SpringBoot Security:
==============================
Springboot starter security---add in pom.xml.
>security features in Spring boot will be enabled for ur app.
Springboot gives so many features for security using less no of lines of code.
1)As soon as we add security dependecny springboot will perform autoconfiguration
and will enable security.
2)
features:1)filters---Antisamy filters,OWASP filters
2)Oauth1.0
3)Oauth2.0-mostly used
4)LDAP
5)SAML
6)JSON token---mostly used
7)Kerberos
8)in-memory login credentials
Example:
mod1
mod2
mod3
mod4
mod5
Customter asked u to insert logging at mod3.