Industrial Training Report (Abhishek Ray) 901
Industrial Training Report (Abhishek Ray) 901
Industrial Training Report (Abhishek Ray) 901
ON
CORE JAVA
UNDERTAKEN
Central Tool Room & Training Centre , Bhubanswar
I am grateful to Central Tool Room & Training Centre , Bhubanswar for giving me
opportunity to Industrial Training & Advanced Software Training. I would like to also thank
my institute, Rajkiya Engineering College , Kannauj for giving permission and necessary
administrative support to take up the training work at Central Tool Room & Training Centre ,
Bhubanswar .
Deepest thanks to our Trainer Mrs. Niharika Pattnaik (Senior Trainer) for his guidance,
monitoring, constant encouragement and correcting various assignments of ours with attention
and care. He has taken pain to go through the project and training sessions and make necessary
Abhishek Ray
1783910901
CONTENT
1. Acknowledgement
2. Certificate
3. Introduction
4. Application
5. History of Java
6. Features of Java
7. Java virtual Machine Architecture
8. Java Variable
9. Data Types in Java
10. Oprators in Java
11. Loops in Java
12. Java Object Oriented
13. multithreading in Java
14. Java I/O
15. Java Read Class
16. Java Write Class
17. Java Buffered Write Class
18. Java Swing
19. Java JDBC
20. Conclusions
Introduction
What is Java
Java was originally developed by James Gosling at Sun Microsystems (which has since been
acquired by Oracle with the specifications of the Java Community Process, Sun
had relicensed most of its Java technologies under the GNU General Public License.
Meanwhile, others have developed alternative implementations of these Sun technologies,
such as the GNU Compiler for Java (bytecode compiler), GNU Class path (standard
libraries), and Iced Tea-Web (browser plugin for applets).
Application
According to Sun, 3 billion devices run Java. There are many devices where Java is currently
used. Some of them are as follows:
Java was originally designed for interactive television, but it was too advanced technology
for the digital cable television industry at the time. The history of java starts with Green
Team. Java team members (also known as Green Team), initiated this project to develop a
language for digital devices such as set-top boxes, televisions, etc. However, it was suited for
internet programming. Later, Java technology was incorporated by Netscape.
The principles for creating Java programming were "Simple, Robust, Portable, Platform-
independent, Secured, High Performance, Multithreaded, Architecture Neutral, Object-
Oriented, Interpreted and Dynamic".
Currently, Java is used in internet programming, mobile devices, games, e-business solutions,
etc. There are given the significant points that describe the history of Java.
2) Originally designed for small, embedded systems in electronic appliances like set-top
boxes.
3) Firstly, it was called "Green talk" by James Gosling, and file extension was .gt.
4) After that, it was called Oak and was developed as a part of the Green project.
5) Why Oak? Oak is a symbol of strength and chosen as a national tree of many countries
like U.S.A., France, Germany, Romania, etc.
6) In 1995, Oak was renamed as "Java" because it was already a trademark by Oak
Technologies.
7) Why had they chosen java name for java language? The team gathered to choose a new
name. The suggested words were "dynamic", "revolutionary", "Silk", "jolt", "DNA", etc.
They wanted something that reflected the essence of the technology: revolutionary, dynamic,
lively, cool, unique, and easy to spell and fun to say.
According to James Gosling, "Java was one of the top choices along with Silk". Since Java
was so unique, most of the team members preferred Java than other names.
8) Java is an island of Indonesia where first coffee was produced (called java coffee).
11) In 1995, Time magazine called Java one of the Ten Best Products of 1995.
Many java versions have been released till now. The current stable release of Java is Java SE
10.
.
The traditional Hello world program can be written in Java as:
public class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Prints the string to the console.
}
}
Features of Java
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic
Simple
Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to
Sun, Java language is a simple programming language because:
o Java syntax is based on C++ (so easier for programmers to learn it after C++).
o Java has removed many complicated and rarely-used features, for example, explicit
pointers, operator overloading, etc.
o There is no need to remove unreferenced objects because there is an Automatic
Garbage Collection in Java.
Object-oriented
1. Object
2. Class
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
Platform Independent
Java is platform independent because it is different from other languages like C, C++, etc.
which are compiled into platform specific machines while Java is a write once, run anywhere
language. A platform is the hardware or software environment in which a program runs.
There are two types of platforms software-based and hardware-based. Java provides a
software-based platform.
The Java platform differs from most other platforms in the sense that it is a software-based
platform that runs on the top of other hardware-based platforms. It has two components:
1. Runtime Environment
2. API(Application Programming Interface)
Java code can be run on multiple platforms, for example, Windows, Linux, Sun Solaris, Mac/
OS, etc. Java code is compiled by the compiler and converted into bytecode. This bytecode is
a platform-independent code because it can be run on multiple platforms, i.e., Write Once and
Run Anywhere(WORA).
Secured
Java is best known for its security. With Java, we can develop virus-free systems. Java is
secured because:
o Class loader: Class loader in Java is a part of the Java Runtime Environment (JRE)
which is used to load Java classes into the Java Virtual Machine dynamically. It adds
security by separating the package for the classes of the local file system from those
that are imported from network sources.
o Bytecode Verifier: It checks the code fragments for illegal code that can violate
access right to objects.
o Security Manager: It determines what resources a class can access such as reading
and writing to the local disk.
Java language provides these securities by default. Some security can also be provided by an
application developer explicitly through SSL, JAAS, Cryptography, etc.
Robust
Architecture-neutral
Java is architecture neutral because there are no implementation dependent features, for
example, the size of primitive types is fixed.
In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4
bytes of memory for 64-bit architecture. However, it occupies 4 bytes of memory for both 32
and 64-bit architectures in Java.
Portable
Java is portable because it facilitates you to carry the Java bytecode to any platform. It doesn't
require any implementation.
High-performance
Java is faster than other traditional interpreted programming languages because Java
bytecode is "close" to native code. It is still a little bit slower than a compiled language (e.g.,
C++). Java is an interpreted language that is why it is slower than compiled languages, e.g.,
C, C++, etc.
Comparison Index C++ Java
Mainly used for C++ is mainly used for Java is mainly used for application programming. It is widely
system programming. used in window, web-based, enterprise and mobile
applications.
Design Goal C++ was designed for Java was designed and created as an interpreter for printing
systems and systems but later extended as a support network computing. It
applications was designed with a goal of being easy to use and accessible
programming. It was to a broader audience.
an extension of C
programming
language.
Goto C++ supports the go Java doesn't support the goto statement.
to statement.
Multiple C++ supports multiple Java doesn't support multiple inheritance through class. It can
inheritance inheritance. be achieved by interfaces in java.
Pointers C++ supports pointers. Java supports pointer internally. However, you can't write the
You can write pointer pointer program in java. It means java has restricted pointer
program in C++. support in java.
Compiler and C++ uses compiler Java uses compiler and interpreter both. Java source code is
Interpreter only. C++ is compiled converted into bytecode at compilation time. The interpreter
and run using the executes this bytecode at runtime and produces output. Java is
compiler which interpreted that is why it is platform independent.
converts source code
into machine code so,
C++ is platform
dependent.
Call by Value and C++ supports both call Java supports call by value only. There is no call by reference
Call by reference by value and call by in java.
reference.
Structure and C++ supports Java doesn't support structures and unions.
Union structures and unions.
Documentation C++ doesn't support Java supports documentation comment (/** ... */) to create
comment documentation documentation for java source code.
comment.
Virtual Keyword C++ supports virtual Java has no virtual keyword. We can override all non-static
keyword so that we methods by default. In other words, non-static methods are
can decide whether or virtual by default.
not override a
function.
unsigned right C++ doesn't support Java supports unsigned right shift >>> operator that fills zero
shift >>> >>> operator. at the top for the negative numbers. For positive numbers, it
works same like >> operator.
Inheritance Tree C++ creates a new Java uses a single inheritance tree always because all classes
inheritance tree are the child of Object class in java. The object class is the
always. root of the inheritance tree in java.
Distributed
Java is distributed because it facilitates users to create distributed applications in Java. RMI
and EJB are used for creating distributed applications. This feature of Java makes us able to
access files by calling the methods from any machine on the internet.
Multi-threaded
A thread is like a separate program, executing concurrently. We can write Java programs that
deal with many tasks at once by defining multiple threads. The main advantage of multi-
threading is that it doesn't occupy memory for each thread. It shares a common memory area.
Threads are important for multi-media, Web applications, etc.
Dynamic
Java is a dynamic language. It supports dynamic loading of classes. It means classes are
loaded on demand. It also supports functions from its native languages, i.e., C and C++.
Java supports dynamic compilation and automatic memory management (garbage collection).
C++ vs Java
JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime
environment in which java bytecode can be executed.
JVMs are available for many hardware and software platforms (i.e. JVM is platform
dependent).
What is JVM
Java Variables
A variable is a container which holds the value while the java program is executed. A
variable is assigned with a datatype.
Variable is a name of memory location. There are three types of variables in java: local,
instance and static.
There are two types of data types in java: primitive and non-primitive.
Variable
1. int data=50;//Here data is variable
Types of Variables
o local variable
o instance variable
o static variable
1) Local Variable
A variable declared inside the body of the method is called local variable. You can use this
variable only within that method and the other methods in the class aren't even aware that the
variable exists.
A variable declared inside the class but outside the body of the method, is called instance
variable. It is not declared as static.
It is called instance variable because its value is instance specific and is not shared among
instances.
3) Static variable
A variable which is declared as static is called static variable. It cannot be local. You can
create a single copy of static variable and share among all the instances of the class. Memory
allocation for static variable happens only once when the class is loaded in the memory.
class A{
int data=50;//instance variable
static int m=100;//static variable
void method(){
int n=90;//local variable
}
}//end of class
Data Types in Java
Data types specify the different sizes and values that can be stored in the variable. There are
two types of data types in Java:
1. Primitive data types: The primitive data types include boolean, char, byte, short, int,
long, float and double.
2. Non-primitive data types: The non-primitive data types include Classes, Interfaces,
and Arrays.
In Java language, primitive data types are the building blocks of data manipulation. These are
the most basic data types available in Java language.
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
Operators in java
Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc.
There are many types of operators in java which are given below:
o Unary Operator,
o Arithmetic Operator,
o Shift Operator,
o Relational Operator,
o Bitwise Operator,
o Logical Operator,
o Ternary Operator and
o Assignment Operator.
Operator Precedence
prefix ++expr --expr +expr -expr ~ !
additive +-
equality == !=
bitwise ^
exclusive OR
bitwise |
inclusive OR
logical OR ||
Ternary ternary ?:
o for loop
o while loop
o do-while loop
Object means a real-world entity such as a pen, chair, table, computer, watch, 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
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
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
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.
Class
public class Employee
{
//code snippet
}
Interface
interface Printable
{
//code snippet
}
Method
class Employee
{
//method
void draw()
{
//code snippet
}
}
Variable
o It should start with a lowercase letter such as id, name.
o It should not start with the special characters like & (ampersand), $ (dollar), _
(underscore).
o If the name contains multiple words, start it with the lowercase letter followed by an
uppercase letter such as first Name, last Name.
o Avoid using one-character variables such as x, y, z.
Example :-
class Employee
{
//variable
int id;
//code snippet
}
Package
package com.javatpoint; //package
class Employee
{
//code snippet
}
Constant
class Employee
{
//constant
static final int MIN_AGE = 18;
//code snippet
}
Multithreading in Java
1. Multithreading
2. Multitasking
3. Process-based multitasking
4. Thread-based multitasking
5. What is Thread
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.
1) It doesn't block the user because threads are independent and you can perform multiple
operations at the same time.
Multitasking
o Each process has an address in memory. In other words, each process allocates a
separate memory area.
o A process is heavyweight.
o Cost of communication between the process is high.
o Switching from one process to another requires some time for saving and loading
registers, memory maps, updating lists, etc.
A thread is a lightweight sub process, the smallest unit of processing. It is a separate path of
execution.
Threads are independent. If there occurs exception in one thread, it doesn't affect other
threads. It uses a shared memory area.
As shown in the above figure, a thread is executed inside the process. There is context-
switching between the threads. There can be multiple processes inside the OS, and one
process can have multiple threads.
Java I/O (Input and Output) is used to process the input and produce the output.
Java uses the concept of a stream to make I/O operation fast. The java.io package contains all
the classes required for input and output operations.
Stream
A stream is a sequence of data. In Java, a stream is composed of bytes. It's called a stream
because it is like a stream of water that continues to flow.
In Java, 3 streams are created for us automatically. All these streams are attached with the
console.
1. System.out.println("simple message");
2. System.err.println("error message");
1. int i=System.in.read();//returns ASCII code of 1st character
2. System.out.println((char)i);//will print the character
Do You Know?
o How to write a common data to multiple files using a single stream only?
o How can we access multiple files by a single stream?
o How can we improve the performance of Input and Output operation?
o How many ways can we read data from the keyboard?
o What does the console class?
o How to compress and un compress the data of a file?
The explanation of Output Stream and Input Stream classes are given below:
Output Stream
Java application uses an output stream to write data to a destination; it may be a file, an array,
peripheral device or socket.
Input Stream
Java application uses an input stream to read data from a source; it may be a file, an array,
peripheral device or socket.
Let's understand the working of Java Output Stream and Input Stream by the figure given
below.
Method Description
1) public void write(int)throws IOException is used to write a byte to the current output
stream.
2) public void write(byte[])throws IOException is used to write an array of byte to the current
output stream.
4) public void close()throws IOException is used to close the current output stream.
InputStream class is an abstract class. It is the superclass of all classes representing an input
stream of bytes.
Method Description
1) public abstract int read()throws reads the next byte of data from the input stream.
IOException It returns -1 at the end of the file.
2) public int available()throws returns an estimate of the number of bytes that can be
IOException
read from the current input stream.
3) public void close()throws IOException is used to close the current input stream.
12) static yield() It causes the currently executing thread object to pause and
void allow other threads to execute temporarily.
16) void destroy() It is used to destroy the thread group and all of its subgroups.
21) static interrupted() It tests whether the current thread has been interrupted.
boolean
22) static int active It returns the number of active threads in the current thread's
Count() thread group.
23) void check It determines if the currently running thread has permission
Access() to modify the thread.
24) static hold Lock() It returns true if and only if the current thread holds the
boolean monitor lock on the specified object.
25) static dump It is used to print a stack trace of the current thread to the
void Stack() standard error stream.
26) Stack get Stack It returns an array of stack trace elements representing the
Trace Trace() stack dump of the thread.
Element
[]
27) static int enumerate() It is used to copy every active thread's thread group and its
subgroup into the specified array.
28) Thread . get State() It is used to return the state of the thread.
State
29) Thread get Thread It is used to return the thread group to which this thread
Group Group() belongs
30) String to String() It is used to return a string representation of this thread,
including the thread's name, priority, and thread group.
31) void notify() It is used to give the notification for only one thread which is
waiting for a particular object.
32) void notify All() It is used to give the notification to all waiting threads of a
particular object.
33) void set Context It sets the context Class Loader for the Thread.
Class
Loader()
34) Class get Context It returns the context Class Loader for the thread.
Loader Class
Loader()
35) static get Default It returns the default handler invoked when a thread abruptly
Thread. Uncaught terminates due to an uncaught exception.
Un Exception
caught Handler()
Excepti
on
Handler
36) static set Default It sets the default handler invoked when a thread abruptly
void Uncaught terminates due to an uncaught exception.
Exception
Handler()
Java Writer
It is an abstract class for writing to character streams. The methods that a subclass must
implement are write(char[], int, int), flush(), and close(). Most subclasses will override some
of the methods defined here to provide higher efficiency, functionality or both.
import java.io.*;
public class WriterExample {
public static void main(String[] args) {
try {
Writer w = new FileWriter("output.txt");
String content = "I love my country";
w.write(content);
w.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Java Reader
Some of the
implementation class are BufferedReader, CharArrayReader, FilterReader, InputStreamRead
er, PipedReader, StringReader
import java.io.*;
public class ReaderExample {
public static void main(String[] args) {
try {
Reader reader = new FileReader("file.txt");
int data = reader.read();
while (data != -1) {
System.out.print((char) data);
data = reader.read();
}
reader.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
Java Buffered Writer Class
Java Buffered Writer class is used to provide buffering for Writer instances. It makes the
performance fast. It inherits Writer class. The buffering characters are used for providing the
efficient writing of single arrays, characters, and strings.
Java Swing
Java Swing tutorial is a part of Java Foundation Classes (JFC) that is used to create
window-based applications. It is built on the top of AWT (Abstract Windowing Toolkit) API
and entirely written in java.
The j avax. swing package provides classes for java swing API such as J Button, J Text Field,
J Text Area, J Radio Button, J Check box, J Menu, J Color Chooser etc.
Java JDBC
JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and execute the
query with the database. It is a part of Java SE (Java Standard Edition). JDBC API uses
JDBC drivers to connect with the database. There are four types of JDBC drivers:
We can use JDBC API to access tabular data stored in any relational database. By the help of
JDBC API, we can save, update, delete and fetch data from the database. It is like Open
Database Connectivity (ODBC) provided by Microsoft.
The current version of JDBC is 4.3. It is the stable release since 21st September, 2017. It is
based on the X/Open SQL Call Level Interface. The java. sql package contains classes and
interfaces for JDBC API.
Before JDBC, ODBC API was the database API to connect and execute the query with the
database. But, ODBC API uses ODBC driver which is written in C language (i.e. platform
dependent and unsecured). That is why Java has defined its own API (JDBC API) that uses
JDBC drivers (written in Java language).
JDBC drivers
JDBC Driver is a software component that enables java application to interact with the
database.
There are 4 types of JDBC drivers
1. JDBC-ODBC bridge driver
2. Native-API driver
3. Network Protocol driver
4. Thin driver
CONCLUSIONS
Practical knowledge means the visualization of the knowledge, which we read in our books. For
this, we perform experiments and get observations. Practical knowledge is very important in every
field. One must be familiar with the problems related to that field so that he may solve them and
become a successful person.
After achieving the proper goal in life, an engineer has to enter in professional life.
According to this life, he has to serve an industry, may be public or private sector or self-own. For
the efficient work in the field, he must be well aware of the practical knowledge as well as
theoretical knowledge.
Due to all above reasons and to bridge the gap between theory and practical, our
Engineering curriculum provides a practical training of 4 Weeks. During this period
a student work in the industry and get well all type of experience and knowledge
about the working of companies and hardware and software tools.
I have undergone my 4 weeks summer training in at Central Tool Room & Training Centre
This report is based on the knowledge, which I acquired during my 4 weeks of summer
training.