JAVA LECTURES NOTE
JAVA LECTURES NOTE
JAVA LECTURES NOTE
Java is one of the most widely used programming languages in the world,
known for its portability, scalability, and ease of use. Understanding its
architecture is crucial for effectively developing and running Java applications.
The Java architecture comprises three primary components: the Java
Development Kit (JDK), the Java Runtime Environment (JRE), and the Java
Virtual Machine (JVM). Each plays a distinct role in the lifecycle of a Java
application.
The Java Development Kit (JDK) is a software development kit used to develop
Java applications. It provides the necessary tools and libraries to compile,
debug, and execute Java programs. The JDK includes:
Compiler (javac): The compiler converts Java source code ( .java files)
into bytecode (.class files). Bytecode is a platform-independent code that
can be executed by the JVM.
Java Runtime Environment (JRE): Included within the JDK, the JRE
provides the libraries and the JVM required to run Java applications. While
the JRE is essential for executing Java programs, it does not include
development tools.
Development Tools: The JDK provides additional tools such
as javadoc for generating documentation, javap for disassembling class
files, and jar for packaging Java applications into JAR (Java ARchive) files.
Debugger (jdb): This tool helps developers diagnose and fix issues in
their Java code by allowing them to set breakpoints, inspect variables,
and control execution flow.
In essence, the JDK is intended for developers who need to create and test Java
applications.
The Java Virtual Machine (JVM) is a crucial component of the Java architecture.
It provides a platform-independent execution environment for Java bytecode.
The key functions of the JVM include:
Bytecode Execution: The JVM reads and executes Java bytecode, which
is a portable, intermediate representation of Java source code. This
allows Java applications to run on any device or operating system that
has a compatible JVM.
Memory Management: The JVM handles memory allocation and
garbage collection. It manages the heap (where objects are allocated)
and the stack (where method calls and local variables are stored).
Just-In-Time (JIT) Compilation: To improve performance, the JVM
employs JIT compilation, which compiles bytecode into native machine
code at runtime. This can lead to significant performance improvements
over interpretation alone.
Class Loading: The JVM dynamically loads classes as needed. It uses
class loaders to find and load class files into memory.
Exception Handling: The JVM manages exceptions and errors during
runtime. It provides mechanisms for throwing, catching, and handling
exceptions, ensuring that Java programs can recover from unexpected
conditions.
An object consists of :
1. State: It is represented by attributes of an object. It also reflects the
properties of an object.
2. Behavior: It is represented by methods of an object. It also reflects the
response of an object with other objects.
3. Identity: It gives a unique name to an object and enables one object to
interact with other objects.
Topics to discuss :
1. Static keyword in Java (https://www.geeksforgeeks.org/static-keyword-
java/)
2. Final keyword in Java (https://www.geeksforgeeks.org/final-keyword-in-
java/)
Access Modifier : Defines access type of the method i.e. from where it can be
accessed in your application. In Java, there 4 type of the access specifiers.
Pillar 1: Abstraction
Data Abstraction is the property by virtue of which only the essential details
are displayed to the user. The trivial or the non-essentials units are not
displayed to the user. Ex: A car is viewed as a car rather than its individual
components.
Pillar 2: Encapsulation
Pillar 3: Inheritence
Pillar 4: Polymorphism
The word polymorphism means having many forms. In simple words, we can
define polymorphism as the ability of a message to be displayed in more than
one form.
Types of polymorphism :
ABSTRACT CLASS :
A class that is declared with the abstract keyword is known as an abstract class
in Java. It can have abstract and non-abstract methods (method with the body).
// An abstract function
abstract void draw();
}
Challenge 1 : Can we have a function in the abstract class with a body ?
References :
https://www.geeksforgeeks.org/abstract-classes-in-java/
INTERFACE :
The interface in Java is a mechanism to achieve abstraction. There can be only
abstract methods in the Java interface, not the method body. It is used to
achieve abstraction and multiple inheritance in Java. In other words, you can
say that interfaces can have abstract methods and variables. It cannot have a
method body. Java Interface also represents the IS-A relationship . That means
all the methods in an interface are declared with an empty body and are public
and abstract and all fields are public, static, and final by default. A class that
implements an interface must implement all the methods declared in the
interface.
// A simple interface
interface Player
{
final int id = 10;
int move();
}
Challenge 1 : Can we have a function in the interface with a body ? ( HINT :
default function)
HINT : If two interfaces have same name default method , we need to override
that method in our implementation class . Its a rule .
We override the default function in the class and inside its body use the
<interfaceName>.super.<methodName>()
HINT : <InterfaceName>.super.<functionName>(x,y)
(i) public
(ii) private
References :
https://www.geeksforgeeks.org/interfaces-in-java/
https://www.geeksforgeeks.org/static-method-in-interface-in-java/
https://www.geeksforgeeks.org/default-methods-java/
HINT : https://www.geeksforgeeks.org/difference-between-abstract-class-and-
interface-in-java/
References :
https://www.geeksforgeeks.org/nested-classes-java/
https://www.geeksforgeeks.org/anonymous-inner-class-java/
https://stackoverflow.com/questions/2515477/why-is-there-no-multiple-
inheritance-in-java-but-implementing-multiple-interfac
https://www.geeksforgeeks.org/java-and-multiple-inheritance/
Exceptions in Java
Exception Handling in Java is one of the effective means to handle the runtime
errors so that the regular flow of the application can be preserved. Java
Exception Handling is a mechanism to handle runtime errors such as
ClassNotFoundException, IOException, SQLException, RemoteException, etc.
What is an Exception?
What is an Error?
Errors are usually beyond the control of the programmer and we should not try
to handle errors.
Error vs Exception
1. Built-in Exceptions
o Checked Exception
o Unchecked Exception
2. User-Defined Exceptions
Points to discuss :
Need of try-catch clause(Customized Exception
Handling) https://ide.geeksforgeeks.org/wWRSZ6gZVj
throw, throws https://www.geeksforgeeks.org/throw-throws-java/
finally https://www.geeksforgeeks.org/g-fact-24-finalfinally-and-finalize-
in-java/
Challenge 1 : We have a Person class . Our task is to make sure that when
we create objects of Person class , constructor gets called only once, i.e. all
objects have the same hashcode .
Challenge 3 : Why does the newly created getPerson function in Person needs
to be static ?
References :
https://www.geeksforgeeks.org/singleton-design-pattern-introduction/
https://www.geeksforgeeks.org/singleton-design-pattern/
https://www.geeksforgeeks.org/java-singleton-design-pattern-practices-
examples/
FUNCTIONAL INTERFACE :
References :
https://www.geeksforgeeks.org/functional-interfaces-java/
https://stackoverflow.com/questions/50892117/why-to-use-
functionalinterface-annotation-in-java-8
https://piyush5807.medium.com/functional-interfaces-in-a-nutshell-for-
java-developers-54268e25324
GENERICS :
Generics means parameterized types. The idea is to allow type (Integer, String,
… etc., and user-defined types) to be a parameter to methods, classes, and
interfaces. Using Generics, it is possible to create classes that work with
different data types. An entity such as class, interface, or method that operates
on a parameterized type is a generic entity.
Now when we create the lambda for this functional interface , we will also need
to accommodate the generic types we want . Below are 2 examples of how we
can use the same Interface with different lambdas because our input type and
output type data types are generics .
References :
https://www.geeksforgeeks.org/generics-in-java
STREAMS :
Intermediate Operations:
Challenge 1 : Given a list of city names .We have to find out which cities start
with a vowvel and return a list with cities which start with vowels and are in
uppercase .
Challenge 2 : You have a list of integers, you need to find the sum of squares
of even numbers [1, 2, 3, 4, 5, 6, 7, 8] = [4 + 16 + 36 + 64 = 120]
Challenge 5 : In the last scenario , what will be the result if we use identity as
null ?
(i)ascending order (ii)descending order (iii) Increasing order of String length (iv)
decreasing order of String length
HINT : https://stackoverflow.com/questions/64974871/what-is-the-difference-
between-intstream-and-streaminteger
https://www.youtube.com/watch?v=F73kB4XZQ4I
https://www.youtube.com/watch?v=1OpAgZvYXLQ
References :
https://piyush5807.medium.com/declarative-programming-in-java-using-
streams-and-lambdas-3f71edcd7a74 IMP
https://stackify.com/streams-guide-java-8/
https://www.geeksforgeeks.org/stream-in-java/
https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html
https://www.geeksforgeeks.org/parallel-vs-sequential-stream-in-java/
https://www.geeksforgeeks.org/streams-arrays-java-8/
Lecture 5: Multithreading
Contents
MULTITHREADING:
HINT: default thread initialised by JVM on running main function . This is the
thread in which all of your code runs .
HINT : Thread.currentThread().getName()
HINT : currentThread() inside Thread class gets its definition from Hardware OS
library .
HINT :
System.out.println(Runtime.getRuntime().availableProcessors());
System.out.println(“Total memory available to JVM ”+
Runtime.getRuntime().totalMemory()
System.out.println(“Total bytes of memory used by JVM :
“+Runtime.getRuntime().totalMemory() -
Runtime.getRuntime().freeMemory());
Challenge 7 : In Thread class definition , why is start0 a private function and
start a public function ?
Challenge 9 : Create 2 custom threads and using debugger lets check which
spawns faster .
Challenge 10 : https://ide.geeksforgeeks.org/NY98CbN0vk
Challenge 11 : Can the same thread object call start() twice ? HINT :
IllegalThreadStateException . We can check this by putting debug points and
observing the threadstatus property .If thread status is not 0 , this means
thread has already started so it throws the exception simply .
Challenge 13 : You are given an array of integers and you need to calculate
the factorial of all these .
HINT : Before terminal operation ( findFirst here ) , the numbers in the stream
get ordered according to their position in the array which was streamed .
Challenge 15 : What is the issue with the below Multithreaded solution for the
above challenge ?
Challenge 16 : The correct solution has used thread.join() . Does this makes
our solution to be parallel or is it still multithreading and the thread.join() call is
not blocking ?
HINT : When we are waiting for a thread to die , are we stopping the processing
for the other threads? Execution cant go ahead until the thread on which join is
called dies , but are we stopping other threads processing ? ( think about it )
Thread.join is waiting for a thread to die while other threads are also
processing . It's just other threads can't proceed ahead in execution of code
until that thread is alive . This is 50% faster than sequential .
HINT 2 : Please have a look at the debug Thread trace with debug point at
thread.join() in this
image
: https://drive.google.com/file/d/19bWesFSJha8aEyOeS93IrfLvDpomr8uK/view?
usp=sharing
HINT : Find the first even number in an array of one million items .
HINT : https://www.geeksforgeeks.org/difference-between-process-and-thread/
HINT : https://www.geeksforgeeks.org/difference-between-daemon-threads-
and-user-threads-in-java/?ref=rp
https://www.geeksforgeeks.org/print-even-and-odd-numbers-in-increasing-
order-using-two-threads-in-java/?ref=rp
https://www.geeksforgeeks.org/difference-between-concurrency-and-
parallelism/
Challenge 22 : What is the volatile keyword in Java ?
References :
https://www.geeksforgeeks.org/multithreading-in-java/
https://www.geeksforgeeks.org/lifecycle-and-states-of-a-thread-in-java/ I
MP
https://www.geeksforgeeks.org/difference-between-thread-start-and-
thread-run-in-java/ IMP
https://stackoverflow.com/questions/8052522/why-we-call-thread-start-
method-which-in-turns-calls-run-method#:~:text=It's%20due%20to
%20the%20design,not%20start%20a%20new%20Thread.
https://www.geeksforgeeks.org/joining-threads-in-java/ IMP
https://www.geeksforgeeks.org/java-lang-threadgroup-class-java/
https://www.geeksforgeeks.org/biginteger-class-in-java/
https://www.geeksforgeeks.org/biginteger-intvalue-method-in-java/
https://www.interviewbit.com/multithreading-interview-questions/#is-it-
possible-that-each-thread-can-have-its-stack-in-multithreaded-
programming
https://www.baeldung.com/java-concurrency-interview-questions
https://www.journaldev.com/1162/java-multithreading-concurrency-
interview-questions-answers
https://pediaa.com/what-is-the-difference-between-serial-and-parallel-
processing-in-computer-architecture/ IMP
https://www.baeldung.com/java-volatile
Lecture 6: Maven
Contents
In short, we can say that Maven is a tool that can be used for building and
managing any Java-based project. Maven makes the day-to-day work of Java
developers easier and generally helps with the comprehension of any Java-
based project.
https://www.geeksforgeeks.org/introduction-apache-maven-build-automation-
tool-java-projects/
HINT : Click on the execute method of statement object for its implementation .
HINT : We can download the dependency as a jar and deploy it in our project
structure .
File > ProjectStructure > Library > Add New > Java
HINT : https://maven.apache.org/guides/mini/guide-naming-conventions.html
-Lombok
Now, let's create a Person class with properties such as id, name, and age.
Then, we'll use the Lombok dependency to create a Person object to test if the
dependency works.
HINT :
Through this button , we have to load the changes and download the
dependency from central repository .
https://repo.maven.apache.org/maven2/
HINT: In your project's pom.xml, click on the artifactId of the dependency for
which you need to know the parent/child dependencies. .
HINT : https://stackoverflow.com/questions/26975818/what-is-scope-under-
dependency-in-pom-xml-for
Challenge 10 : How do you search for the mysql-connector-java dependency
in the Official Central repository?
HINT : Go to https://repo.maven.apache.org/maven2/
First search for group id and then artifact id and then the (latest) version .
MAVEN REPOSITORY
Maven Repository
By default, the Maven local repository is located in the user's home directory,
for example:
C:\Users\asingh.m2.
Challenge 1 : Lets explore the local repository in your .m2 folder of your
computer
Challenge 2 : What will happen if I delete a dependency version which my
maven project is currently using ?
HINT : It does not give an error immediately, but we will notice that the
dependency is no longer present in the 'External Libraries.' When we run the
Java class, it throws a SQL exception: 'No suitable driver found.'
validate: Validates that the project is correct and that all necessary
information is available.
compile: Compiles the source code of the project.
test: Tests the compiled source code using a suitable unit testing
framework. These tests should not require the code to be packaged or
deployed.
package: Takes the compiled code and packages it in its distributable
format, such as a JAR.
verify: Runs any checks on the results of integration tests to ensure that
quality criteria are met.
install: Installs the package into the local repository for use as a
dependency in other local projects.
deploy: Performed in the build environment, it copies the final package
to the remote repository for sharing with other developers and projects.
Maven Commands
mvn clean: Cleans the project and removes all files generated by the previous
build.
mvn validate : (intermediary phase )Validates the src folder to check if code
files are placed correctly .
mvn package: compiles , runs tests and Creates JAR or WAR file for the
project to convert it into a distributable format.
mvn install: Deploys the packaged JAR/ WAR file to the local repository.
mvn deploy: Copies the packaged JAR/ WAR file to the remote repository after
compiling, running tests and building the project.
Challenge 4 : Now if we run the maven package once again , will it again
download from the central repository or refer to the dependency in the local
repository (.m2 folder) ?
Challenge 5 : Does mvn package or mvn install also perform mvn clean ?
HINT : Generally when we run any of the above commands, we add the mvn
clean step so that the target folder generated from the previous build is
removed before running a newer build. This is how the command would look on
integrating the clean step with install phase: mvn clean install .
HINT: mvn install also installs your current project in your .m2/repository folder
so other projects can use it as an archetype or dependency. (Source:
https://stackoverflow.com/questions/16602017/how-are-mvn-clean-package-
and-mvn-clean-install-different)
(ii) Will the JAR file be created inside the target folder?
(iii) Will we get an error if we run mvn test instead of mvn compile?
HINT: Maven lifecycle phases are sequential. If you run mvn test, then mvn
validate and mvn compile will also run.
Challenge 11: What if you delete the 'Calculator' dependency from the local
repository? Then:
(i) If there is code using the 'Calci' class in the 'Business' project or the original
project's class files, will they throw a compile-time error?
HINT: Run the mvn install command for the 'Calculator' project to install it in
the local repository.
Challenge 12: If you go to your 'Calculator' project and add a new method
called 'calculatePower' inside the 'Calci' class, your task is to find 3^4 by
calling Calci.power(3, 4) inside the 'Business' Project.
(i) Will you be able to call this new function inside the 'Business' project?
(ii) If you run mvn package, will you be able to use this function inside the
'Business' project?
(iii) If you run mvn install, will you be able to use this function inside the
'Business' project?
Challenge 13: What is the difference between mvn package and mvn clean
package?
HINT: Consider the position of defining dependencies A and B in the POM. In the
case of the same dependencies, the version will be of whichever is listed first in
the POM of C. If you don't want to rely on the position in the POM, you can use
exclusions. If you want to use the version of mysql-connector-java from Project
A, you can use an exclusion tag while defining the dependency of B in the POM
of C.
HINT : In the pom.xml, add the following code after your 'dependencies' tag:
<build>
<directory>/Users/aadhar/Desktop/JBDL-master/L4_maven-basics/new</
directory>
</build>
Challenge 16 : (Homework) How can you change the path of the .m2 folder
using the pom.xml?
References :
https://www.geeksforgeeks.org/introduction-apache-maven-build-
automation-tool-java-projects/ IMP
Official Maven Documentation by Apache : https://maven.apache.org/
https://repo.maven.apache.org/maven2/ Official Maven Central
Repository
https://mvnrepository.com/ Unofficial Maven Central Resource
https://stackoverflow.com/questions/39185798/what-is-the-difference-
between-artifactid-and-groupid-in-pom-xml IMP
https://stackoverflow.com/questions/14725316/what-is-the-use-of-pom-
xml-in-maven
https://maven.apache.org/guides/introduction/introduction-to-
repositories.html
https://www.geeksforgeeks.org/maven-lifecycle-and-basic-maven-
commands/ IMP
https://maven.apache.org/guides/introduction/introduction-to-the-
lifecycle.html
https://stackoverflow.com/questions/6028534/how-to-exclude-
dependency-in-a-maven-plugin IMP Exclusions
https://maven.apache.org/guides/introduction/introduction-to-optional-and-
excludes-dependencies.html IMP Exclusions
Lecture 8: Intro to Spring Boot
Contents
Challenge 2 : When we type amazon.in in the url window of Google , does this
request hit Amazon server or Google server ?
Challenge 3 : Let's explore Google Chrome Developer Tools and inspect the
requests in the Network tab .
Challenge 4 : What is an API and why Rest api is called Idempotent while
SOAP is not ?
HINT : API is just cient b/w client and server to communicate and get a
response .
https://www.geeksforgeeks.org/application-programming-interfaces-api-and-its-
types/
HINT : https://www.bigcommerce.com/blog/what-is-an-api/#what-about-rest-
soap-apis
Challenge 6 : What is the meaning of HTTP request ? Is rest api request not
HTTP request ?
HINT : https://www.geeksforgeeks.org/differences-between-web-services-and-
web-api/
https://stackoverflow.com/questions/808421/api-vs-webservice
Now put the ip address of google.com in the url bar and press enter .
HINT : https://www.cloudzero.com/blog/horizontal-vs-vertical-scaling
HINT : https://www.geeksforgeeks.org/load-balancer-system-design-interview-
question/
HINT : response will be the same irrespective of how many times we make the
request .
References :
https://www.geeksforgeeks.org/client-server-model/
https://medium.com/@maneesha.wijesinghe1/what-happens-
when-you-type-an-url-in-the-browser-and-press-enter-
bb0aa2449c1a
https://www.geeksforgeeks.org/introduction-to-apis/
https://stackoverflow.com/questions/19336347/what-is-the-
difference-between-a-web-api-and-a-web-service
https://blog.uptrends.com/technology/the-anatomy-of-an-api-
call/
https://blog.yellowant.com/rest-api-calls-made-easy-
7e620e4d3e82
https://www.geeksforgeeks.org/proxy-server/
https://www.nginx.com/resources/glossary/reverse-proxy-vs-
load-balancer
https://www.geeksforgeeks.org/state-the-core-components-of-
an-http-response/
https://www.smashingmagazine.com/2018/01/understanding-
using-rest-api/
Spring is widely used for creating scalable applications. For web applications
Spring provides Spring MVC which is a widely used module of spring which is
used to create scalable web applications. But the main disadvantage of spring
projects is that configuration is really time-consuming and can be a bit
overwhelming for the new developers. Making the application production-ready
takes some time if you are new to the spring. Solution to this is Spring Boot.
Spring Boot is built on the top of the spring and contains all the features of
spring.
HINT : It gives you low level code that helps to start the server . An embedded
server is embedded as part of the deployable application. If we talk about Java
applications, that would be a JAR. The advantage with this is you don’t need
the server pre-installed in the deployment environment. With SpringBoot, the
default embedded server is Tomcat (built by Apache) . Other options available
are Jetty(built by Eclipse) and UnderTow(built by Redhat) .
Challenge 2 : What is the difference b/w Web server and Application server ?
HINT : For static websites we call it a web server and for dynamic websites ,we
have an application server .
https://www.geeksforgeeks.org/difference-between-web-server-and-application-
server/
Challenge 3 : What is a database server ?
HINT : Application server uses database server to persist data . App server has
code logic running and does not have much space to store all data , thus , we
need the Database server .
HINT : https://azure.microsoft.com/en-in/overview/what-is-a-virtual-machine/
Challenge 5 : Let's make our first spring boot project with maven using
start.spring.io . ( Don't add any dependencies yet )
Challenge 6 : What are the two dependencies that are added to the POM.xml
by default by start.spring.io and why ?
Challenge 8 : Now how to load our downloaded spring boot project into IntelliJ
IDE ?
Challenge 9 : Let's explore the POM of our project and check the parent POM
of each dependency by clicking on artifact id .
Challenge 10 : Let's explore the structure of our spring boot project and
External Libraries .
Challenge 11 : Run the application . Now lets see the difference between
spring-boot-starter and spring-boot-starter-web by replacing spring-boot-
starter-web from our POM.xml with spring-boot-starter . Run the application
once again after loading the changes .
HINT : Once added and changes are loaded , we can see Jetty in the External
Libraries. Run.
HINT : https://www.geeksforgeeks.org/tcp-ip-ports-and-its-applications/
Challenge 15 : What will happen if we don't exclude Tomcat and also add
Jetty as a dependency in our POM.xml . Now which port will be used and which
server will run the spring boot application ?
HINT : This is the class responsible for loading the web server into application
context .
Search for server.port by Ctrl + Shift + F and look in scope to check where the
default value 8080 is defined for it . While Spring Boot is able to override its
default values in autoconfigure jar by using application.properties .This
functionality is missing in Spring .
HINT : Jetty will run in every case . Order does not matter .
References :
https://www.geeksforgeeks.org/difference-between-spring-and-spring-
boot/ IMP
https://www.geeksforgeeks.org/introduction-to-spring-boot/ IMP
https://www.educative.io/edpresso/web-server-vs-application-server
https://www.baeldung.com/java-jar-war-packaging IMP
https://stackoverflow.com/questions/39632667/how-do-i-kill-the-process-
currently-using-a-port-on-localhost-in-windows
HINT : In terms of severity : Error > Warning > Info > Debug > Trace
Challenge 4 : If logging level is debug , what all levels of logs will be printed ?
HINT : All logging levels above and over debug in terms of severity will be
printed ie Error , Warning , Info , Debug . Trace logs will not be printed .
Challenge 5 : Which logging level will have the most number of logs ?
HINT : Trace
HINT : Cost of storing such a huge number of logs is high and memory
requirements are high .Not suitable for debugging .
HINT : We can have a separate config file ( application.properties ) file for each
environment .
Step 1 - Create the application-<env>.properties file and define the port
number and the logging level you require when the application runs in that
environment .
Step 2 - Open Edit Configuration for the project as shown below and define
which spring profile should the application run as out of all spring profiles we
https://dzone.com/articles/spring-boot-profiles-1
HINT :
HINT : This annotation is used to mark the main class of a Spring Boot
application. It encapsulates @SpringBootConfiguration,
@EnableAutoConfiguration, and @ComponentScan annotations with their
default attributes.
https://www.geeksforgeeks.org/spring-boot-annotations/
https://learnjava.co.in/the-springbootapplication-annotation-explained/
References :
https://www.geeksforgeeks.org/spring-boot-logging/
https://www.youtube.com/watch?v=lGrcZsw-hKQ
https://stackoverflow.com/questions/5817738/how-to-use-log-
levels-in-java
https://docs.spring.io/spring-boot/docs/2.1.13.RELEASE/
reference/html/boot-features-logging.html
https://dzone.com/articles/spring-boot-profiles-1 IMP
https://www.geeksforgeeks.org/http-headers/ V Good for
Request and Response Headers