Training Report
Training Report
Submitted By
SUBMITTED TO:
1
DECLARATION
I hereby declare that the Industrial Training Report entitled JAVA CORE is an authentic record
of my own work as requirements of Industrial Training during the period from 18TH June, 2018
to 28TH July for the award of degree of B.Tech. (Computer Science & Engineering),
GREATER NOIDA INSTITUTE OF ENGINEERING & TECHNOLOGY, GREATER
NOIDA
1513210013
2
ACKNOWLEDGEMENT
I am immensely indebted to Mr. Rahul Chauhan for the invaluable help that he
rendered at every step of this project. It is a wonderful experience to be a part of.
“Codules Technologies” Where we work under brilliant minds. We owe our deep
regards for the support and kind staff authorities who are helped me in my lean
patches during these months. The knowledge we are gaining throughout our studies
have the practical implementation during this period. We are grateful to all the staff
of “Codules Technologies”
3
ABOUT COMPANY
4
Table of Contents
1) Introduction
2) History of Java
3) JVM & JRE
4) JDK
5) Features of Java
6) Object
7) Class
8) Object oriented programming
a) Inheritance
i) Single Inheritance
ii) Multiple Inheritance
iii) Hierarchical Inheritance
iv)Hybrid Inheritance
b) Encapsulation
c) Abstraction
d) Polymorphism
9) Java static and this keyword
10) Super and final keyword
11) Java method overloading
12) Java method overriding
13) Packages
14) Exception handling in Java
a) Types of Exception
b) Common Scenarios of Java Exceptions
5
15) Java try-catch block
16) Project
a) Introduction
b) Purpose
c) Scope
d) Background
e) User characteristics
f) Data Tables
g) Snapshots
17) Conclusion
6
List of Tables
1) Exception keywords
2) Desk login
3) Doctor login
4) Patient Information
5) Patient diagnosis
7
List of Figures
1) Object-oriented programming
2) Inheritance
3) Single Inheritance
4) Multiple Inheritance
5) Hierarchical Inheritance
6) Hybrid Inheritance
7) Encapsulation
8) Hierarchy of Java Exception classes
9) Types of Exceptions
10) Working of try-catch block
11) DFD
12) Project homepage
13) Desk login
14) Doctor login
15) Register new patients
16) View patients
17) View diagnostics
18)
8
INTRODUCTION
Java is one of the programming language or technology used for developing web applications.
Java language developed at SUN Micro Systems in the year 1995 under the guidance of James
Gosling and their team. Originally SUN Micro Systems is one of the Academic university
(Stanford University Network).
Whatever the software developed in the year 1990, SUN Micro Systems has released on the
name of oak, which is original name of java (scientifically oak is one of the tree name). The
OAK has taken 18 months to develop. The oak is unable to fulfill all requirements of the
industry. So, James Gosling again reviews this oak and released with the name of java in the
year 1995. Scientifically java is one of the coffee seed name.
9
History of Java
Java was started as a project called "Oak" by James Gosling in June 1991. Gosling's goals
were to implement a virtual machine and a language that had a familiar C like notation but with
greater uniformity and simplicity than C/C++.
The First publication of Java 1.0 was released by Sun Microsystems in 1995. It made the
promise of "Write Once, Run Anywhere", with free runtimes on popular platforms.
In 2006-2007 Sun released java as open source and platform independent software.
Over time new enhanced versions of Java have been released. The current version of Java
is Java 1.7 which is also known as Java 7.
10
JVM & JRE
The Java virtual machine (JVM) is a software implementation of a computer that executes
programs like a real machine.
The Java virtual machine is written specifically for a specific operating system, e.g. for
Linux a special implementation is required as well as for Windows.
Java programs are compiled by the Java compiler into bytecode. The Java virtual machine
interprets this bytecode and executes the Java program.
The Java runtime environment (JRE) consists of the JVM and the Java class libraries and
contains the necessary functionality to start Java programs.
The JDK contains in addition the development tools necessary to create Java programs. The
JDK consists therefore of a Java compiler, the Java virtual machine, and the Java class
libraries.
JDK
JDK (Java SE Development Kit) Includes a complete JRE (Java Runtime Environment) plus
tools for developing, debugging, and monitoring Java applications. JDK is required to build and
run Java applications and applets.
1) Simple
Java is a simple language because of its various features, Java Doesn’t Support
Pointers, Operator Overloading etc. It doesn’t require unreferenced object because java
support automatic garbage collection.
Java provides bug free system due to the strong memory management.
2) Object-Oriented
Object-Oriented Programming Language (OOPs) is the methodology which provide
software development and maintenance by using object state, behavior, and properties.
11
As the languages like Objective C, C++ fulfills the above four characteristics yet they are
not fully object-oriented languages because they are structured as well as object-oriented
languages.
In java everything is an Object. Java can be easily extended since it is based on the Object
model
3) Secure
Java is Secure Language because of its many features it enables to develop virus-free,
tamper-free systems. Authentication techniques are based on public-key encryption.
Java does not support pointer explicitly for the memory.
All Program Run under the sandbox.
4) Robust
Java was created as a strongly typed language. Data type issues and problems are
resolved at compile-time, and implicit casts of a variable from one type to another are
not allowed.
Memory management has been simplified java in two ways. First Java does not
support direct pointer manipulation or arithmetic. This make it possible for a java
program to overwrite memory or corrupt data.
Second, Java uses runtime garbage collection instead of instead of freeing of memory.
In languages like C++, it Is necessary to delete or free memory once the program has
finished with it.
5) Platform-independent
Java Language is platform-independent due to its hardware and software environment. Java
code can be run on multiple platforms e.g. windows, Linux, sun Solaris, Mac/OS etc. Java
code is compiled by the compiler and converted into byte code. This byte code is a platform
independent code because it can be run on multiple platforms i.e. Write Once and Run
Anywhere (WORA).
6) Architecture neutral
It is not easy to write an application that can be used on Windows, UNIX and a Macintosh.
And it’s getting more complicated with the move of windows to non-Intel CPU
architectures.
12
Java takes a different approach. Because the Java compiler creates byte code instructions
that are subsequently interpreted by the java interpreter, architecture neutrality is achieved
in the implementation of the java interpreter for each new architecture.
7) Portable
Java code is portable. It was an important design goal of Java that it be portable so that as
new architectures (due to hardware, operating system, or both) are developed, the java
environment could be ported to them.
In java, all primitive types (integers, longs, floats, doubles, and so on) are of defined sizes,
regardless of the machine or operating system on which the program is run. This is in direct
contrast to languages like C and C++ that leave the sized of primitive types up to the
compiler and developer.
Additionally, Java is portable because the compiler itself is written in Java.
8) Dynamic
Because it is interpreted, Java is an extremely dynamic language, At runtime, the java
environment can extends itself by linking in classes that may be located on remote servers
on a network (for example, the internet)
At runtime, the java interpreter performs name resolution while linking in the necessary
classes. The Java interpreter is also responsible for determining the placement of object in
memory. These two features of the Java interpreter solve the problem of changing the
definition of a class used by other classes.
9) Interpreted
We all know that Java is an interpreted language as well. With an interpreted language such
as Java, programs run directly from the source code.
The interpreter program reads the source code and translates it on the fly into computations.
Thus, Java as an interpreted language depends on an interpreter program.
The versatility of being platform independent makes Java to outshine from other languages.
The source code to be written and distributed is platform independent.
Another advantage of Java as an interpreted language is its error debugging quality. Due to
this any error occurring in the program gets traced. This is how it is different to work with
Java.
13
10) High performance
For all but the simplest or most infrequently used applications, performance is always a
consideration for most applications, including graphics-intensive ones such as are
commonly found on the world wide web, the performance of java is more than adequate.
11) Multithreaded
Writing a computer program that only does a single thing at a time is an artificial constraint
that we’ve lived with in most programming languages. With java, we no longer have to live
with this limitation. Support for multiple, synchronized threads is built directly into the Java
language and runtime environment.
Synchronized threads are extremely useful in creating distributed, network-aware
applications. Such as application may be communicating with a remote server in one thread
while interacting with a user in a different thread.
12) Distributed.
Java facilitates the building of distributed application by a collection of classes for use in
networked applications. By using java’s URL (Uniform Resource Locator) class, an
application can easily access a remote server. Classes also are provided for establishing
socket-level connections.
What is Object?
In real-world an entity that has state and its behavior is known as an object.
For Example:
A Car is an object. It has states (name, color, model) and its behavior (changing gear,
applying brakes).
A Pen is an object. Its name is Parker; color is silver etc. known as its state. It is used to write,
so writing is its behavior.
In real-world object and software object have conceptually similar characteristics. In terms of
object-oriented programming, software objects also have a state and behavior.
What is class?
A class is a template or blueprint that is used to create objects.
Class representation of objects and the sets of operations that can be applied to such objects.
A class consists of Data members and methods.
The primary purpose of a class is to hold data/information. This is achieved with attributes
which are also known as data members.
We will understand the below core concepts of Object-oriented Programming in the following
sequence:
15
1. Inheritance
2. Encapsulation
3. Abstraction
4. Polymorphism
In OOP, computer programs are designed in such a way where everything is an object that
interact with one another. Inheritance is one such concept where the properties of one class can
be inherited by the other. It helps to reuse the code and establish a relationship between
different classes.
Fig-1
As we can see in the image, a child inherits the properties from his father. Similarly, in Java,
there are two classes:
A class which inherits the properties is known as Child Class whereas a class whose properties
are inherited is known as Parent class.
Fig-2
16
1.Sinlge Inheritance
In single inheritance, one class inherits the properties of another. It enables a derived class to
inherit the properties and behavior from a single parent class. This will in turn enable code
reusability as well as add new features to the existing code.
Here, Class A is your parent class and Class B is your child class which inherits the properties
and behavior of the parent class.
Fig-3
Class A
{
---
}
Class B extends A {
---
}
2. Multiple Inheritance
When a class is derived from a class which is also derived from another class, i.e. a class having
more than one parent class but at different levels, such type of inheritance is called Multilevel
Inheritance.
If we talk about the flowchart, class B inherits the properties and behavior of class A and class C
inherits the properties of class B. Here A is the parent class for B and class B is the parent class
17
for C. So, in this case class C implicitly inherits the properties and methods of class A along with
Class B. That’s what is multilevel inheritance.
Fig-4
Class A{
---
}
Class B extends A{
---
}
Class C extends B{
---
}
3. Hierarchical Inheritance
When a class has more than one child classes (sub classes) or in other words, more than one child
classes have the same parent class, then such kind of inheritance is known as hierarchical.
If we talk about the flowchart, Class B and C are the child classes which are inheriting from the
parent class i.e. Class A.
18
Fig-5
Class A{
---
}
Class B extends A{
---
}
Class C extends A{
---
}
4. Hybrid Inheritance
If we talk about the flowchart, class A is a parent class for class B and C, whereas Class B and C
are the parent class of D which is the only child class of B and C.
Fig-6
2. Encapsulation
19
Encapsulation is a mechanism where you bind your data and code together as a single unit. It
also means to hide your data in order to make it safe from any modification. What does this
mean? The best way to understand encapsulation is to look at the example of a medical capsule,
where the drug is always safe inside the capsule. Similarly, through encapsulation the methods
and variables of a class are well hidden and safe.
Fig-7
3. Abstraction
Abstraction refers to the quality of dealing with ideas rather than events. It basically deals with
hiding the details and showing the essential things to the user. If you look at the image here,
whenever we get a call, we get an option to either pick it up or just reject it. But in reality, there
is a lot of code that runs in the background. So you don’t know the internal processing of how a
call is generated, that’s the beauty of abstraction. Therefore, abstraction helps to reduce
complexity. You can achieve abstraction in two ways:
a) Abstract Class
b) Interface
4. Polymorphism
Polymorphism means taking many forms, where ‘poly’ means many and ‘morph’ means forms.
It is the ability of a variable, function or object to take on multiple forms. In other words,
polymorphism allows you define one interface or method and have multiple implementations.
There are various reserve words that Java provides to do different types of operations.
Keywords are reserved words whose meanings are already known to Java compiler. There are
two essential keywords in Java that are used for very special purposes
20
What is static keyword in Java?
Static is a keyword that acts as a non-access modifier in Java that is used mainly to manage
memory. The variable or Method that are marked static belongs to the Class rather than to any
particular instance. A Static method cannot access an instance variable. If a Class contains any
static blocks, then that block will be executed only when the Class is loaded in JVM.
Programmers can apply the Java keyword static with different programming objects like:
variables
methods
initialization - block
nested class
Class
Constructor
Local inner classes
Inner class methods
Instance variables
Local variables
Interfaces
Static variables or methods can be invoked without having an instance of the class. Only a class
is needed to call up a static method or a static variable. If you declare any variable as static, it is
known static variable. The static variable can refer to a common property of all objects (that is
not unique for each object), e.g. company name of employees, college name of students, etc.
Memory in a static variable is reserved only once in a class area at the time of class loading.
One advantage of using static is that it increases the efficiency of the memory.
Program for static in Java
21
What is this keyword in Java?
this is another Java keyword which as a reference to the current object within an instance
method or a constructor — the object whose method or constructor is being called. By the use
of this keyword, programmers can refer to any member of the current object within an instance
method or a constructor. This keyword can be used to refer to the current object, and it always
acts as a reference to an object in which method was invoked. There are the various uses of this
keyword in Java. These are:
For referring current class instance variable, this keyword can be used
To invoke current class constructor, this() is used
this can be passed as message argument in a method call
In a constructor call, this can be passed as argument
For returning current class instance, this keyword is used
Super is a keyword of Java which refers to the immediate parent of a class and is used inside
the subclass method definition for calling a method defined in the superclass. A superclass
having methods as private cannot be called. Only the methods which are public and protected
22
can be called by the keyword super. It is also used by class constructors to invoke constructors
of its parent class.
Syntax:
super.<method-name>();
Usage of super
Super variables refer to the variable of a variable of the parent class.
Super() invokes the constructor of immediate parent class.
Super refers to the method of the parent class.
Class
Methods
Variables
When a class is declared as final, it cannot be extended further. Here is an example what
happens within a program
Example:
final class stud {
// Methods cannot be extended to its sub class
}
class books extends stud {
void show() {
System.out.println("Book-Class method");
}
public static void main(String args[]) {
books B1 = new books();
B1.show();
}
23
class books extends stud{
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.
Declaring a method in the subclass which already exists there in the parent class is known as
method overriding. When a class is inheriting a method from a superclass of its own, then there
is an option of overriding the method provided it is not declared as final. The advantage of
using overriding is the ability to classify a behavior that's specific to the child class, and the
child class can implement a parent class method based on its necessity.
There are certain rules that a programmer should follow to implement overriding. These are:
24
In Java, a method can only be written in the child class and not in same class.
Argument list should be the same as that of the overridden method of that class.
Instance methods can also be overridden if they are inherited by the child class.
A constructor cannot be overridden.
Final - declared methods cannot be overridden.
Any method that is static cannot be used to override.
The return type must have to be the same, or a subtype of the return type declared in the
original overridden method in the parent class.
If a method cannot be inherited, then it cannot be overridden.
A child class within the same package as the instance's parent class can override any parent
class method that is not declared private or final.
A child class in a different package can only override the non-final methods declared as
public or protected.
Java Packages
It is repeatedly said that one of the main features of the Object Oriented Programming is the
ability to reuse the code already written by the programmer. One way of achieving is by
extending class and using the interface. It has a limitation. What will you have to do if you have
to use a class from another program without physically copying them into the program at the
time of development? So another way of achieving the concept of reusability in Java is via the
use of Packages.
Packages in Java are groups of similar types of classes, interface and sub packages. It is a way
of grouping a variety of classes or interfaces collectively. The grouping is usually done
according to functionality. The Java packages act as containers for Java classes.
1. The classes contained in the packages of another program can be easily reused.
2. Packages also allow programmers to separate design from coding.
3. In packages, classes can be declared uniquely compared with classes in other packages.
25
4. Java Packages provide a way to 'hide' classes thus preventing other programs or packages
from accessing classes that are meant for internal use only.
5. Packages provide access protection.
6. Java package removes naming collision.
For most applications, programmers need to use different sets of classes, one for the internal
representation of program's data and other for the external presentation purposes. You may
build your classes for handling your program data and use existing class libraries for designing
class libraries for designing the user interface.
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.
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 use exception
handling. Let's take a scenario:
1. statement 1;
2. statement 2;
3. statement 3;
4. statement 4;
5. statement 5;//exception occurs
6. statement 6;
7. statement 7;
8. statement 8;
9. statement 9;
10. statement 10;
Suppose there are 10 statements in your program and there occurs an exception at statement 5,
the rest of the code will not be executed i.e. statement 6 to 10 will not be executed. If we perform
exception handling, the rest of the statement will be executed. That is why we use exception
handling in Java.
27
Fig-8
28
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
Fig-9
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
29
Keyword Description
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.
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.
Tab-1
Let's see an example of Java Exception Handling where we using a try-catch statement to
handle the exception.
30
1) A scenario where ArithmeticException occurs
1. int a=50/0;//ArithmeticException
If we have a null value in any variable, performing any operation on the variable throws a
NullPointerException.
1. String s=null;
2. System.out.println(s.length());//NullPointerException
The wrong formatting of any value may occur NumberFormatException. Suppose I have a string
variable that has characters, converting this variable into digit will occur
NumberFormatException.
1. String s="abc";
2. int i=Integer.parseInt(s);//NumberFormatException
If you are inserting any value in the wrong index, it would result in
ArrayIndexOutOfBoundsException as shown below:
Java try block is used to enclose the code that might throw an exception. It must be used within
the method.
Java catch block is used to handle the Exception. It must be used after the try block only.
31
You can use multiple catch block with a single try.
Fig-10
The JVM firstly checks whether the exception is handled or not. If exception is not handled, JVM
provides a default exception handler that performs the following tasks:
But if exception is handled by the application programmer, normal flow of the application is
maintained i.e. rest of the code is executed.
32
Project
Introduction
Purpose
Scope
It can be used in any Hospital, Clinic, Dispensary or Pathology labs for maintaining patient
details.
33
Background
A Hospital is a place where Patients come up for general diseases. Hospitals provide facilities
like: -
Consultation by Doctors on Diseases.
Diagnosis for diseases.
Providing treatment facility.
Facility for admitting Patients (providing beds, nursing, medicines etc.)
Immunization for Patients/Children.
These are the various jobs that need to be done in a Hospital by the operational staff and
Doctors. All these works are done on papers.
All this work is done manually by the receptionist and other operational staff and lot of
papers are needed to be handled and taken care of.
34
User Characteristics
Constraints
GUI is only in English.
Login and password are used for identification of user and there is no facility for guest.
Data Tables
35
3. Patient Information Table
5. Patient Diagnosis
36
DFD
Fig-11
PID: Patient Id allotted during Patient registration
37
Snapshots
1. Homepage
Fig-12
2. Desk Login
Fig-13
38
3. Doctor Login
Fig-14
4. Register New Patient
Fig-15
39
5. View Patients
Fig-16
6. View Diagnostics
Fig-17
40
Conclusion
The project Hospital Management System is for computerizing the working in a hospital. The
software takes care of all the requirements of an average hospital and is capable to provide easy
and effective storage of information related to patients that come up to the hospital, provide
prescription details.
41