You are on page 1of 19

A

PRACTICAL TRAINING REPORT


ON

“CORE JAVA”
Submitted in partial fulfillment for the award of Bachelor Of
Technology degree
Of the Bikaner Technical University, Kota

Approved By AICTE & Affiliated to Bikaner Technical University, Kota


SESSION 2019-2023

Rahul Sharma

19EBKIT025

DEPARTMENT OF INFORMATION TECHNOLOGY ENGG.

BKBIET,PILANI

Bikaner Technical University


2022
CERTIFICATE
ACKNOWLEDGEMENT

I am grateful to BKBIET,for permitting me to undergo for a minor project for the


development of an expert system. While developing this project, I have learnt a lot.
This will be an un-forgetful experience. While developing this project, a lot of
difficulties were faced by me. But it was the help of some special people that I have
gained much confidence and developed the project quite well.

I would like to thank all the lecturers of Udemy to co-ordinate with me and provide
me the information needed to complete the analysis part of this project.

(RAHUL SHARMA)

CONTENTS

Chapter 1: History

1.1 Principles

Chapter 2: Features of Java

2.1 Encapsulation

2.2 Java Platform


1
HISTORY
Duke, the Java mascotSee also: Java (Sun) history and Java version history. James
Gosling initiated the Java language project in June 1991 for use in one of his many
set-top box projects. The language, initially called Oak after an oak tree that stood
outside Gosling's office, also went by the name Green and ended up later renamed
as Java, from a list of random words.

Gosling aimed to implement a virtual machine and a language that had a familiar
C/C++ style of notation. Sun released the first public implementation as Java 1.0 in
1995. It promised "Write Once, Run Anywhere" (WORA), providing no-cost
runtimes on popular platforms. Fairly secure and featuring configurable security, it
allowed network- and file-access restrictions. Major web browsers soon incorporated
the ability to run Java applets within web pages, and Java quickly became popular.

With the advent of Java 2 (released initially as J2SE 1.2 in December 1998), new
versions had multiple configurations built for different types of platforms. For
example, J2EE targeted enterprise applications and the greatly stripped-down version
J2ME for mobile applications. J2SE designated the Standard Edition. 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 JTC1 standards body and later
the Ecma International to formalize Java, but it soon withdrew from the process. Java
remains a de facto standard, controlled through the Java Community 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.

Sun distinguishes between its Software Development Kit (SDK) and Runtime
Environment (JRE) (a subset of the SDK); the primary distinction involves the JRE's
lack of the compiler, utility programs, and header files. On 13 November 2006, Sun
released much of Java as open source software under the terms of the GNU General
Public License (GPL).

On 8 May 2007 Sun finished the process, making all of Java'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.

1.1What Is the Java Technology?


• Java technology is:
A programming language
A development environment
An application environment
A deployment environment
• It is similar in syntax to C++; similar in semantics to
SmallTalk
• It is used for developing both applets and applications

1.2PRIMARY GOALS OF THE JAVA TECHNOLOGY

• Provides an easy-to-use language by:


• Avoiding the pitfalls of other languages
• Being object-oriented
• Enabling users to create streamlined and clear code
• Provides an interpreted environment for:
• Improved speed of development
• Code portability
• Enables users to run more than one thread of activity
• Loads classes dynamically; that is, at the time they are actually needed
• Supports dynamically changing programs during runtime by loading classes
from disparate sources
• Furnishes better security
2
FEATURES OF JAVA
• Simple
• Secure
• Portable
• Object-oriented
• Robust
• Multithreaded
• Architecture-neutral
• Interpreted
• High performance
• Distributed
• Dynamic

SIMPLE

Java was designed to be easy for the professional programmer to learn and use
effectively. The basic concepts of object-oriented programming , make learning Java
easier. Beyond its similarities with C/C++, Java has another attribute that makes it
easy to learn: it makes an effort not to have surprising features.

SECURE

Every time that you download a “normal” program, you are risking a viral infection.
Prior to Java, most users did not download executable programs frequently, and those
who did scanned them for viruses prior to execution. Even so, most users still worried
about the possibility of infecting their systems with a virus. When you use a
Javacompatible Web browser, you can safely download Java applets without fear of
viral infection or malicious intent.

PORTABILITY

Many types of computers and operating systems are in use throughout the world and
many are connected to the Internet. For programs to be dynamically downloaded to all
the various types of platforms connected to the Internet, some means of generating
portable executable code is needed, which is provided by java.

OBJECT-ORIENTED

Java was not designed to be source-code compatible with any other language. This
allowed the Java team the freedom to design with a blank slate. One outcome of this
was a clean, usable, pragmatic approach to objects. The object model in Java is simple
and easy to extend, while simple types, such as integers, are kept as high-performance
non objects.
ROBUST

The multiplatformed environment of the Web places extraordinary demands on a


program, because the program must execute reliably in a variety of systems. Thus, the
ability to create robust programs was given a high priority in the design of Java. To
gain reliability, Java restricts you in a few key areas, to force you to find your
mistakes early in program development. At the same time, Java frees you from having
to worry about many of the most common causes of programming errors. Because
Java is a strictly typed language, it checks your code at compile time. However, it also
checks your code at run time. In fact, many hard-to-track-down bugs that often turn
up in hard-to-reproduce run-time situations are simply impossible to create in Java.
Knowing that what you have written will behave in a predictable way under diverse
conditions is a key feature of Java.

MULTITHREADED

Java was designed to meet the real-world requirement of creating interactive,


networked programs. To accomplish this, Java supports multithreaded programming,
which allows you to write programs that do many things simultaneously. The Java
run-time system comes with an elegant yet sophisticated solution for multiprocess
synchronization that enables you to construct smoothly running interactive systems.
Java’s easy-to-use approach to multithreading allows you to think about the specific
behavior of your program, not the multitasking subsystem.

ARCHITECTURE-NEUTRAL

A central issue for the Java designers was that of code longevity and portability. One
of the main problems facing programmers is that no guarantee exists that if you write
a program today, it will run tomorrow—even on the same machine. Operating system
upgrades, processor upgrades, and changes in core system resources can all combine
to make a program malfunction. The Java designers made several hard decisions in
the Java language and the Java Virtual Machine in an attempt to alter this situation.
Their goal was “write once; run anywhere, any time, forever.” To a great extent, this
goal was accomplished.

INTERPRETED AND HIGH PERFORMANCE

Java enables the creation of cross-platform programs by compiling into an


intermediate representation called Java bytecode. This code can be interpreted on any
system that provides a Java Virtual Machine. Most previous attempts at crossplatform
solutions have done so at the expense of performance

DISTRIBUTED

Java is designed for the distributed environment of the Internet, because it handles
TCP/IP protocols. In fact, accessing a resource using a URL is not much different
from accessing a file. The original version of Java (Oak) included features for
intraaddress-space messaging. This allowed objects on two different computers to
execute procedures remotely. Java revived these interfaces in a package called
Remote Method Invocation (RMI). This feature brings an unparalleled level of
abstraction to client/server programming.

DYNAMIC

Java programs carry with them substantial amounts of run-time type information that
is used to verify and resolve accesses to objects at run time. This makes it possible to
dynamically link code in a safe and expedient manner. This is crucial to the
robustness of the applet environment, in which small fragments of bytecode may be
dynamically updated on a running system.
3
SOFTWARE DEVELOPMENT USING JAVA
3.1WHAT IS A JAVA BEAN?

A Java Bean is a software component that has been designed to be reusable in a


variety of different environments. There is no restriction on the capability of a Bean.
It may perform a simple function, such as checking the spelling of a document, or a
complex function, such as forecasting the performance of a stock portfolio. A Bean
may be visible to an end user.A Bean that provides real-time price information from a
stock or commodities exchange would need to work in cooperation with other
distributed software to obtain its data.

3.1.1ADVANTAGES OF JAVA BEANS

A Software component architecture provides standard mechanisms to deal with


software building blocks.
• A Bean obtains all the benefits of Java’s “write-once, run-anywhere”
paradigm.
• The properties, events, and methods of a Bean that are exposed to an
application builder tool can be controlled.
• A Bean may be designed to operate correctly in different locales, which
makes it useful in global markets.
• Auxiliary software can be provided to help a person configure a Bean. This
software is only needed when the design-time parameters for that component
are being set. It does not need to be included in the run-time environment.
• The configuration settings of a Bean can be saved in persistent storage and
restored at a later time.
• A Bean may register to receive events from other objects and can generate
events that are sent to other objects.

3.2A TOUR OF SWING

Swing is a set of classes that provides more powerful and flexible components than
are possible with the AWT. In addition to the familiar components, such as buttons,
check boxes, and labels, Swing supplies several exciting additions, including tabbed
panes, scroll panes, trees, and tables. Even familiar components such as buttons have
more capabilities in Swing.

The Swing component classes that are used in this book are shown here:
Class Description
AbstractButton Abstract superclass for Swing
buttons.
ButtonGroup Encapsulates a mutually exclusive set of
buttons.
ImageIcon Encapsulates an icon.
JApplet The Swing version of Applet.
JButton The Swing push button class.
JCheckBox The Swing check box class.
JComboBox Encapsulates a combo box (an
combination of a drop-down list and text
field).
JLabel The Swing version of a label.
JRadioButton The Swing version of a radio button.
JScrollPane Encapsulates a scrollable window.
JTabbedPane Encapsulates a tabbed window.
JTable Encapsulates a table-based control.
JTextField The Swing version of a text field.
JTree Encapsulates a tree-based control.
This example Swing application creates a single window with "Hello, world!" inside:

// Hello.java (Java SE 5)
import java.awt.BorderLayout;
import javax.swing.*;
public class Hello extends JFrame
{
public Hello()
{
super("hello");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
add(new JLabel("Hello, world!"));
pack();
}
public static void main(String[] args)
{
new Hello().setVisible(true);
}
}

The first import statement directs the Java compiler to include the BorderLayout class
from the java.awt package in the compilation; the second import includes all of the
public classes and interfaces from the javax.swing package.

The Hello class extends the JFrame class; the JFrame class implements a window with
a title bar and a close control.

The Hello() constructor initializes the frame by first calling the superclass constructor,
passing the parameter "hello", which is used as the window's title. It then calls the
setDefaultCloseOperation(int) method inherited from JFrame to set the default
operation when the close control on the title bar is selected to
AWT - BUILDING A GRAPHICAL INTERFACE

• Adding a Frame and using the show() method


package com.cosc210.awt; import java.awt.*;
public class MyApp1
{
public static void main (String arg[])
{
Frame myFrame = new Frame("example Frame for
cosc210"); myFrame.show(); // necessary for the frame to be visible }
}

Used the mouse to drag the

Window to a larger size

WindowConstants.EXIT_ON_CLOSE — this causes the JFrame to be


disposed of when the frame is closed (as opposed to merely hidden), which allows
the JVM to exit and the program to terminate.

Next, the layout of the frame is set to a BorderLayout; this tells Swing how to
arrange the components that will be added to the frame.
3.3SERVLETS

Servlets are small programs that execute on the server side of a Web connection.

A Simple Servlet:-
To become familiar with the key servlet concepts, we will begin by building and
testing a simple servlet. The basic steps are the following:
• Create and compile the servlet source code.
• Start Tomcat.
• Start a Web browser and request the servlet.
4
SYNTAX
The syntax of Java is largely derived from C++. Unlike C++, which combines the
syntax for structured, generic, and object-oriented programming, Java was built
almost exclusively as an object oriented language. All code is written inside a class
and everything is an object, with the exception of the intrinsic data types (ordinal and
real numbers, boolean values, and characters), which are not classes for performance
reasons.

Java suppresses several features (such as operator overloading and multiple


inheritance) for classes in order to simplify the language and to prevent possible errors
and anti-pattern design.

Java uses the same commenting methods as C++. There are two different styles of
comment: a single line style marked with two forward slashes, and a multiple line
style opened with a forward slash asterisk (/*) and closed with an asterisk forward
slash (*/).

Example:

//This is an example of a single line comment using two forward slashes

/* This is an example of a multiple line comment using the forward slash and asterisk.
This type of comment can be used to hold a lot of information but it is very important
to remember to close the comment. */
5
EXAMPLES
5.1 Hello world
The traditional Hello world program can be written in Java as:
/*
* Outputs "Hello, world!" and then exits
*/
public class HelloWorld { public static

void main(String[] args) {

System.out.println("Hello, world!");

Source files must be named after the public class they contain, appending the suffix
.java, for example, HelloWorld.java. It must first be compiled into bytecode, using a
Java compiler, producing a file named HelloWorld.class.

Only then can it be executed, or 'launched'.


The java source file may only contain one public class but can contain multiple
classes with less than public access and any number of public inner classes. A class
that is declared private may be stored in any .java file.The compiler will generate a
class file for each class defined in the source file. The name of the class file is the
name of the class, with .class appended.

It is simply the name of the method the Java launcher calls to pass control to the
program. Java classes that run in managed environments such as applets and
Enterprise JavaBean do not use or need a main() method. A java program may contain
multiple classes that have main methods, which means that the VM needs to be
explicitly told which class to launch from.

5.2 A MORE COMPREHENSIVE EXAMPLE

import java.awt.*;
import javax.swing.*;

public class JLabelDemo extends JApplet{


public void init() {
// Get content pane
Container contentPane = getContentPane();
// Create an icon
ImageIcon ii = new ImageIcon("france.gif");
// Create a label
JLabel jl = new JLabel("France", ii, JLabel.CENTER);
// Add label to the content pane
contentPane.add(jl);
}
}

Output from this applet is shown here:


6
SPECIAL CLASS
6.1 APPLET

Java applets are programs that are embedded in other applications, typically in a Web
page displayed in a Web browser.

// Hello.java import
javax.swing.JApplet; import
java.awt.Graphics;
public class Hello extends JApplet
{ public void paintComponent(Graphics g)
{
g.drawString("Hello, world!", 65, 95);
}
}

The import statements direct the Java compiler to include the javax.swing.JApplet and
java.awt.Graphics classes in the compilation.The import statement allows these
classes to be referenced in the source code using the simple class name (i.e. JApplet)
instead of the fully qualified class name (i.e. javax.swing.JApplet).
The Hello class extends (subclasses) the JApplet (Java Applet) class; the JApplet class
provides the framework for the host application to display and control the lifecycle of
the applet.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"


"http://www.w3.org/TR/html4/strict.dtd">
<!-- Hello.html -->
<html>
<head>
<title>Hello World Applet</title>
</head>
<body>
<applet code="Hello" width="200" height="200">
</applet>
</body>
</html>

An applet is placed in an HTML document using the <applet> HTML element. The
applet tag has three attributes set: code="Hello" specifies the name of the JApplet
class and width="200" height="200" sets the pixel width and height of the applet.
Applets may also be embedded in HTML using either the object or embed
element[26], although support for these elements by Web browsers is inconsistent.
[27] However, the applet tag is deprecated, so the object tag is preferred where
supported.
The host application, typically a Web browser, instantiates the Hello applet and
creates an AppletContext for the applet. Once the applet has initialized itself, it is
added to the AWT display hierarchy.
The paint method is called by the AWT event dispatching thread whenever the display
needs the applet to draw itself.

6.2 SERVLET

Java Servlet technology provides Web developers with a simple, consistent


mechanism for extending the functionality of a Web server and for accessing existing
business systems.

Servlets are server-side Java EE components that generate responses (typically HTML
pages) to requests (typically HTTP requests) from clients.

6.3 JAVA SERVER PAGE

JavaServer Pages (JSPs) are server-side Java EE components that generate responses,
typically HTML pages, to HTTP requests from clients.

JSPs embed Java code in an HTML page by using the special delimiters <% and %>.
A JSP is compiled to a Java servlet, a Java application in its own right, the first time it
is accessed.After that, the generated servlet creates the response.

6.4 GENERICS

In 2004 generics were added to the Java language, as part of J2SE 5.0. Prior to the
introduction of generics, each variable declaration had to be of a specific type.

For container classes, for example, this is a problem because there is no easy way to
create a container that accepts only specific types of objects.

Either the container operates on all subtypes of a class or interface, usually Object, or
a different container class has to be created for each contained class.

Generics allow compile-time type checking without having to create a large number
of container classes, each containing almost identical code.

7
Documentation
Javadoc is a comprehensive documentation system, created by Sun Microsystems,
used by many Java developers. It provides developers with an organized system for
documenting their code. Whereas normal comments in Java and C are set off with /*
and */, the multi-line comment tags, Javadoc comments have an extra asterisk at the
beginning, so that the tags are /** and */.
8.1 Examples

The following is an example of java code commented with simple Javadoc-style


comments:

/**
* A program that does useful things.
*/
public class Program
{
/**
* A main method.
* @param args The arguments
*/
public static void main(String[] args)
{
//do stuff
}

8
Editions
Sun has defined and supports four editions of Java targeting different application
environments and segmented many of its APIs so that they belong to one of the
platforms.

The platforms are:

• Java Card • Micro Edition (ME) • Standard Edition (SE) • Enterprise


Edition (EE)

Java Card –Java Card refers to a technology that allows Java –dd
application(applets)to be run securely on smart cards and similar small memory
footprint devices. Java Card is the tiniest of Java targeted for embedded devices.
Java Card gives the user ability to program the device and make them application
specific. It is widely used in SIM cards(used in mobile phones) and ATM cards.
The first Java Card was introduced in 1996 by Schlumberger’s card division
which later merged with Gemplus to form Gemalto. Java Card products are
based on the Java Card Platform specifications developed by Sun Microsystems,
a subsidiary of Oracle Corporation.
Java Platform, Standard Edition (Java SE) — J2SE is Sun's platform that
includes the Java Virtual Machine (JVM) and packages. There is the core package
which is basically the contents of rt.jar in the distribution package of J2SE. Then
there are specification such as Swing and Networking. Java Platform, Standard
Edition or Java SE is a widely used platform for programming in the Java
language. It is the Java Platform used to deploy portable applications for general
use. In practical terms, Java SE consists of a virtual machine, which must be used
to run Java programs, together with a set of libraries (or "packages") needed to
allow the use of file systems, networks, graphical interfaces, and so on, from
within those programs

Java Platform, Enterprise Edition (Java EE) — J2EE on the other hand builds
on top of J2SE so to speak; J2EE needs J2SE. It includes tools to create
frameworks, API specifications suitable for companies. By specification, JSP and
Servlets (and Beans) are J2EE. Java Platform, Enterprise Edition or Java EE is
a widely used platform for server programming in the Java programming
language. The Java platform (Enterprise Edition) differs from the Java Standard
Edition Platform (Java SE) in that it adds libraries which provide functionality to
deploy fault-tolerant, distributed, multi-tier Java software, based largely on
modular components running on an application server

Java Platform, Micro Edition (Java ME) — Java Platform, Micro Edition, or
Java ME, is a Java platform designed for embedded systems (mobile devices are one
kind of such systems) . Target devices range from industrial controls to mobile phones
(especially feature phones) and set-top boxes. Java ME was formerly known as Java
2 Platform, Micro Edition (J2ME).

Java ME was designed by Sun Microsystems, now a subsidiary of Oracle


Corporation; the platform replaced a similar technology, PersonalJava. Originally
developed under the Java Community Process as JSR 68, the different flavors of Java
ME have evolved in separate JSRs. Sun provides a reference implementation of the
specification, but has tended not to provide free binary implementations of its Java
ME runtime environment for mobile devices, rather relying on third parties to provide
their own. J2ME (Micro Edition) which runs on portable, mobile, handheld devices.
I'm honestly not that familiar with this one; I don't really have a testing environment.

The classes in the Java APIs are organized into separate groups called packages. Each
package contains a set of related interfaces, classes and exceptions. Refer to the
separate platforms for a description of the packages available.

The set of APIs is controlled by Sun Microsystems in cooperation with others through
the Java Community Process program.Companies or individuals participating in this
process can influence the design and development of the APIs.

This process has been a subject of controversy. Sun also provided an edition called
PersonalJava that has been superseded by later, standards-based Java ME
configuration-profile pairings.

You might also like