Java Project Final-3
Java Project Final-3
ON
“JAVA PROGRAMMING”
SUBMITTED FOR THE FULFILLMENT OF THE
REQUIREMENTS FOR THE DEGREEOF THE BACHELOR
OF TECHNOLOGY UNDER BPUT
SUBMITTED BY
SITALLAPALLI, BERHAMPUR-761003
1
CERTIFICATE
2
ACKNOWLEDGEMENT
I express my deep sense of gratitude indebtedness on the successful completion of my internship work
would have been incomplete without the mention of the people who made it possible ,whose precious
guidance ,encouragement , supervision and helpful discussion made it possible. I would like to convey my
heartfelt gratitude to Dr. Debasish Mohapatra for his tremendous support and assistance in the completion of
my project. I would also like to thank our principal Prof. Ranjana Kumar Swain for providing me with this
wonderful opportunity to work on a project with the topic Food Culture during the Pandemic. The
completion of the project would not have been possible without their help and insights. Lastly I would like
to thanks my parents, my peers and fellow classmates, who supported and help me throughout the course of
internship project.
3
ABSTRACT
The java programming language is currently growing in popularity within the academic community , and a
result this ,a lot of colleges converting their introductory computer science course into java . while java is
very portable and web compatible languages , students often have a hard time mastering it . there have been
some project that were aimed to assist student in grasping java s conceptual frame work , but many of these
involved either simplified java syntax pre constructed module that distance student from the process of
coding . our goal was to design an educational tool that will identify common java programming errors and
misconception and facilitate the learning process while making sure that students are directly with their
code.
4
CONTENTS PAGES
• INTRODUCTION TO JAVA 06
• DATA TYPES 08
• FEATURES OF OOPS 09
• TOKENS IN JAVA 10
• CONTROL STATEMENT IN JAVA 16
• METHODS 18
• CLASS AND OBJECTS 22
• ACCESS MODIFIER 24
• CONSTRUCTER 24
• INHERITANCE 28
• ABSTRACT CLASS 28
• INTERFACE 30
• ARRAY 31
• PACKAGE 32
• EXCEPTION HANDLING 33
• PROJECTS 34
• ADVANTAGES OF JAVA 38
• DISADVANTAGES OF JAVA 38
• CONCLUSION 38
5
INTRODUCTION OF JAVA
Java is a programming language and a platform. Java is a high level, robust, object-oriented and secure
programming language.
.Platform: Any hardware or software environment in which a program runs , is known as a platform. Since
Java has a runtime environment (JRE) and API, it is called a platform.
History:
Java’s history is very interesting. It is a programming language created in 1991. James Gosling, Mike
Sheridan, and Patrick Naught on, a team of Sun engineers known as the Green team initiated the Java
language in 1991. Sun Microsystems released its first public implementation in 1996 as Java 1.0. It
provides no-cost -run-times on popular platforms. Java1.0 compiler was re-written in Java by Arthur Van
Hoff to strictly comply with its specifications. With the arrival of Java 2, new versions had multiple
configurations built for different types of platforms.
In 1997, Sun Microsystems approached the ISO standards body and later formalized Java, but it soon
withdrew from the process. At one time, Sun made most of its Java implementations available without
charge, despite their proprietary software status. Sun generated revenue from Java through the selling of
licenses for specialized products such as the Java Enterprise System.
APPLICATION:
According to Sun, 3 billion devices run Java. There are many devices where Java is currently used. Some of
them are as follows:
2. Web Applications.
4. Mobile
5. Embedded System
6. Robotics
7. Games, etc.
6
JVM
JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it doesn't physically
exist. It is a specification that provides a runtime environment in which Java byte code can be executed. It can
also run those programs which are written in other languages and compiled to Java byte code.
JVMs are available for many hardware and software platforms. JVM, JRE, and JDK are platform dependent
because the configuration of each OS is different from each other. However, Java is platform independent.
There are three notions of the JVM: specification, implementation, and instance.
JRE
JRE is an acronym for Java Runtime Environment. It is also written as Java RTE. The Java Runtime
Environment is a set of software tools which are used for developing Java applications. It is used to provide
the runtime environment. It is the implementation of JVM. It physically exists. It contains a set of libraries +
other files that JVM uses at runtime.
The implementation of JVM is also actively released by other companies besides Sun Micro Systems.
JDK
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a software development
environment which is used to develop Java applications and applets. It physically exists. It contains JRE +
development tools.
JDK is an implementation of any one of the below given Java Platforms released by Oracle Corporation:
The JDK contains a private Java Virtual Machine (JVM) and a few other resources such as an
interpreter/loader (java), a compiler, a jar ,a documentation generator, etc. to complete the development of a
Java Application.
7
DATATYPES 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:
In Java language, primitive data types are the building blocks of data manipulation. These are the most basic
data types available in Java language.
JAVA FEATURES:
The primary objective of Java programming language creation was to make it portable, simple and secure
programming language. Apart from this, there are also some excellent features which play an important role
in the popularity of this language. The features of Java are also known as Java buzzwords.
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
8
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic
FEATURES OF OOPS
Object-Oriented Programming is a paradigm that provides many concepts, such as inheritance, data
binding, polymorphism, etc.
Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects.
It simplifies software development and maintenance by providing some concepts:
o Object
o Class
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation
Object
o 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.
o 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:
o 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
9
o 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.
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.
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.
TOKENS IN JAVA
The tokens are the small building blocks of a Java program that are meaningful to the Java compiler.
In Java, the program contains classes and methods. Further, the methods contain the expressions and
statements required to perform a specific operation. These statements and expressions are made up
of tokens. In other words, we can say that the expression and statement is a set of tokens.
The Java compiler breaks the line of code into text (words) is called Java tokens. These are the smallest
element of the Java program. The Java compiler identified these words as tokens. These tokens are separated
by the delimiters. It is useful for compilers to detect errors. Remember that the delimiters are not part of the
Java tokens.
10
Types of Java Tokens
There are five types of java tokens: keywords , identifiers, literals, operators and separators. The
classification is based on their work type; some are used to define names, and others for arithmetic
operations.
Keywords
Keywords are reserved words in programming languages. These are used to indicate predefined terms and
actions in a program. As a result, these words are not allowed to be used as names of variables or objects. It
is case-sensitive and always written in lowercase. Java has the following keywords:
Identifier
A method name, class name, variable name, or label is an identifier in Java. The user typically defines these.
⭐ Identifiers are case-sensitive. That is, “ninja” is not the same as “NINJA”.
Literals
Literals represent fixed values in a source code. These are similar to standard variables with the difference
that these are constant. These can be classified as an integer literal, a string literal, a Boolean etc. The user
Integer
Floating Point
Boolean
11
Character
String
Operators
As the name suggests, operators perform operations between different entities. Whenever the compiler sees
an operator, it tokenizes it and proceeds further. Java has other operators based on their functionality. In
There are many types of operators in Java which are given below:
Arithmetic Operators
Assignment Operators
Relational Operators
Logical Operators
Unary Operators
Bitwise Operators
Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations on variables and data..
Operator Operation
+ Addition
- Subtraction
* Multiplication
12
/ Division
Assignment Operators
Assignment operators are used in Java to assign values to variables. a=5; Here = is the assignment operator.
Operator Example
= a = b;
+= a += b;
-= a -= b;
*= a *= b;
/= a /= b;
%= a %= b;
Relational Operators
Relational operators are used to check the relationship between two operands .
Here, < operator is the relational operator. It checks if a is less than b or not.
Operator Description
== Is Equal To
13
!= Not Equal To
Logical Operators
Logical operators are used to check whether an expression is true or false. They are used in decision making.
Operator Meaning
Unary Operators
Unary operators are used with only one operand. For example, ++ is a unary operator that increases the
Operator Meaning
+ Unary plus: not necessary to use since numbers are positive without using it
14
! Logical complement operator: inverts the value of a Boolean.
Bitwise Operators
Bitwise operators in Java are used to perform operations on individual bits. For example,
Here, ~ is a bitwise operator. It inverts the value of each bit (0 to 1 and 1 to 0).
Operator Description
~ Bitwise Complement
^ Bitwise exclusive OR
Separators
These are the special symbols used to separate java tokens. These are sometimes called punctuators. The
separators have special meaning and thus should not be used for anything else.
Brackets []: These are used to define arrays and represent single and multi-dimension subscripts.
Braces {}: These mark the start and end of multi-line code blocks.
15
CONTROL STATEMENT IN JAVA:
Java compiler executes the code from top to bottom. The statements in the code are executed according to the
order in which they appear. However, Java provides statements that can be used to control the flow of Java
code. Such statements are called control flow statements. It is one of the fundamental features of Java, which
provides a smooth flow of program.
Decision making structures have one or more conditions to be evaluated or tested by the
program, along with a statement or statements that are to be executed if the condition is determined to be true,
and optionally, other statements to be executed if the condition is determined to be false.
16
Java programming language provides following types of decision making statements.
1 if statement
2 if...else statement
A if statement can be followed by an optional else statement, which executes when the Boolean
expression is false.
3 nested if statement
You can use one if or else if statement inside another if or else if statement(s).
4 switch statement
A switch statement allows a variable to be tested for equality against a list of values.
Loop statements:
A loop statement allows us to execute a statement or group of statements multiple times and
following is the general form of a loop statement in most of the programming languages −
Java programming language provides the following types of loop to handle looping requirements.
17
Sr. Loop & Description
No.
1 while loop
Repeats a statement or group of statements while a given condition is true. It tests the
condition before executing the loop body.
2 for loop
Execute a sequence of statements multiple times and abbreviates the code that manages the
loop variable.
3 do...while loop
Like a while statement, except that it tests the condition at the end of the loop body.
2. Jump Statements:
Jump statements change execution from its normal sequence. When execution leaves a scope,
all automatic objects that were created in that scope are destroyed.
Java supports the following control statements.
No.
1 break statement
Terminates the loop or switch statement and transfers execution to the statement immediately
following the loop or switch.
2 continue statement
Causes the loop to skip the remainder of its body and immediately retest its condition prior to
reiterating.
METHODS
Method in Java or Java Method is a collection of statements that perform some specific task and
return the result to the caller. A Java method can perform some specific task without returning
18
anything. Methods in Java allow us to reuse the code without retyping the code. In Java, every method
must be part of some class that is different from languages like C, C++, and Python.
1. A method is like a function i.e. used to expose the behavior of an object.
2. it is a set of codes that perform a particular task.
Method Declaration
The method declaration provides information about method attributes, such as visibility, return-type, name
and arguments .
Types of Method
o Predefined Method
o User-defined Method
Predefined Method
In Java, predefined methods are the method that is already defined in the Java class libraries is
known as predefined methods. It is also known as the standard library method or built-in method. We
can directly use these methods just by calling them in the program at any point. Some pre-defined methods
are length(), equals(), compare To(), sqrt (), etc. When we call any of the predefined methods in our
program, a series of codes related to the corresponding method runs in the background that is already stored
in the library.
User-defined Method
The method written by the user or programmer is known as a user-defined method. These methods are
modified according to the requirement. We can declare two types of user-defined methods in an application.
1. Instance Method
2. Static Method
19
Instance Method in Java
An instance method is used to implement behaviors of each object/instance of the class. Since the
instance method represents behaviors of the objects. Therefore, instance method is linked with an object.
An instance method is also known as non-static method. So, without creating an object of the class, the
methods cannot exist to perform their desired behaviors or task. It is allocated in the heap memory during
the object creation.
When you declare any method with a static modifier, it is called static method in java. A static
method is linked with class.
Therefore, it is also known as a class method. It is used to implement the behavior of the class itself. Static
methods load into the memory during class loading and before object creation.
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.
In this example, we have created two methods, first add () method performs addition of two numbers and
second add method performs addition of three numbers.
In this example, we are creating static methods so that we don't need to create instance for calling methods.
20
static int add(int a,int b)
In this example, we have created two methods that differs in data type. The first add method receives two
integer arguments and second add method receives two double arguments.
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.
o Method overriding is used to provide the specific implementation of a method which is already
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.
class Vehicle{
21
}
void run(){
obj.run();
}
}
entities.
Class:
1. Class is a set of object which shares common characteristics/ behavior and common properties/
attributes.
2. Class is not a real world entity. It is just a template or blueprint or prototype from which objects are
created.
• data member
• method
• constructor
22
• interface
Object:
It is a basic unit of Object-Oriented Programming and represents real-life entities. A typical Java
program creates many objects, which as you know, interact by invoking methods.
An object consists of :
2. Behavior: It is represented by the methods of an object. It also reflects the response of an object
3. Identity: It gives a unique name to an object and enables one object to interact with other objects.
//another class
class Student{
int id;
String name;
class TestStudent1{
System.out.println(s1.id);
System.out.println(s1.name);
23
ACCESS MODIFIER
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.
1. Private: The access level of a private modifier is only within the class. It cannot be accessed from
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.
CONSTRUCTER
Java constructors is a terminology used to construct something in our programs. A constructor in Java
is a special method that is used to initialize objects. The constructor is called when an object of a class
is created. It can be used to set initial values for object attributes.
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 the 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.
2. Parameterized constructor
In this example, we are creating the no-arg constructor in the Bike class. It will be invoked at the time of
object creation.
class Bike1{
Bike1(){System.out.println("Bike is created");}
//main method
In this example, we have created the constructor of Student class that have two parameters. We can have any
number of parameters in the constructor.
class Student4{
int id;
String name;
25
Student4(int i,String n){
id = i;
name = n;
s1.display();
s2.display();
In Java, a constructor is just like a method but without return type. It can also be overloaded like Java methods.
Constructor overloading in Java is a technique of having more than one constructor with different parameter
lists. They are arranged in a way that each constructor performs a different task. They are differentiated by the
compiler by the number of parameters in the list and their types.
class Student5{
int id;
String name;
26
int age;
id = i;
name = n;
id = i;
name = n;
age=a;
s1.display ();
s2.display ();
INHERITANCE
27
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).
In the terminology of Java, a class which is inherited is called a parent or super class, and the new class is
called child or subclass
The extends keyword indicates that you are making a new class that derives from an existing class. The
meaning of "extends" is to increase the functionality.
3. Hierarchical Inheritance
In Hierarchical Inheritance, one class serves as a super class (base class) for more than one subclass. In the
below image, class A serves as a base class for the derived classes B, C, and D.
4. Multiple Inheritance (Through Interfaces)
In Multiple inheritances, one class can have more than one super class and inherit features from all parent
classes. Please note that Java does not support multiple inheritances with classes. In java, we can achieve
multiple inheritances only through Interfaces. In the image below, Class C is derived from interfaces A
and B.
ABSTRACT CLASS
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.
28
Points to Remember
o It cannot be instantiated.
o It can have final methods which will force the subclass not to change the body of the method .
void printInfo() {
System.out.println(name);
System.out.println(age);
System.out.println(salary);
class Base {
s.printInfo();
29
}
INTERFACE
An Interface in Java programming language is defined as an abstract type used to specify the behavior
of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains 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 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.
interface In1
System.out.println ("hello");
30
{
t.display();
ARRAY
Java array is a collection of similar type of elements which has contiguous memory location.
Java array is an object which contains elements of a similar data type. Additionally, The elements of an array
are stored in a contiguous memory location. It is a data structure where we store similar elements. We can
store only a fixed set of elements in a Java array.
Array in Java is index-based, the first element of the array is stored at the 0th index, 2nd element is stored on
1st index and so on.
o Multidimensional Array
//Java Program to illustrate how to declare, instantiate, initalize //and traverse the Java array.
class Testarray{
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
31
//traversing array
System.out.println(a[i]);
}}
Multidimensional Array
In such case, data is stored in row and column based index (also known as matrix form).
class Testarray3{
int arr[][]={{1,2,3},{2,4,5},{4,4,5}};
//printing 2D array
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(arr[i][j]+" "); }
System.out.println(); } }}
JAVA PACKAGES
A java package is a group of similar types of classes, interfaces and sub-packages..
package mypack;
Types of packages:
1) Java package is used to categorize the classes and interfaces so that they can be easily maintained.
EXCEPTION HANDLING
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 .
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.
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
33
public class JavaExceptionExample{
String name=sc.nextLine();
String accNo=sc.nextLine();
obj1.menu(); }}
class BankAccount{
this.customerName=customerName;
this.mobileNo=mobileNo;
34
this.accNo=accNo;
this.IFSEcode=IFSEcode;
if(amount!=0){
bal+=amount;
prevTrans=amount;
}}
bal-=amt;
prevTrans=-amt;
else if(bal<amt){
void getPreviousTrans(){
if(prevTrans>0){
System.out.println("Deposited: "+prevTrans); }
else if(prevTrans<0)
{ System.out.println("Withdrawn: "+Math.abs(prevTrans)); }
void menu1(){
System.out.println("e) Exit");
void menu(){
35
char option;
System.out.println("hello "+customerName);
menu1();
do{
System.out.println("Choose an option");
option=sc.next().charAt(0);
switch (option){
case 'a':
System.out.println("Balance ="+bal);
menu1();
break;
case 'b':
double amt=sc.nextDouble();
deposit(amt);
menu1();
break;
case 'c':
double amtW=sc.nextDouble();
withdraw(amtW);
menu1();
break;
case 'd':
System.out.println("Previous Transaction:");
getPreviousTrans();
menu1();
36
break;
case 'e':
break;
default:
break; }
}while(option!='e');
}}
ADVANTAGES OF JAVA
1. Platform independent: Java code can run on any platform that has a Java Virtual Machine (JVM)
installed, which means that applications can be written once and run on any device.
2. Object-Oriented: Java is an object-oriented programming language, which means that it follows the
principles of encapsulation, inheritance, and polymorphism.
3. Security: Java has built-in security features that make it a secure platform for developing
applications, such as automatic memory management and type checking.
4. Large community: Java has a large and active community of developers, which means that there is a
lot of support available for learning and using the language.
5. Enterprise-level applications: Java is widely used for developing enterprise-level applications, such
as web applications, e-commerce systems, and database systems .
DISADVANTAGES OF JAVA
1. Performance: Java can be slower compared to other programming languages, such as C++, due to its
use of a virtual machine and automatic memory management.
2. Memory management: Java’s automatic memory management can lead to slower performance and
increased memory usage, which can be a drawback for some applications.
CONCLUSION
Java offers the real possibility that most programs can be written in a type-safe language. However,
for Java to be broadly useful, it needs to have more expressive power than it does at present. This paper
addresses one of the areas where more power is needed. It extends Java with a mechanism for parametric
polymorphism, which allows the definition and implementation of generic abstractions. The paper gives a
complete design for the extended language. The proposed extension is small and conservative and the paper
discusses the rationale for many of our decisions. The extension does have some impact on other parts of
Java, especially Java arrays, and the Java class library. The paper also explains how to implement the
extensions. We first sketched two designs that do not change the JVM, but sacrifice some space or time
performance. Our implementation avoids these performance problems. We had three main goals: to allow all
instantiations to share the same bytecodes (avoiding code blowup), to have good performance when using
parameterized code, and to have little impact on the performance of code that does not use parameterization.
The implementation discussed in Section 3 meets these goals. In that section, we described some small
extensions to the virtual machine specification that are needed to support parameterized abstractions; we
also described the designs of the bytecode verifier and interpreter, and the runtime
38
39