Professional Documents
Culture Documents
JAVA SE Platform 8
Training Report Submitted in Partial Fulfillment of BE IT Final Year
Bachelor of Engineering
in
Information Technology
Submitted by
Parth Agarwal: 16ITE38023
The satisfaction that accompanies that the successful completion of any task would be
incomplete without the mention of people whose ceaseless cooperation made it possible, whose
constant guidance and encouragement crown all efforts with success.
We are grateful to our training guide Mr. Shaikh Alfozen for the guidance, inspiration and
constructive suggestions that helpful us understanding this language better.
We also thank our colleagues who have helped in successful completion of this training.
1. Introduction ……………………………………………………………………………………….. 3
2. History………………………………………………………………………………………………… 4
3. Basics of JAVA…………………………………………………………………………………….. 5
5. OOPS Concepts…………………………………………………………………………………… 17
8. Applets…………………………………………………………………... 31
9. Project Undertaken…………………………………………………….. 33
Conclusion
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 there team. Originally SUN Micro Systems is one of the Academic university
(Standford 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.
J2SE
J2SE is used for developing client side applications.
J2EE
J2EE is used for developing server side applications.
J2ME
J2ME is used for developing mobile or wireless application by making use of a predefined
protocol called WAP (wireless Access / Application protocol).
Sun Microsystems released the first public implementation as Java 1.0 in 1996. It promised
"Write Once, Run Anywhere" (WORA), providing no-cost run-times on popular platforms.
Major web browsers soon incorporated the ability to run Java applets within web pages, and
Java quickly became popular. The Java 1.0 compiler was re-written in Java by Arthur van Hoff
to comply strictly with the Java 1.0 language specification. With the advent of Java 2 (released
initially as J2SE 1.2 in December 1998 – 1999), new versions had multiple configurations built
for different types of platforms. J2EE included technologies and APIs for enterprise applications
typically run in server environments, while J2ME featured APIs optimized for mobile
applications. The desktop version was renamed J2SE. In 2006, for marketing purposes, Sun
renamed new J2 versions as Java EE, Java ME, and Java SE, respectively.
In 1997, Sun Microsystems approached the ISO/IEC JTC 1 standards body and later the Ecma
International to formalize 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.
On November 13, 2006, Sun released much of its Java virtual machine (JVM) as free and open-
source software, (FOSS), under the terms of the GNU General Public License (GPL). On May 8,
2007, Sun finished the process, making all of its JVM's core code available under free
software/open-source distribution terms, aside from a small portion of code to which Sun did not
hold the copyright.
Sun's vice-president Rich Green said that Sun's ideal role with regard to Java was as an
"evangelist".Following Oracle Corporation's acquisition of Sun Micro-systems in 2009–10,
Oracle has described itself as the "steward of Java technology with a relentless commitment to
fostering a community of participation and transparency". This did not prevent Oracle from
filing a lawsuit against Google shortly after that for using Java inside the Android SDK (see
Google section below). Java software runs on everything from laptops to data centers, game
consoles to scientific supercomputers. On April 2, 2010, James Gosling resigned from Oracle.
In January 2016, Oracle announced that Java run-time environments based on JDK 9 will
discontinue the browser plugin.
Define JRE
The Java Runtime Environment (JRE) is part of the Java Development Kit (JDK). It
contains set of libraries and tools for developing java application. The Java Runtime
Environment provides the minimum requirements for executing a Java application.
Define JVM
JVM is set of programs developed by sun Micro System and supplied as a part of jdk for
reading line by line of byte code and it converts into native understanding form of operating
system. Java language is one of the compiled and interpreted programming language.
Garbage Collector
Garbage Collector is the system Java program which runs in the background along with
regular Java program to collect un-Referenced (unused) memory space for improving the
performance of our applications.
Define an API
An API (Application Programming Interface) is a collection of packages, a package is the
collection of classes, interfaces and sub-packages. A sub-package is a collection of classes
interfaces and sub sub packages etc.
Java programming is containing user friendly syntax so that we can develop effective
application s. in other words if any language is providing user friendly syntax, we can develop
error free applications.
Definition of JIT
JIT is the set of programs developed by SUN Micro System and added as a part of JVM, to
speed up the interpretation phase
Path Variable
Path variable is set for providing path for all java tools like java, javac, javap, javah, jar,
appletviewer which are use in java programming. These all tools are available in bin folders
so we set path upto bin folders.
Classpath Variable
Classpath variable is set for providing path for predefined java classes which is used in our
application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.
JVM : JVM (Java Virtual Machine) is a software. It is a specification that provides runtime
environment in which java bytecode can be executed. It not physically exists.JVMs are not
same for all hardware and software, for example for window os JVM is different and for Linux
VJM is different. JVM, JRE and JDK are platform dependent because configuration of each OS
differs. But, Java is platform independent.
JRE : The Java Runtime Environment (JRE) is part of the Java Development Kit (JDK). It
contains set of libraries and tools for developing java application. The Java Runtime
Environment provides the minimum requirements for executing a Java application. It physically
exists. It contains set of libraries + other files that JVM uses at runtime.
JDK : The Java Development Kit (JDK) is primary components. It physically exists. It is
collection of programming tools and JRE, JVM.
Byte 0 1 byte
Short 0 2 byte
Int 0 4 byte
Long 0L 8 byte
Variable
Variable is an identifier which holds data or another one variable is an identifier whose value
can be changed at the execution time of program. Variable is an identifier which can be used
to identify input data in a program.
4.1 Downloading
Following are steps to install Java in Windows
Step 1) Go to official website of Oracle. Click on Download JDK. For java latest version.
Step 2) Next,
Let's look into the steps to set the PATH and CLASSPATH
Step 7) Paste Path of bin folder in Variable value and click on OK Button.
Note: In case you already have a PATH variable created in your PC, edit the PATH variable to
Here, %PATH% appends the existing path variable to our new value
class class_name
{
type instance-variable1;
type instance-variable2;
type method-name(parameter-list){
//body of method
}
}
To work with OOP, you should be able to identify three key characteristics of objects:
• The object’s behavior—What can you do with this object, or what methods can you apply to it?
• The object’s state—How does the object react when you apply those methods?
• The object’s identity—How is the object distinguished from others that may have the same
behavior and state?
5.4 Inheritance
When one class inherits from another , it is called Inheritance.
The class which is inherited is called superclass and the class which inherits is called
subclass.
So we can say that subclass extends superclass but subclass can add new methods and
instance variables of its own and it can override the methods of superclass.
Example :
Any number of classes can implement an interface, also one class can implement any
number of interfaces.
Defining an Interface:
Implementing an interface:
returntype method1(){
//body
returntype method2(){
// body
Syntax:
5.6 Polymorphism
It describes the ability of the object in belonging to different types with specific behavior
of each type.
It can be done by two ways:
Overloading
Overriding
Overloading
An overloaded method is just a different method that happens to have the same method
name.
An overloaded method is NOT the same as an overridden method.
The returntype can be different.
The number of parameters can be different.
Datatype of parameters can also be different.
Example
Overriding
An instance method in a subclass with the same signature and returntypes as an instance
method in the superclass overrides the siperclass’s method.
The overriding method has same name , numer and types of parameters and return types
as the method it overrides.
If a subclass defines a method with same signature as a class method in the superclass ,
the method in subclass hides the one in superclass.
5.7 Encapsulation
Encapsulation is the concept of hiding the implementation details of a class and allowing access
to the class through a public interface. For this, we need to declare the instance variables of the
class as private or protected.
The client code should access only the public methods rather than accessing the data directly.
Also, the methods should follow the Java Bean's naming convention of set and get.
Encapsulation makes it easy to maintain and modify code. The client code is not affected when
the internal implementation of the code changes as long as the public method signatures are
unchanged. For instance:
We know that every java program must start with a concept of class that is without classes
concept there is no java program perfect.In java programming we have two types of classes they
are
1. Concrete class
2. Abstract class
A constructor is a special member method which will be called implicitly (automatically) by the
JVM whenever an object is created for placing user or programmer defined values in place of
default values. In a single word constructor is a special member method which will be called
automatically whenever object is created.
The purpose of constructor is to initialize an object called object initialization. Constructors are
mainly create for initializing the object. Initialization is a process of assigning user defined values
at the time of allocation of memory space.
Types of constructors
Based on creating objects in Java constructor are classified in two types. They are
Parameterized constructor.
In a class we can take any number of static block but all these static block will be execute from top
to bottom.
Type of relationship always makes to understand how to reuse the feature from one class to
another class. In java programming we have two types of relationship they are.
Is-A Relationship
Has-A Relationship
Example
class Rectangle{
int length,breadth;
void show(int length,int breadth){
this.length=length;
this.breadth=breadth;
}
int calculate(){
return(length*breadth);
}
}
public class UseOfThisOperator{
public static void main(String[] args){
Rectangle rectangle=new Rectangle();
rectangle.show(5,6);
Output:
C:\java>java UseOfThisOperator
The area of a Rectangle is : 30
Exception, that means exceptional errors. Actually exceptions are used for handling errors in
programs that occurs during the program execution. During the program execution if any error
occurs and you want to print your own message or the system message about the error then you
write the part of the program which generate the error in the try{} block and catch the errors
using catch() block. Exception turns the direction of normal flow of the program control and
send to the related catch() block. Error that occurs during the program execution generate a
specific object which has the information about the errors occurred in the program.
Example:
Output:
1
2
3
4
5
6
7
8
9
10
It is simple to make it work on Linux, Windows and Mac OS i.e. to make it cross
platform. Applets are supported by most web browsers
Applets also improve with use: after a first applet is run, the JVM is already running and
starts quickly (JVM will need to restart each time the browser starts fresh).
It can move the work from the server to the client, making a web solution more scalable
with the number of users/clients
The applet naturally supports the changing user state like figure positions on the
chessboard.
Example:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
import java.io.*;
public Notepad() {
this.setSize(500, 300); // set the initial size of the window
this.setTitle("Java Notepad Tutorial"); // set the title of the window
setDefaultCloseOperation(EXIT_ON_CLOSE); // set the default close operation
(exit when it gets closed)
this.textArea.setFont(new Font("Century Gothic", Font.BOLD, 12)); // set a
default font for the TextArea
// this is why we didn't have to worry about the size of the TextArea!
// first off, the design of the menuBar itself. Pretty simple, all we need to do
// is add a couple of menus, which will be populated later on
this.file.setLabel("File");
// now it's time to work with the menu. I'm only going to add a basic File menu
// but you could add more!
// now we can start working on the content of the menu~ this gets a little
repetitive,
// so please bare with me!
// time for the repetitive stuff. let's add the "Open" option
this.openFile.setLabel("Open"); // set the label of the menu item
this.openFile.addActionListener(this); // add an action listener (so we know when
it's been clicked
this.openFile.setShortcut(new MenuShortcut(KeyEvent.VK_O, false)); // set a
keyboard shortcut
this.file.add(this.openFile); // add it to the "File" menu
// and lastly, if the source of the event was the "save" option
else if (e.getSource() == this.saveFile) {
JFileChooser save = new JFileChooser(); // again, open a file chooser
int option = save.showSaveDialog(this); // similar to the open file, only
this time we call
// showSaveDialog instead of showOpenDialog
// if the user clicked OK (and not cancel)
if (option == JFileChooser.APPROVE_OPTION) {
try {
// create a buffered writer to write to a file
BufferedWriter out = new BufferedWriter(new
FileWriter(save.getSelectedFile().getPath()));
out.write(this.textArea.getText()); // write the contents of
the TextArea to the file
out.close(); // close the file stream
} catch (Exception ex) { // again, catch any exceptions and...
// ...write to the debug console
System.out.println(ex.getMessage());
}
}
}
}
// the main method, for actually creating our notepad and setting it to visible.
}
}
2. Main.java
import notepad.*;
public class main
{
public static void main(String args[]){
Notepad app=new Notepad();
app.setVisible(true);
}
}