Java Full Stack Internship Report
Java Full Stack Internship Report
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
CERTIFICATE
Contents
• Introduction to web
• Introduction to Java
• Java Language Fundamentals
• OOP implementation
• Packages
• Arrays
• Exception handling
• Working with String
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 used for:
Syntax:
public class Main{
public static void main(String[] args){
System.out.println(“Hello World”);
}
}
• 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.
• 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.
• Inside the main() method, we can use the println() method to print a
line of text to the screen.
IDENTIFIERS:
Variables:
• Variables are containers for storing data values.
• To create a variable, you must specify the type and assign it a value.
Data Types:
• Data types are divided into two groups:
✓
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.
Example:
int myInt = 9;
double myDouble = myInt;
Example:
double myDouble = 9.78d;
int myInt = (int)
myDouble;
Operators:
• Operators are used to perform operations on variables and values.
✓ Arithmetic operators
✓ Assignment operators
✓ Comparison operators
✓ Logical operators
✓ Bitwise operators
• Arithmetic Operators:
6
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ ModDivoisi
on 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
• Logical Operators:
Operator Example Meaning
true if either
OR)
|| expression1 expression1 or
expression2
expression2 is
true
!(Logical !expression true if expression is
NOT) false and vice versa
• Unary Operators:
Operator Meaning
Conditional Statements:
• Java has the following conditional statements:
Syntax:
if (condition) {
// block of code to be executed if the condition is true
}
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
}
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
}
✓ 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.
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:
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.
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.
• 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");
}
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.
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.
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();
}
}
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>{
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.
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.
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.
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{
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.
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:
SELECT name,
unit_price FROM
product
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.