Documen PDF
Documen PDF
Documen PDF
ON
“Learn JAVA Programming Beginner to Master”
Submitted
In partial fulfilment of the requirement of the award of the degree of
Submitted by:
Shaha Rahiminshaha (2011630045)
Guided by:
Prof.P.P.Deshpande
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
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.
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
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.
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.
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
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()
button.addActionListener(this);
add(textField); add(button);
setVisible(true);
textField.setText("GFG!");
}
new EventTop();
18
}
Output :
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
// default constructor
calculator()
s0 = s1 = s2 = "";
// main function
22
// create a frame
f = new JFrame("calculator");
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
;
catch (Exception e) {
System.err.println(e.getMessage());
// create a textfield
l = new JTextField(16);
23
// set the textfield to non editable
l.setEditable(false);
JButton b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bs, bd,
bm, be, beq, beq1;
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("=");
ba = new JButton("+");
bs = new JButton("-");
bd = new JButton("/");
bm = new JButton("*");
be = new JButton(".");
// create a panel
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);
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);
f.add(p);
f.setSize(200, 220);
f.show();
27
public void actionPerformed(ActionEvent e)
String s = e.getActionCommand();
if (!s1.equals(""))
s2 = s2 + s;
else
s0 = s0 + s;
l.setText(s0 + s1 + s2);
s0 = s1 = s2 = "";
28
// set the value of text
l.setText(s0 + s1 + s2);
double te;
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));
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;
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);
s1 = s;
s2 = "";
}
l.setText(s0 + s1 + s2);
31
}
OUTPUT :
CONCLUSION
33