Documen PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

INDUSTRIAL TRANING REPORT

ON
“Learn JAVA Programming Beginner to Master”
Submitted
In partial fulfilment of the requirement of the award of the degree of

Diploma in computer Engineering

Submitted by:
Shaha Rahiminshaha (2011630045)
Guided by:
Prof.P.P.Deshpande

Department of “Computer Engineering”


GOVERMENT POLYTECHNIQUE, HINGOLI
2022-2023

1
ACKNOWLEDGMENT
The completion of this training work could have been possible
with continued and dedicated efforts & guidelines of large
number of faculty & staff members of the institute. I
acknowledgment however will be incomplete without specific
mention as follows
Furthermore, I would like to acknowledge with much
appreciation the crucial role of our HOD Prof. A. T. Adhave for
this training encouragement & providing all the facilities in the
department.
I would like to say that I am indebted to my parents for
everything that they have done for me. All of this would have
been impossible without their constant support. And I also
thanks to God for being kind to me and driving me through this
journey.

2
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
GOVERMENT POLYTECHNIQUE HINGOLI

CERTIFICATE
This is to certify that the project report entitled “Advance java”
was successfully completed by student of fourth semester
diploma in Computer Engineering.

NAME OF STUDENTS
Shaha Rahiminshaha (2011630045)
In partial Fulfilment of The Requirements For The Award Of
The Diploma In Computer Engineering & Submitted To The
Department Of Computer Engineering Of Government
Polytechnic Hingoli Work Carried out During A Period For The
Academic Year 2021-2022 as Per Curriculum.
Name of Guide: Head of Department:
Prof.P.P.Deshpande Prof.A.T.Adhave
Principle:Dr.Ashok.Upadhya

APPROVAL CERTIFICATE

3
INDEX
Sr.No Title Page No

4
1 TECHNOLOGY

2 COLLECTION

3 MULTITHREADING

4 AWT

5 JAVA NETWORKING

6 LIFE CYCLE OF SURVLET

7 EVENT HANDLING

8 APPLET

9 PROGRAM

10 CONCLUSION

5
TECHNOLOGY
INDRUCTION:
Java programming language, java was developed by James
Gosling at Sun Microsystem in the year 1995, later acquired by
oracle Corporation. It is simple programming language. Java
makes writing, compiling, and debugging programming easy. It
helps to create reusable code and modular programs. Java is a
class based, object-oriented programming language and is
designed to have as few implementation dependencies as
possible. A general-purpose programming language is made for
developers to write once run anywhere that is compiled to byte
code that can run on any way java virtual machine.

There are five primary goals in the creation of the java language.

It should be “simple, object-oriented and familiar”.


It should be “architecture neutral and portable”.
It should be “robust and secure”.
It should be executed with “high performance”.

COLLECTION
Collections are like containers that group multiple items in a
single unit. For example, a jar of chocolates, a list of names, etc.

6
Java provides collections framework that is the architecture to
represent and manipulate collection in java in standard way.
Collocation tree part
1. List- Array List
2. Set- Tree set, Hash Map, Hash Table, Tree Map
3. Map- Hash Map, Hash Table, Tree Map

2 : Benefits of the java Collection Framework

• Reduces programming effort:


By providing useful data structures and algorithm, the
Collections framework frees you to concentrate on the
important parts of your program rather than on the low-level
“plumbing" required to make it work. By facilitating
interoperability among unrelated APIs, the java Collection
Framework frees writing adapter objects or conversion code to
connect APIs.

• Increases program speed and quality:


This Collection Framework provides high performance of
useful data structure and algorithm. The various
implementation of each interface are interchangeable, so
program can be easily tuned by switching collection
implementation. Because you’re freed from the drudgery of
7
writing your own data structure, you’ll have more time to
devote to improving programs quality and performance.

• Allows interoperability among unrelated APIs:


The collection interface are the vernacular by which APIs pass
collection back and forth. If any network administration API
furnishes a collection of node names and if your GUI toolkit
expects a collection of column headings, our APIs will
interoperate seamlessly, even though they were written
independently.

• Reduces effort to design new APIs:


This is the flip side of the previous advantages. Designers and
implementers don’t have to reinvent the wheel each time they
create an API that relies on collections but instead use the
standard collection interface.

• Reduces effort to learn and to use new APIs:


Many APIs naturally take collections on input and furnish then
as output. In the past, each such API had a little sub-API, so you
had to learn each one from scratch, and it was easy to make
mistakes when using them. With the advent of standard
collection interfaces, the problem went away.

• Fosters software reuse:


8
New data structures that conform to the standard collection
interfaces are by nature reusable. The same goes for new
algorithm that operate on objects that implement t
MULTITHREADING
Multithreading in Java is a process of executing multiple
threads simultaneously. A thread is a lightweight sub-process,
the smallest unit of processing. Multiprocessing, multithreading
both are used to achieve multitasking 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. Life Cycle of a Thread


A thread goes through stages in its cycle for example, a thread is
born, started, runs, and then dies.

9
New – A new thread begins its life cycle in the new state. It
remains in this state until the program starts the thread. It also
referred to as a born thread.
Runnable – after a newly born thread is started, the thread
becomes runnable. A thread in this state is considered to be
executing its task.
Waiting- When a thread is temporarily inactive, then it’s in one
of the following states:
• Blocked
• Waiting

10
Timed Waiting - A thread lies in a timed waiting state when it
calls a method with a time-out parameter. A thread lies in this
state until the timeout is completed or until a notification is
received. For example, when a thread calls sleep or a conditional
wait, it is moved to a timed waiting state.
Terminated state - A thread terminates because of either of the
following reasons:
•Because it exits normally. This happens when the code of the
thread has been entirely executed by the program.
•Because there occurred some unusual erroneous event, like
segmentation fault or an unhandled exception.

 Implementing the Thread States in Java:


In Java, to get the current state of the thread, use
Thread.getState() method to get the current state of the thread.
Java provides java.lang.Thread.State class that defines the
ENUM constants for the state of a thread, as a summary of
which is given below:

ABSTRACT WINDOWING TOOLKIT (AWT)


Java AWT (Abstract Windowing Toolkit) is an develop GUI or
windows-based application in java.
AWT component are heavyweight.
11
AWT component are platform-dependent.
AWT doesn’t support pluggable look and feel.
AWT provides fewer components than swing.

• Java AWT Hierarchy:

JAVA NETWORKING
Java Networking is a concept of connecting two or more
computing devices together so that we can share resources.

12
Java socket programming provides facility to share data
between different computing devices.

1. Java net package provides support for the two common


network protocol.
TCP: Transmission Control Protocol provides reliable
communication between the sender and receiver. TCP is used
along with the Internet Protocol referred as TCP/IP.
UDP: User Datagram Protocol provides a connection-less
protocol service by allowing packet of data to be transferred
along two or more nodes.

2. This chapter gives a good understanding on the following


two subjects -
URL: The URL programming interface (UPI) effectively provides a
set of URLs for a device that are available to any user capable of
performing the HTTP protocol. HTTP has become so universal
that, in college computer courses, students are often given as an
assignment the creation of an HTTP stack.
SOCKET PROGRAMMING: A socket is a communications
connection point (endpoint) that you can name and address in a
network.

13
LIFE CYCLE OF SURVLET
The entire life cycle of a Servlet is managed by the Servlet
container which uses the javax.servlet.Servlet interface to
understand the Servlet object and manage it. So, before
creating a Servlet object, let’s first understand the life cycle of
the Servlet object which is actually understanding how the
Servlet container manages the Servlet object.

14
1 .Loading : Loads the Servlet class. Instantiation : Creates an
instance of the Servlet. To create a new instance of the Servlet,
the container uses the no-argument constructor.
2.Initializing a Servlet: After the Servlet is instantiated
successfully, the Servlet container initializes the instantiated
Servlet object. The container initializes the Servlet object by
invoking the Servlet.init(ServletConfig) method which accepts
ServletConfig object reference as parameter.
3.The Servlet container invokes the Servlet.init(ServletConfig)
method only once, immediately after the
Servlet.init(ServletConfig) object is instantiated successfully. This
method is used to initialize the resources, such as JDBC
datasource.
4.Now, if the Servlet fails to initialize, then it informs the Servlet
container by the ServletException or UnavailableException.
5.Handling request: After initialization, the Servlet instance is
ready to serve the client requests. The Servlet container
performs the following operations when the Servlet instance is
located to service a request :It creates the ServletRequest and
ServletResponse objects. In this case, if this is a HTTP request,
then the Web container creates HttpServletRequest and
HttpServletResponse objects which are subtypes of the
ServletRequest and ServletResponse objects respectively.

15
After creating the request and response objects it invokes the
Servlet.service(ServletRequest, ServletResponse) method by
passing the request and response objects.
The service() method while processing the request may throw
the ServletException or UnavailableException or
IOException.Destroying a Servlet: When a Servlet container
decides to destroy the Servlet, it performs the following
operations,It allows all the threads currently running in the
service method of the Servlet instance to complete their jobs
and get released.After currently running threads have
completed their jobs, the Servlet container calls the destroy()
method on the Servlet instance.After the destroy() method is
executed, the Servlet container releases all the references of
this Servlet instance so that it becomes eligible for garbage
collection.

Event Handling
An event can be defined as changing the state of an object or
behaviour by performing actions. Actions can be a button click,
16
cursor movement, keypress through keyboard or page scrolling,
etc.
The java.awt.event package can be used to provide various
event classes.
Classification of Events
Foreground Events
Background Events

It is a mechanism to control the events and to decide what


should happen after an event occur. To handle the events, Java
follows the Delegation Event model.

Flow of Event Handling


2. User Interaction with a component is required to generate
an event.

17
3. The object of the respective event class is created
automatically after event generation, and it holds all
information of the event source.
4. The newly created object is passed to the methods of the
registered listener.
5. The method executes and returns the result.
BASIC CODE OF EVENT HANDLING:
import java.awt.*; import java.awt.event.*; class
Event extends Frame implements ActionListener {

TextField textField;

EventTop()

textField = new TextField();


textField.setBounds(60, 50, 180, 25); Button
button = new Button("click Here");
button.setBounds(100, 120, 80, 30);

button.addActionListener(this);
add(textField); add(button);
setVisible(true);

public void actionPerformed(ActionEvent e)


{

textField.setText("GFG!");
}

public static void main(String[] args)

new EventTop();

18
}
Output :

Applet Life Cycle


In Java, an applet is a special type of program embedded in the
web page to generate dynamic content. Applet is a class in Java.
The applet life cycle can be defined as the process of how the
object is created, started, stopped, and destroyed during the
entire execution of its application. It basically has five core
19
methods namely init(), start(), stop(), paint() and destroy ().
These methods are invoked by the browser to execute.

init(): The init() method is the first method to run that


initializes the applet. It can be invoked only once at the time
of initialization. The web browser creates the initialized
objects, i.e., the web browser (after checking the security
settings) runs the init() method within the applet.
start(): The start() method contains the actual code of the
applet and starts the applet. It is invoked immediately after
the init() method is invoked. Every time the browser is loaded
20
or refreshed, the start () method is invoked. It is also invoked
whenever the applet is maximized, restored, or moving from
one tab to another in the browser. It is in an inactive state
until the init () method is invoked.
Stop (): The stop () method stops the execution of the applet.
The stop () method is invoked whenever the applet is
stopped, minimized, or moving from one tab to another in
the browser, the stop () method is invoked. When we go back
to that page, the start () method is invoked again.
destroy (): The destroy () method destroys the applet after
its work is done. It is invoked when the applet window is
closed or when the tab containing the webpage is closed. It
removes the applet object from memory and is executed
only once. We cannot start the applet once it is destroyed.
paint(): The paint() method belongs to the Graphics class in
Java. It is used to draw shapes like circle, square, trapezium,
etc., in the applet. It is executed after the start() method and
when the browser or applet windows are resized.

PROGRAM

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

21
class calculator extends JFrame implements ActionListener {

// create a frame

static JFrame f;

// create a textfield

static JTextField l;
// store operator and operands

String s0, s1, s2;

// default constructor

calculator()

s0 = s1 = s2 = "";

// main function

public static void main(String args[])

22
// create a frame

f = new JFrame("calculator");

try {

// set look and feel

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
;

catch (Exception e) {

System.err.println(e.getMessage());

// create a object of class

calculator c = new calculator();

// create a textfield

l = new JTextField(16);

23
// set the textfield to non editable

l.setEditable(false);

// create number buttons and some operators

JButton b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bs, bd,
bm, be, beq, beq1;

// create number buttons

b0 = new JButton("0");

b1 = new JButton("1");

b2 = new JButton("2");

b3 = new JButton("3");

b4 = new JButton("4");

b5 = new JButton("5");

b6 = new JButton("6");

b7 = new JButton("7");

b8 = new JButton("8");

b9 = new JButton("9");

// equals button

24
beq1 = new JButton("=");

// create operator buttons

ba = new JButton("+");

bs = new JButton("-");

bd = new JButton("/");

bm = new JButton("*");

beq = new JButton("C"); // create . button

be = new JButton(".");

// create a panel

JPanel p = new JPanel();

// add action listeners

bm.addActionListener(c);

bd.addActionListener(c);

bs.addActionListener(c); ba.addActionListener(c);

b9.addActionListener(c);

b8.addActionListener(c);

25
b7.addActionListener(c);

b6.addActionListener(c);

b5.addActionListener(c);

b4.addActionListener(c);

b3.addActionListener(c);

b2.addActionListener(c);

b1.addActionListener(c);

b0.addActionListener(c);

be.addActionListener(c); beq.addActionListener(c);

beq1.addActionListener(c);

// add elements to panel

p.add(l);

p.add(ba);

p.add(b1);

p.add(b2);

p.add(b3);

p.add(bs);

p.add(b4);

26
p.add(b5);

p.add(b6);

p.add(bm);

p.add(b7);

p.add(b8);

p.add(b9);

p.add(bd);

p.add(be);

p.add(b0);

p.add(beq);

p.add(beq1);

// set Background of panel

p.setBackground(Color.blue); // add panel to frame

f.add(p);

f.setSize(200, 220);

f.show();

27
public void actionPerformed(ActionEvent e)

String s = e.getActionCommand();

// if the value is a number

if ((s.charAt(0) >= '0' && s.charAt(0) <= '9') ||


s.charAt(0) == '.') {

// if operand is present then add to second no

if (!s1.equals(""))

s2 = s2 + s;

else

s0 = s0 + s;

// set the value of text

l.setText(s0 + s1 + s2);

else if (s.charAt(0) == 'C') {

// clear the one letter

s0 = s1 = s2 = "";
28
// set the value of text

l.setText(s0 + s1 + s2);

else if (s.charAt(0) == '=') {

double te;

// store the value in 1st

if (s1.equals("+"))

te = (Double.parseDouble(s0) +
Double.parseDouble(s2));

else if (s1.equals("-"))

te = (Double.parseDouble(s0) -
Double.parseDouble(s2));

else if (s1.equals("/"))
te = (Double.parseDouble(s0) /
Double.parseDouble(s2));

else

te = (Double.parseDouble(s0) *
Double.parseDouble(s2));

// set the value of text

29
l.setText(s0 + s1 + s2 + "=" + te);

// convert it to string

s0 = Double.toString(te);

s1 = s2 = "";

else {
// if there was no operand

if (s1.equals("") || s2.equals(""))

s1 = s;

// else evaluate

else {

double te;

// store the value in 1st

if (s1.equals("+"))

te = (Double.parseDouble(s0) +
Double.parseDouble(s2));

else if (s1.equals("-"))

te = (Double.parseDouble(s0) -
Double.parseDouble(s2));
30
else if (s1.equals("/"))

te = (Double.parseDouble(s0) /
Double.parseDouble(s2));

else

te = (Double.parseDouble(s0) *
Double.parseDouble(s2));

// convert it to string

s0 = Double.toString(te);

// place the operator

s1 = s;

// make the operand blank

s2 = "";
}

// set the value of text

l.setText(s0 + s1 + s2);

31
}

OUTPUT :

CONCLUSION

The training focused upon increasing our knowledge and interest in


toward the java. Because java is most interesting and most used
language in these days. We learnt how to create a web sites and web
pages. It was a great experience. it increases our practical skills that
are the main which we learnt in the training session.
32
The Advance java problem set, a step-by-step approach used by the
student, has ensured that the student acquired enough knowledge
required in various aspects for the stage, before proceeding on.
During the 5 months attachment in Hewlett-Packard lab, the student
had done the following.

33

You might also like