You are on page 1of 31

lOMoARcPSD|21088629

java full stack internship report

COMPUTER SCIENCE ENGINEERING (Jawaharlal Nehru Technological University,


Kakinada)

Studocu is not sponsored or endorsed by any college or university


Downloaded by priya (raj3roy4@gmail.com)
lOMoARcPSD|21088629

An Internship Report
On
JAVA FULL STACK
Submitted
in partial fulfilment for the award of the degree
Of
Bachelor of Technology
in
Computer Science and Engineering
By
NAME : K LIKITHA

ROLL NO: 20F61A0928

Department of Computer Science and Engineering


SIDDHARTH INSTITUTE OF ENGINEERING & TECHNOLOGY
(AUTONOMOUS)

(Approved by AICTE & Affiliated to JNTUA, Ananthapuramu) (Accredited by


NBA for Civil, EEE, ECE, MECH and CSE, New Delhi)
(Accredited by NAAC with ‘A+’ Grade, an ISO 9001:2008 Certified Institution)
Siddharth Nagar, Narayanavanam road, Puttur-517583, A.P
2020- 2024

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

SIDDHARTH INSTITUTE OF ENGINEERING & TECHNOLOGY


(AUTONOMOUS)

(Approved by AICTE & Affiliated to JNTUA, Ananthapuramu) (Accredited by


NBA for Civil, EEE, ECE, MECH and CSE, New Delhi)
(Accredited by NAAC with ‘A+’ Grade, an ISO 9001:2008 Certified Institution)
Siddharth Nagar, Narayanavanam road, Puttur-517583, A.P

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CERTIFICATE

This is to certify that Mr./Ms. K.LIKITHA bearing Roll


No 20F61A0928 of III year B.Tech I semester in the
department of Computer Science and
Engineering(CSM) has completed his/her Internship
in the topic of JAVA FULL STACK at QSPIDERS for the
academic year 2022-23.

Date: Head of the Department

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

Contents

• Introduction to web
• Introduction to Java
• Java Language Fundamentals
• OOP implementation
• Packages
• Arrays
• Exception handling
• Working with String

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

Java Full Stack:


A full-stack developer is a person who can develop application's backend
and frontend. Java full-stack is basically a term used for a web developer that
uses Java to develop the entire technology stack is referred to as Java full stack
developer.

Introduction to Java:
• Java is a popular programming language, created in 1995.
• It is owned by Oracle, and more than 3 billion devices run Java.
• Java works on different platforms (Windows, Mac, Linux, Raspberry Pi,
etc.).
• It is easy to learn and simple to use.

• It is open source and free.

• It is secure, fast and powerful.

• Java is an object oriented language which gives a clear structure to


programs and allows code to be reused, lowering development costs.

• It is used for:

Mobile applications (specially Android apps)


Desktop applications
Web applications
Web servers and application servers
Games

Syntax:
public class Main{
public static void main(String[] args){
System.out.println(“Hello World”);
}
}

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

• Every line of code that runs in Java must be inside a class. In our example,
we named the class Main. A class should always start with an uppercase
first letter.

• Java is case-sensitive: "MyClass" and "myclass" has different meaning.

• The name of the java file must match the class name. When saving the
file, save it using the class name and add ".java" to the end of the
filename.

• Any code inside the main() method will be executed.

• Inside the main() method, we can use the println() method to print a line
of text to the screen.

IDENTIFIERS:

 Java identifiers are names given to variables, methods, classes, and


other program elements in Java programming language.

 Java identifiers must start with a letter, a currency character "$", or an


underscore "_". The first character cannot be a digit.

 Java identifiers can contain letters, digits, underscores, and currency


characters. The name can be of any length.

 Java is case-sensitive, which means that "name" and "Name" are two
different identifiers.

 Identifiers should not be a Java keyword, which are reserved words in


Java that have a specific meaning and cannot be used as an identifier.

 Examples of valid identifiers in Java are "myVariable", "_count",


"MAX_VALUE", "calculateSum", "MyClass".

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

Variables:
• Variables are containers for storing data values.

• In Java, there are different types of variables, for example:

✓ String - stores text, such as "Hello". String values are surrounded


by double quotes
✓ int - stores integers (whole numbers), without decimals, such
as 123 or -123
✓ float - stores floating point numbers, with decimals, such as 19.99
or -19.99
✓ char - stores single characters, such as 'a' or 'B'. Char values are
surrounded by single quotes
✓ boolean - stores values with two states: true or false.

• To create a variable, you must specify the type and assign it a value.

✓ Syntax: type variableName = value;

• All Java variables must be identified with unique names.


• These unique names are called identifiers.
• Identifiers can be short names (like x and y) or more descriptive
names (age, sum, totalVolume).
• The general rules for naming variables are:
✓ Names can contain letters, digits, underscores, and dollar signs
✓ Names must begin with a letter
✓ Names should start with a lowercase letter and it cannot
contain whitespace
✓ Names can also begin with $ and _ .

✓ Names are case sensitive ("myVar" and "myvar" are different


variables).

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

✓ Reserved words (like Java keywords, such as int or boolean)


cannot be used as names.

Data Types:
• Data types are divided into two groups:

✓ Primitive data types -


includes byte, short, int, long, float, double, boolean and char.

✓ Non-primitive data types - such as String, Arrays and Classes.

• Primitive number types are divided into two groups:


✓ Integer types stores whole numbers, positive or negative
(such as 123 or -456), without decimals. Valid types
are byte, short, int and long. Which type you should use, depends on the
numeric value.
✓ Floating point types represents numbers with a fractional part,
containing one or more decimals. There are two
types: float and double.
• Integer Types:
✓ The byte data type can store whole numbers from -128 to 127.
This can be used instead of int or other integer types to save
memory when you are certain that the value will be within -128
and 127.
✓ The short data type can store whole numbers from -32768 to
32767.
✓ The int data type can store whole numbers from -2147483648 to
2147483647. In general, the int data type is the preferred data type
when we create variables with a numeric value.
✓ The long data type can store whole numbers from -
9223372036854775808 to 9223372036854775807. This is
used when int is not large enough to store the value. Note that
you should end the value with an "L".
• Floating Point Types:

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629


The float and double data types can store fractional numbers. Note
that you should end the value with an "f" for floats and "d" for
doubles.
✓ A floating point number can also be a scientific number with an
"e" to indicate the power of 10.

• Type casting is when you assign a value of one primitive data type
to another type.
• In Java, there are two types of casting:
✓ Widening Casting (automatically) - converting a smaller type to
a larger type size
byte -> short -> char -> int -> long -> float -> double

Example:
int myInt = 9;
double myDouble = myInt;

✓ Narrowing Casting (manually) - converting a larger type to a


smaller size type
double -> float -> long -> int -> char -> short -> byte

Example:
double myDouble = 9.78d;
int myInt = (int) myDouble;

Operators:
• Operators are used to perform operations on variables and values.

• Java divides the operators into the following groups:

✓ Arithmetic operators
✓ Assignment operators
✓ Comparison operators
✓ Logical operators
✓ Bitwise operators

• Arithmetic Operators:
6

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

Operator Operation
+ Addition
- Subtraction
* Multiplication
/ ModDivoisio
n O er tion
%
(Remainder after division)

• Assignment Operators:
Operator Example Equivalent to

= a = b; a = b;

+= a += b; a = a + b;

-= a -= b; a = a - b;

*= a *= b; a = a * b;

/= a /= b; a = a / b;

%= a %= b; a = a % b;

• Relational Operators:
Operator Description Example

3 == 5 returns
== Is Equal To
false

3 != 5 returns
!= Not Equal To
true

3 > 5 returns
> Greater Than
false

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

3 < 5 returns
< Less Than
true

3 >= 5 returns
false

3 <= 5 returns
true

• Logical Operators:
Operator Example

Meaning
expr t
&&
r
(Logi essio u
cal&
e
& n1
AND
o
) expr n
l
|| (Logical OR) essio y

n2 i
f

expression1
b
expr
o
essio
n2 t
h

e
x
p
r
e
s
s
i
o
Downloaded by priya (raj3roy4@gmail.com)
lOMoARcPSD|21088629

n u o true if
1 e n expression
1 is
a t false and
n r vice versa
o
d u
r
e
e e
x i
x
p f
p
r r
e e
e
s i
s
s t
s
i h
i
o e
o
n r
n
2 2
e
a x
i
r p
s
e r
e
t
t s
r
r s
u
i
e
! expressio
(L n
og NOT)

ic
al

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

thout using
it

• Unary Operators:
Greater Than or Equal To - Unary minus: inverts the sign
>=
Operator Less
Meaning
Than or Equal To of an
<=
Unary
plus: not ++ Increment operator:
necessary increments
to use
+

s 8
i
n
c
e

n
u
m
b
e
r
s

a
r
e

p
o
s
i
t
i
v
e

w
i
Downloaded by priya (raj3roy4@gmail.com)
lOMoARcPSD|21088629

-- Decrement operator: decrements

! Logical complement operator: t

Conditional Statements:
• Java has the following conditional statements:

✓ Use if to specify a block of code to be executed, if a specified


condition is true.

Syntax:
if (condition) {
// block of code to be executed if the condition is true
}

✓ Use else to specify a block of code to be executed, if the same


condition is false.

Syntax:
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}

✓ Use else if to specify a new condition to test, if the first condition


is false.

if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and
condition2 is true
} else {
// block of code to be executed if the condition1 is false and
condition2 is false

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

}
✓ Use switch to specify many alternative blocks of code to be
executed.

Syntax:
switch(expression) { case
x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
✓ The switch expression is evaluated once.

✓ The value of the expression is compared with the values of


each case.

✓ If there is a match, the associated block of code is executed.

✓ The break and default keywords are optional.

Loops:
• Loops can execute a block of code as long as a specified condition is
reached.
• Loops are handy because they save time, reduce errors, and they make
code more readable.
While Loop:
The while loop loops through a block of code as long as a specified condition
is true.
Syntax:
while (condition) {
// code block to be executed
}
Do/While Loop:

10

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

The do/while loop is a variant of the while loop. This loop will execute the
code block once, before checking if the condition is true, then it will repeat the
loop as long as the condition is true.
Syntax:
do {
// code block to be executed
}
while (condition);
For Loop:
When you know exactly how many times you want to loop through a block
of code, use the for loop instead of a while loop.
Syntax:
for (statement 1; statement 2; statement 3)
{ // code block to be executed
}
✓ Statement 1 is executed (one time) before the execution of the code
block.
✓ Statement 2 defines the condition for executing the code block.
✓ Statement 3 is executed (every time) after the code block has been
executed.
Arrays:
• Arrays are used to store multiple values in a single variable, instead of
declaring separate variables for each value.
• To declare an array, define the variable type with square brackets:
Example: String[]
cars;
• You can access an array element by referring to the index number.
• This statement accesses the value of the first element in cars:
Example:
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};

// Outputs Volvo
Multidimensional Arrays:
• A multidimensional array is an array of arrays.
• Multidimensional arrays are useful when you want to store data as a
tabular form, like a table with rows and columns.

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

• To create a two-dimensional array, add each array within its own set
of curly braces.
Example:
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
System.out.println(myNumbers[1][2]); // Outputs
7

Methods:
• A method is a block of code which only runs when it is called.
• You can pass data, known as parameters, into a method.
• Methods are used to perform certain actions, and they are also known
as functions.
• Why use methods? To reuse code: define the code once, and use it
many times.
• A method must be declared within a class. It is defined with the name of
the method, followed by parentheses ( ).
Example:
public class Main {
static void myMethod() {
// code to be executed
}}
✓ myMethod() is the name of the method.

✓ static means that the method belongs to the Main class and not an
object of the Main class. You will learn more about objects and how
to access methods through objects.
✓ void means that this method does not have a return value.

• To call a method in Java, write the method's name followed by two


parentheses () and a semicolon;

• Information can be passed to methods as parameter. Parameters act as


variables inside the method.
• Parameters are specified after the method name, inside the
parentheses. You can add as many parameters as you want, just
separate them with a comma.

12

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

• The following example has a method that takes a String called fname as
parameter. When the method is called, we pass along a first name,
which is used inside the method to print the full name:
public class Main {
static void myMethod(String fname) {
System.out.println(fname + " Refsnes");
}

public static void main(String[] args) {


myMethod("Liam");
myMethod("Jenny");
myMethod("Anja");
}
}
Return Values:
The void keyword, used in the examples above, indicates that the
method should not return a value. If you want the method to return a value,
you can use a primitive data type (such as int, char, etc.) instead of void, and
use the return keyword inside the method:
public class Main {
static int myMethod(int x) {
return 5 + x;
}
public static void main(String[] args) {
System.out.println(myMethod(3));
}
}

Java OOP(Object Oriented Programing):


• OOP stands for Object-Oriented Programming.
• Procedural programming is about writing procedures or methods that
perform operations on the data, while object-oriented programming is
about creating objects that contain both data and methods.

• Object-oriented programming has several advantages over procedural


programming:

13

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

✓ OOP is faster and easier to execute.

✓ OOP provides a clear structure for the programs.

✓ OOP helps to keep the Java code DRY "Don't Repeat Yourself",
and makes the code easier to maintain, modify and debug.

✓ OOP makes it possible to create full reusable applications


with less code and shorter development time
Object:
Any entity that has state and behavior is known as an object. For example, a
chair, pen, table, keyboard, bike, etc. It can be physical or logical.
An Object can be defined as an instance of a class. An object contains an address
and takes up some space in memory. Objects can communicate without knowing
the details of each other's data or code. The only necessary thing is the type of
message accepted and the type of response returned by the objects. Example: A
dog is an object because it has states like color, name, breed, etc. as well as
behaviors like wagging the tail, barking, eating, etc.
Class:
Collection of objects is called class. It is a logical entity.
A class can also be defined as a blueprint from which you can create an individual
object. Class doesn't consume any space. 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.
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.
Another example can be to speak something; for example, a cat speaks meow,
dog barks woof, etc.

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

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.
Inheritance in Java:
Inheritance in Java is a mechanism in which one object acquires all the
properties and behaviors of a parent object. It is an important part of OOPs
(Object Oriented programming system).
The idea behind inheritance in Java is that you can create new classes that are
built upon existing classes. When you inherit from an existing class, you can
reuse methods and fields of the parent class. Moreover, you can add new
methods and fields in your current class also.
Inheritance represents the IS-A relationship which is also known as a parent-
child relationship.
• Class: A class is a group of objects which have common properties. It is a
template or blueprint from which objects are created.

• Sub Class/Child Class: Subclass is a class which inherits the other


class. It is also called a derived class, extended class, or child class.

• Super Class/Parent Class: Superclass is the class from where a subclass


inherits the features. It is also called a base class or a parent class.

• Reusability: As the name specifies, reusability is a mechanism which


facilitates you to reuse the fields and methods of the existing class when
you create a new class. You can use the same fields and methods already
defined in the previous class.
Syntax:
class Subclass-name extends Superclass-name
{
//methods and fields
}

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

Types of Inheritance:
• Single Inheritance
• Multiple Inheritance
• Multi-Level Inheritance
• Hierarchical Inheritance
• Hybrid Inheritance

Abstraction in Java
Abstraction is a process of hiding the implementation details and showing only
functionality to the user.
Another way, it shows only essential things to the user and hides the internal
details, for example, sending SMS where you type the text and send the message.
You don't know the internal processing about the message delivery. Abstraction
lets you focus on what the object does instead of how it does it.
Ways to achieve Abstraction
There are two ways to achieve abstraction in java
1. Abstract class (0 to 100%)
2. Interface (100%)
Abstract class in Java
A class which is declared as abstract is known as an abstract class. It can have
abstract and non-abstract methods. It needs to be extended and its method
implemented. It cannot be instantiated.
• An abstract class must be declared with an abstract keyword.
• It can have abstract and non-abstract methods.
• It cannot be instantiated.
• It can have constructors and static methods also.
• It can have final methods which will force the subclass not to change the
body of the method.
Example: abstract
class Bike{
abstract void run();
}
class Honda4 extends Bike{
void run(){System.out.println("running safely..");}
public static void main(String args[]){
Bike obj = new
Honda4(); obj.run();

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

}
}
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.
• It cannot be instantiated just like the abstract class.
• Since Java 8, we can have default and static methods in an interface.
• Since Java 9, we can have private methods in an interface.
• There are mainly three reasons to use interface. They are given below.
✓ It is used to achieve abstraction.
✓ By interface, we can support the functionality of multiple
inheritance.
✓ It can be used to achieve loose coupling.
• An interface is declared by using the interface keyword. It provides total
abstraction; means all the methods in an interface are declared with the
empty body, and all the fields are public, static and final by default. A class
that implements an interface must implement all the methods declared in
the interface.

Syntax:

interface <interface_name>{

// declare constant fields


// declare methods that abstract
// by default.
}
Polymorphism:
Polymorphism means "many forms", and it occurs when we have many classes
that are related to each other by inheritance.

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

Like we specified in the previous chapter; Inheritance lets us inherit


attributes and methods from another class. Polymorphism uses those
methods to perform different tasks. This allows us to perform a single action in
different ways.
For example, think of a superclass called Animal that has a method
called animalSound(). Subclasses of Animals could be Pigs, Cats, Dogs, Birds -
And they also have their own implementation of an animal sound (the pig
oinks, and the cat meows, etc.):
Example:
class Animal {
public void animalSound() {
System.out.println("The animal makes a sound");
}
}

class Pig extends Animal { public void


animalSound() { System.out.println("The pig
says: wee wee");
}
}

class Dog extends Animal { public void


animalSound() { System.out.println("The dog
says: bow wow");
}
}
Method Overloading:
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
increases the readability of the program.
Suppose you have to perform addition of the given numbers but there can be any
number of arguments, if you write the method such as a(int,int) for two
parameters, and b(int,int,int) for three parameters then it may be difficult for
you as well as other programmers to understand the behavior of the method
because its name differs.
So, we perform method overloading to figure out the program quickly.

19

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

Advantage of method overloading


Method overloading increases the readability of the program.
Different ways to overload the method
There are two ways to overload the method in java
1. By changing number of arguments
2. By changing the data type
Example:
class Adder{
static int add(int a,int b){return a+b;}
static int add(int a,int b,int c){return a+b+c;}
}
class TestOverloading1{
public static void main(String[] args){
System.out.println(Adder.add(11,11));
System.out.println(Adder.add(11,11,11));
}}
Method Overriding:
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
oMethod overriding is used to provide the specific implementation of a
method which is already provided by its superclass.
oMethod overriding is used for runtime polymorphism
Rules for Java Method Overriding
1. The method must have the same name as in the parent class
2. The method must have the same parameter as in the parent class.
3. There must be an IS-A relationship (inheritance).
Example:
class Vehicle{
void run(){System.out.println("Vehicle is running");}
}
class Bike extends Vehicle{

public static void main(String args[]){


Bike obj = new Bike();

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

obj.run();
}
}
Encapsulation:
Encapsulation in Java is a process of wrapping code and data together into a
single unit, for example, a capsule which is mixed of several medicines.
We can create a fully encapsulated class in Java by making all the data members
of the class private. Now we can use setter and getter methods to set and get the
data in it.
The Java Bean class is the example of a fully encapsulated class.
Advantage of Encapsulation in Java
By providing only a setter or getter method, you can make the class read-only or
write-only. In other words, you can skip the getter or setter methods.
It provides you the control over the data. Suppose you want to set the value of
id which should be greater than 100 only, you can write the logic inside the
setter method. You can write the logic not to store the negative numbers in the
setter methods.
It is a way to achieve data hiding in Java because other class will not be able to
access the data through the private data members.
The encapsulate class is easy to test. So, it is better for unit testing.
The standard IDE's are providing the facility to generate the getters and setters.
So, it is easy and fast to create an encapsulated class in Java.
Java Package:
A java package is a group of similar types of classes, interfaces and sub-
packages.
Package in java can be categorized in two form, built-in package and user-
defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net, io,
util, sql etc.
Here, we will have the detailed learning of creating and using user-defined
packages.
Advantage of Java Package:
1) Java package is used to categorize the classes and interfaces so that they
can be easily maintained.
2) Java package provides access protection.
3) Java package removes naming collision.
There are three ways to access the package from outside the package.

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

1. import package.*;
2. import package.classname;
3. fully qualified name.
Access Modifiers in Java:
There are two types of modifiers in Java: access modifiers and non-access
modifiers.
The access modifiers in Java specifies the accessibility or scope of a field,
method, constructor, or class. We can change the access level of fields,
constructors, methods, and class by applying the access modifier on it. There
are four types of Java 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.
There are many non-access modifiers, such as static, abstract,
synchronized, native, volatile, transient, etc
Exception Handling in Java
The Exception Handling in Java is one of the powerful mechanism to handle
the runtime errors so that the normal flow of the application can be maintained.
What is Exception in Java?
In Java, an exception is an event that disrupts the normal flow of the program.
It is an object which is thrown at runtime.
What is Exception Handling?
Exception Handling is a mechanism to handle runtime errors such as
ClassNotFoundException, IOException, SQLException, RemoteException, etc. The
core advantage of exception handling is to maintain the normal flow of the
application. An exception normally disrupts the normal flow of the application;
that is why we need to handle exceptions.

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

Types of Java Exceptions


There are mainly two types of exceptions: checked and unchecked. An error is
considered as the unchecked exception. However, according to Oracle, there are
three types of exceptions namely:
1. Checked Exception
2. Unchecked Exception
3. Error

The classes that directly inherit the Throwable class except RuntimeException and
Error are known as checked exceptions. For example, IOException, SQLException,
etc. Checked exceptions are checked at compile-time.

The classes that inherit the RuntimeException are known as unchecked


exceptions. For example, ArithmeticException, NullPointerException,
ArrayIndexOutOfBoundsException, etc. Unchecked exceptions are not checked at
compile-time, but they are checked at runtime.

Error is irrecoverable. Some example of errors are OutOfMemoryError,


VirtualMachineError, AssertionError etc.

Java provides five keywords that are used to handle the exception.
• The "try" keyword is used to specify a block where we should place an
exception code. It means we can't use try block alone. The try block must
be followed by either catch or finally.
• 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.
• The "finally" block is used to execute the necessary code of the
program. It is executed whether an exception is handled or not.
• The “throw” keyword is used to throw an exception.
• The "throws" keyword is used to declare exceptions. It specifies that
there may occur an exception in the method. It doesn't throw an
exception. It is always used with method signature.
Example:
public class JavaExceptionExample{

public static void main(String args[]){

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

try{
int data=100/0;

}catch(ArithmeticException e){System.out.println(e);
}
System.out.println("rest of the code...");
}}
Multithreading in Java:
Multithreading in Java is a process of executing multiple threads
simultaneously.
A thread is a lightweight sub-process, the smallest unit of processing.
Multiprocessing and multithreading, both are used to achieve multitasking.
However, we use multithreading than multiprocessing because threads use a
shared memory area. They don't allocate separate memory area so saves
memory, and context-switching between the threads takes less time than process.
Java Multithreading is mostly used in games, animation, etc.

Advantages of Java Multithreading


1) It doesn't block the user because threads are independent and you can
perform multiple operations at the same time.
2) You can perform many operations together, so it saves time.
3) Threads are independent, so it doesn't affect other threads if an exception
occurs in a single thread.

Relational database concepts


A relational database management system (RDBMS) stores and retrieves data
that is represented in tables. A relational database consists of a collection of
tables that store interrelated data.
This section introduces some of the terms and concepts that are important in
talking about relational databases.
Database tables
In a relational database, all data is held in tables, which are made
up of rows and columns.
Each table has one or more columns, and each column is assigned a specific
datatype, such as an integer number, a sequence of characters (for text), or
a date. Each row in the table has a value for each column.

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

A typical fragment of a table containing employee information may look as


follows:
emp_ID emp_lname emp_fname emp_phone

10057 Huong Zhang 1096

10693 Donaldson Anne 7821


The tables of a relational database have some important characteristics:
• There is no significance to the order of the columns or rows.
• Each row contains one and only one value for each column.
• Each value for a given column has the same type.
The following table lists some of the formal and informal relational database
terms describing tables and their contents, together with their equivalent in
other nonrelational databases. This manual uses the informal terms.
Formal relational Informal relational Equivalent nonrelational
term term term

Relation Table File

Attribute Column Field

Tuple Row Record


When you are designing your database, make sure that each table in the
database holds information about a specific thing, such as employees,
products, or customers.
By designing a database this way, you can set up a structure that eliminates
redundancy and inconsistencies. For example, both the sales and accounts
payable departments may look up information about customers. In a
relational database, the information about customers is entered only once, in a
table that both departments can access.
A relational database is a set of related tables. You use primary and foreign
keys to describe relationships between the information in different tables.
Primary and foreign keys
Primary and foreign keys define the relational structure of a database. These keys
enable each row in the database tables to be identified, and define the
relationships between the tables.

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

Tables have a primary key


All tables in a relational database should have a primary key. The primary
key is a column, or set of columns, that allows each row in the table to be
uniquely identified. No two rows in a table with a primary key can have the
same primary key value.
If no primary key is assigned, all the columns together become the primary key.
It is good practice to keep your primary key for each table as compact as
possible.
Examples
In a table holding information about employees, the primary key may be an ID
number assigned to each employee.
In the sample database, the table of sales order items has the
following columns:
• An order number, identifying the order the item is part of
• A line number, identifying each item on any order
• A product ID, identifying the product being ordered
• A quantity, showing how many items were ordered
• A ship date, showing when the order was shipped
To find the name of a particular employee's department, there is no need to put
the name of the employee's department into the employee table. Instead, the
employee table contains a column holding the department ID of the employee's
department. This is called a foreign key to the department table. A foreign key
references a particular row in the table containing the corresponding primary
key.
In this example, the employee table (which contains the foreign key in the
relationship) is called the foreign table or referencing table. The
department table (which contains the referenced primary key) is called the
primary table or the referenced table.

Queries
Retrieve data from a database using the SELECT statement. The basic query
operations in a relational system are projection, restriction, and join. The
SELECT statement implements all of these operations.
A projection is a subset of the columns in a table. A restriction (also
called selection) is a subset of the rows in a table, based on some conditions.
For example, the following SELECT statement retrieves the names and prices of
all products that cost more than $15:

Downloaded by priya (raj3roy4@gmail.com)


lOMoARcPSD|21088629

SELECT name, unit_price

FROM product

WHERE unit_price > 15


This query uses both a restriction (WHERE unit_price > 15) and a
projection (SELECT name, unit_price)
A JOIN links the rows in two or more tables by comparing the values in key
columns and returning rows that have matching values. For example, you
may want to select the item identification numbers and product names for all
items for which more than a dozen has been shipped: SELECT
sales_order_items.id, product.name

FROM product KEY JOIN sales_order_items

WHERE sales_order_items.quantity > 12


The product table and the sales_order_items table are joined together
based on the foreign key relationships between them.

Downloaded by priya (raj3roy4@gmail.com)

You might also like