0% found this document useful (0 votes)
48 views

Java

The document provides an overview of Java concepts including: Java features like object-oriented, platform independent, etc.; the basic Hello World program; inheritance types like single, multilevel, hierarchical; polymorphism through method overloading and overriding; abstraction using abstract classes and interfaces; encapsulation; methods; data types; constructors; exception handling; and common classes like String and StringBuffer. It introduces these fundamental Java topics at a high level.

Uploaded by

G K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Java

The document provides an overview of Java concepts including: Java features like object-oriented, platform independent, etc.; the basic Hello World program; inheritance types like single, multilevel, hierarchical; polymorphism through method overloading and overriding; abstraction using abstract classes and interfaces; encapsulation; methods; data types; constructors; exception handling; and common classes like String and StringBuffer. It introduces these fundamental Java topics at a high level.

Uploaded by

G K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 42

Introduction

• Why Java ?
• Java /Core Java
• Introduce the Java Opps Concepts
• Hibernate
• Spring Boot
• Mysql Database

Created By Pathan Shahruh Khan


Features of Java
• A list of the most important features of the
Java language is given below.
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic
First Java Program | Hello World
Example
• The requirement for Java Hello World Example
• For executing any Java program, the following
software or application must be properly
installed.

For executing any Java program, the following
software or application must be properly
installed.

Inheritance
• When one object acquires all the properties
and behaviors of a parent object, it is known as
inheritance. It provides code reusability. It is
used to achieve runtime polymorphism
• Type of Inheritance
• Single Inheritance
• Multilevel Inheritance
• Hierarchical Inheritance 
• Multiple Inheritance 
• Hybrid Inheritance
• Single Inheritance
• When a class inherits another class, it is known
as a single inheritance
• Multilevel Inheritance
• When there is a chain of inheritance, it is
known as multilevel inheritance
• Hierarchical Inheritance
• When two or more classes inherits a single
class, it is known as hierarchical inheritance
• multiple inheritance
• Java dose not support Multiple inheritance
• We can achieve this type of inheritance with
the help of Interface
Polymorphism
• If one task is performed in different ways, it is
known as polymorphism. For example: to
convince the customer differently, to draw
something, for example, shape, triangle,
rectangle, etc.
• In Java, we use method overloading and
method overriding to achieve polymorphism
In short we have one interface and multiple
implmentions
Abstraction
• Hiding internal details and showing functionality is known as
abstraction.
• For example phone call, we don't know the internal processing.

• In Java, we use abstract class and interface to achieve


abstraction.
Encapsulation

• Binding (or wrapping) code and data


together into a single unit are known as
encapsulation. For example, a capsule, it is
wrapped with different medicines.
• A java class is the example of
encapsulation. Java bean is the fully
encapsulated class because all the data
members are private here.
Method in Java
• A method is a block of code or
collection of statements
• or a set of code grouped together to
perform a certain task or operation.
• It is used to achieve the reusability of
code
• The most important method in Java is
the main() method
Data Types in Java
• Data types specify the different sizes and values
that can be stored in the variable. There are two
types of data types in Java:
1.Primitive data types: The primitive data types
include boolean, char, byte, short, int, long, float
and double.
2.Non-primitive data types: The non-primitive data
types include Classes, Interfaces, and Arrays.
Method Overloading in Java
• if a class has multiple methods having same name but
different in parameters, it is known as Method
Overloading.
• If we have to perform only one operation, having same
name of the methods incr
• eases the readability of the program.
• Advantage of method overloading
• Method overloading increases the readability of the
program.
Method Overriding in Java
• If subclass (child class) has the same method
as declared in the parent class, it is known
as method overriding in Java.
• In other words, If a subclass provides the
specific implementation of the method that
has been declared by one of its parent class,
it is known as method overriding.
Usage of Java Method Overriding
• Method overriding is used to provide
the specific implementation of a method
which is already provided by its
superclass.
• Method overriding is used for runtime
polymorphism
Rules for Java Method
Overriding
• The method must have the same
name as in the parent class
• The method must have the same
parameter as in the parent class.
• There must be an IS-A relationship
(inheritance)
Object class in Java
• class
• A class is a blueprint for the object.
Before we create an object, we first
need to define the class.
• Class it is logical entity
• Object
• An object is called an instance of a
class
• Object it is physical and logical entity
So, what is a class?
• A class consists of
– a collection of fields, or variables, very much
like the named fields of a struct
– all the operations (called methods) that can be
performed on those fields
– can be instantiated
• A class describes objects and operations
defined on those objects
Access Modifiers in Java
• There are two types of modifiers in
Java: access modifiers and non-access
modifiers.
1. Private: The access level of a private modifier is only within the class. It
cannot be accessed from outside the class.
2. Default: The access level of a default modifier is only within the package. It
cannot be accessed from outside the package. If you do not specify any
access level, it will be the default.
3. Protected: The access level of a protected modifier is within the package and
outside the package through child class. If you do not make the child class, it
cannot be accessed from outside the package.
4. Public: The access level of a public modifier is everywhere. It can be
accessed from within the class, outside the class, within the package and
outside the package
Java String
• In Java, string is basically an object that
represents sequence of char values. An array of
characters works same as Java String. For
example:
1.char[] ch={'j','a','v','a','t','p','o','i','n','t'};  
2.String s=new String(ch);  
3.is same as
4.String s="javatpoint";  
5.Note: Once we declared the String then we can not
change the size if we need to the change the we
must go string buffer or builder in java
Java StringBuffer Class
Java StringBuffer class is used to create mutable
(modifiable) String objects. The StringBuffer class
in Java is the same as String class except it is
mutable i.e. it can be changed.

Note: Java StringBuffer class is thread-


safe i.e. multiple threads cannot access
it simultaneously. So it is safe and will
result in an order.
Java StringBuilder Class

• Java StringBuilder class is used to


create mutable (modifiable) String.
The Java StringBuilder class is same
as StringBuffer class except that it is
non-synchronized.
Exception Handling in Java
• The Exception Handling in Java is one of the
powerful mechanism to handle the runtime errors so
that normal flow of the application can be maintained.
• In Java, an exception is an event that disrupts the
normal flow of the program. It is an object which is
thrown at runtime.
• Exception Handling is a mechanism to handle runtime
errors such as ClassNotFoundException,
IOException, SQLException, RemoteException, etc.

Types of Java Exceptions
• There are mainly two types of exceptions:
checked and unchecked. Here, an error is
considered as the unchecked exception.
According to Oracle, there are three types of
exceptions:
1.Checked Exception
2.Unchecked Exception
3.Error
1) Checked Exception
The classes which directly inherit Throwable class except
RuntimeException and Error are known as checked
exceptions e.g. IOException, SQLException etc. Checked
exceptions are checked at compile-time.
2) Unchecked Exception
The classes which inherit RuntimeException are known as
unchecked exceptions e.g. ArithmeticException,
NullPointerException, ArrayIndexOutOfBoundsException
etc. Unchecked exceptions are not checked at compile-
time, but they are checked at runtime.
3) Error
Error is irrecoverable e.g. OutOfMemoryError,
VirtualMachineError, AssertionError etc
Java Exception Keywords
There are 5 keywords which are used in handling exceptions in
Java.
try The "try" keyword is used to specify a block where
we should place exception code. The try block must
be followed by either catch or finally. It means, we
can't use try block alone.

catch The "catch" block is used to handle the exception. It


must be preceded by try block which means we
can't use catch block alone. It can be followed by
finally block later.
finally The "finally" block is used to execute the important
code of the program. It is executed whether an
exception is handled or not.
throw The "throw" keyword is used to throw an exception.

throws The "throws" keyword is used to declare


exceptions. It doesn't throw an exception. It
specifies that there may occur an exception in the
method. It is always used with method signature.
Constructors in Java
In Java, a constructor is a block of codes similar to the method. It is
called when an instance of the class is created. At the time of calling
constructor, memory for the object is allocated in the memory.
It is a special type of method which is used to initialize the object.
Every time an object is created using the new() keyword, at least one
constructor is called.
There are two types of constructors in Java: no-arg constructor, and
parameterized constructor
Rules for creating Java constructor
There are two rules defined for the constructor.
1.Constructor name must be the same as its class name

2.A Constructor must have no explicit return type

3.A Java constructor cannot be abstract, static, final, and synchronized


Interface in Java
An interface in Java is a blueprint of a class. It has static
constants and abstract methods.
The interface in Java is a mechanism to achieve abstraction.
There can be only abstract methods in the Java interface, not
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.
Hibernate Tutorial
• What Is Hibernate Framework
• Hibernate is a Java framework that simplifies the
development of Java application to interact with the
database. It is an open source, lightweight, ORM (Object
Relational Mapping) tool. Hibernate implements the
specifications of JPA (Java Persistence API) for data
persistence
• ORM Tool
• An ORM tool simplifies the data creation, data
manipulation and data access. It is a programming
technique that maps the object to the data stored in the
database
• What is JPA?
• Java Persistence API (JPA) is a Java
specification that provides certain functionality
and standard to ORM tools.
The javax.persistence package contains the JPA
classes and interfaces.

• Advantages of Hibernate Framework


• Following are the advantages of hibernate framework:
• 1) Open Source and Lightweight
• 2) Fast Performance
• 3) Database Independent Query
• 4) Automatic Table Creation
• 5) Simplifies Complex Join
Hibernate Architecture
The Hibernate architecture includes many objects
such as persistent object, session factory, transaction
factory, connection factory, session, transaction etc.

The Hibernate architecture is categorized in four


layers.
•Java application layer
•Hibernate framework layer
•Backhand api layer
•Database layer
• Define persistent classes.
• Classes whose objects are stored in a database
table are called as persistent classes.
•   What is SessionFactory?
• SessionFactory provides the instance of Session. It
is a factory of Session. It holds the data of second
level cache that is not enabled by default.
• What is Session?
• It maintains a connection between the hibernate
application and database.
• It provides methods to store, update, delete or fetch
data from the database such as persist(), update(),
delete(), load(), get() etc.
• What is the difference between session.save() and
session.persist() method?
No. save() persist()

1) returns the identifier Return nothing because its


(Serializable) of the instance. return type is void.

2) Syn: public Serializable Syn: public void


save(Object o) persist(Object o)
• How many types of association
mapping are possible in hibernate?
• There can be 4 types of association mapping in
hibernate.
1. One to One
2. One to Many
3. Many to One
4. Many to Many
5. What is HQL (Hibernate Query Language)?
• Hibernate Query Language is known as an
object-oriented query language. It is like a
structured query language (SQL).
Spring Boot
•What is Spring Boot?
•Spring Boot is a Spring module which
provides RAD (Rapid Application
Development) feature to Spring framework.
•It is used to create stand alone spring based
application that you can just run because it
needs very little spring configuration.
• What are the advantages of Spring
Boot?
• Create stand-alone Spring applications
that can be started using java -jar.
• Embed Tomcat, Jetty or Undertow
directly. You don't need to deploy WAR
files.
• It provides opinionated 'starter' POMs to
simplify your Maven configuration.
• It automatically configure Spring
whenever possible.
• What are the features of Spring
Boot?
• Web Development
• SpringApplication
• Application events and listeners
• Admin features
• How to create Spring Boot application using
Maven?
There are multiple approaches to create Spring Boot project. We
can use any of the following approach to create application.
• Spring Maven Project
• Spring Starter Project Wizard
• Spring Initializr
• Spring Boot CLI
• What are the Spring Boot Annotations?
• The @RestController is a stereotype annotation. It
adds @Controller and @ResponseBody
annotations to the class. We need to import
org.springframework.web.bind.annotation
package in our file, in order to implement it.
• What is Spring Boot dependency
management?
• Spring Boot manages dependencies and
configuration automatically. You don't need to
specify version for any of that dependencies.
• Spring Boot upgrades all dependencies
automatically when you upgrade Spring Boot.
• What are the Spring Boot Starters?

• Starters are a set of convenient dependency


descriptors which we can include in our
application.
• Spring Boot provides built-in starters which
makes development easier and rapid. For
example, if we want to get started using Spring
and JPA for database access, just include
the spring-boot-starter-data-jpa dependency in
your project.
• What is Spring Boot Actuator
• Spring Boot provides actuator to monitor and
manage our application. Actuator is a tool which
has HTTP endpoints. when application is pushed
to production, you can choose to manage and
monitor your application using HTTP endpoints.
• What is thymeleaf?
• It is a server side Java template engine for web
application. It's main goal is to bring elegant
natural templates to your web application.
• It can be integrate with Spring Framework and
ideal for HTML5 Java web applications.
• What is @RestController annotation in SB
• The @RestController is a stereotype annotation. It
adds @Controller and @ResponseBody
annotations to the class. We need to import
org.springframework.web.bind.annotation package
in our file, in order to implement it.
• What is @RequestMapping annotation in SB
The @RequestMapping annotation is used to
provide routing information. It tells to the Spring
that any HTTP request should map to the
corresponding method. We need to import
org.springframework.web.annotation package in
our file.
MySQL
•What is MySQL?
•MySQL is a multithreaded, multi-user
SQL database management system
•MySQL is an Oracle-supported
Relational Database Management System
(RDBMS) based on structured query
language.
•How to add columns in MySQL?
1.ALTER TABLE table_name     
2.    ADD COLUMN column_name column_definition [FIRST|
AFTER 
•  How to delete a table in MySQL?
• We can delete a table in MySQL using the Drop Table statement
• DROP TABLE  table_name;   
• How to add foreign keys in MySQL?
• Using the CREATE TABLE Statement
• Using the ALTER TABLE Statement

• Following is the syntax to define a foreign key using


CREATE TABLE OR ALTER TABLE statement:

[CONSTRAINT constraint_name]    
•     FOREIGN KEY [foreign_key_name] (col_name, ...) 
   
•     REFERENCES parent_tbl_name (col_name,...)  
•  How to change the table name in
MySQL?

•  MySQL provides the following syntax to rename one or


more tables in the current database:

• mysql> RENAME old_table TO new_table; 

• If we want to change more than one table name, use the


below syntax:

RENAME TABLE old_tab1 TO new_tab1,    
•              old_tab2 TO new_tab2, old_tab3 TO new_tab3;  

You might also like