Professional Documents
Culture Documents
Submitted
in partial fulfillment
for the award of the Degree of
Bachelor of Technology
In
Computer Engineering
Certificate
This is to certify that the work, which is being presented in the Industrial
Training report for training taken at < Dreamtech IT Solution Pvt. Ltd. >
entitled “ Java Programming Language ” submitted by Mr. Ravi Raja ,
a student of third year(VSem) B.Tech. in Computer Engineering as a
partial fulfilment for the award of degree of bachelor of technology is a
record of student’s work carried out and found satisfactory for
submission.
I hereby declare that the work, which is being presented in the Industrial
Training report, entitled “ Java Programming Language ”in partial fulfillment
for the award of Degree of “Bachelor of Technology” in Department of Computer
Science &Engineering with Specialization in Computer Engineering and submitted
to the Department of Computer Science & Engineering, Arya Institute of
Engineering & Technology, is a record of my own investigations carried under the
Guidance of Mr. Manish Choubisa, Associate Professor, Department of Computer
Science & Engineering.
Ravi Raja
RAVI RAJA
Roll No:- 17EAICS122.
Acknowledgement
CONCLUSION
REFERENCES
HISTORY OR INTRODUCTION OF JAVA
History of Java
Java is a General Purpose, Object Oriented Programming Language
developed by Sun Microsystems of USA I 1991. Originally called Oak by Games
Gosling, one of the invention of the language, java was designed for the
development of software for consumer electronic devices like TVs, VCRs, toasters
and such other electronic Machines.This goal had a strong impact on the
development team to make the language simple, portable and highly reliable.
The java team which included Patrick Naughton discovered that the existing
languages like C and C++ had limitations in terms of both reliability and
portability. However, they modeled their new language Java on C and C++ but
removed a number of features of of C and C++ that were considered as source of
problems and thus made java really simple, reliable,portable and powerful
language.
1990-> Sun Microsystems decided to develop special software that could be used
to manipulate consumer electronic devices. A team of Sun Microsystems
programmers headed by James Gosling was formed to undertake this task.
1992-> The team, known as a Green Project team by Sun, demonstrated the
application of their new language to control a list of home appliance using a hand-
held device with a tiny touch sensitive screen.
1993-> The World Wide Web(WWW) appeared on the internet and transformed
the text-based Internet into a Graphical-rich environment. The green Project team
came up with the idea of developing Web Applets(tiny programs) using the new
language that could run on all types of computers connected to Internet.
1994-> The team developed a web browser called “Hot Java” to locate and run
applet programs on Internet. Hot Java demonstrated the power of the new
language, thus making it instantly popular among the Internet users.
1995-> Oak was named “Java”, due to some legal snags. Java is just a name
and is not an acronym. Many popular companies including Netscape and
Microsoft announce to their support to Java.
1996->Java established itself not only a leader for Internet Programming but also as
a general-purpose, object oriented programming language. Java found its
home.
There were five primary goals in the creation of the Java language.
JDK : Java Development Kit comes with a collection of tools that are used for
developing and running Java Programs. They include :
Java-> Java Interpreter, which runs applets and applications by reading and
interpreting bytecode files.
Javac-> The Java compiler, which translates Java source code to byte code files
that the interpreter understad.
a7 f4 73 5a 1b 92 7d
When the code is run by the user, it is processed by something called the Java
Virtual Machine (JVM). The JVM is essentially an interpreter for the bytecode. It
goes through the bytecode and runs it. There are different versions of the JVM that
are compatible with each OS and can run the same code. There is virtually no
difference for the end-user, but this makes it a lot easier for programmers doing
software development.
- The Java runtime environment (JRE) consists of the JVM and the Java class
libraries and contains the necessary functionality to start Java programs.
- The JDK contains in addition the development tools necessary to create Java
programs. The JDK consists therefore of a Java compiler, the Java virtual
machine, and the Java class libraries.
INSTALLATION OF JAVA
Check Installation
- Java might already be installed on your machine. You can test this by
opening a console (if you are using Windows: Win+R, enter cmd and
press Enter) and by typing in the following command:
- java –version.
- If Java is correctly installed, you should see some information about
your Java installation. If the command line returns the information that
the program could not be found, you have to install Java.
Note on Editions
- The JDK comes in three editions.
- Java Standard Edition (JSE) – This version is the basic platform for Java.
The course will focus on this edition.
- Java Enterprise Edition (JEE) – This edition is mainly for developing and
running distributed multitier architecture Java applications, based
largely on modular software components running on an application
server. We will not be covering this version in the course.
- Java Micro Edition (JME) – This edition is primarily for developing
programs to run on consumer applicances, such as PDAs and cell
phones.
Configuring Variables
- Before writing code, it is recommended that you set the Path variable on
your system so you can compile your code more easily.
For Macintosh
- Apple sets everything up for you. Sit back and relax.
- The only drawback is that because Apple handles development and
maintenance of Java on the Mac, there is usually a delay from the time
that a new version is released by Sun and the time that the new version is
released on the Mac. Also, getting the latest version sometimes requires
an operating system upgrade.
- Oh well, you can't have everything.
Validate installation
- Switch again to the command line and run the following command.
- java -version
- The output should be similar to the following output.
- java version "1.7.0_25"
- OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-
1ubuntu0.13.04.2)
- OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
Development Process with Java
- Java source files are written as plain text documents. The programmer
typically writes Java source code in an Integrated Development
Environment (IDE) for programming. An IDE supports the programmer
in the task of writing code, e.g. it provides auto-formating of the source
code, highlighting of the important keywords, etc.
- At some point the programmer (or the IDE) calls the Java compiler
(javac). The Java compiler creates the bytecode instructions. These
instructions are stored in .class files and can be executed by the Java
Virtual Machine.
Garbage collector
- The JVM automatically re-collects the memory which is not referred to
by other objects. The java garbage collector checks all object references
and find the objects which can be automatically released.
- While the garbage collector releases the programmer from the need to
explicitly manage memory the programmer still need to ensure that he
does not keep unneeded object references otherwise the garbage collector
cannot release the associated memory. Keeping unneeded object
references are typically called memory leaks.
Classpath
- The classpath defines where the Java compiler and Java runtime look for
.class files to load. This instructions can be used in the Java program.
- For example if you want to use an external Java library you have to add
this library to your classpath to use it in your program.
Java basic terms
Basics: Package, Class and Object
- It is important to understand the base terminology of Java in terms of
packages, classes and objects. This section gives an overview of these
terms.
Package
- Java groups classes into functional packages.
- Packages are typically used to group classes into logical units. For
example all graphical views of an application might be placed in the same
package called com.vogella.webapplication.views.
- It is common practice to use the reverse domain name of the company as
top level package. For example the company might own the domain,
vogella.com and in this example the Java packages of this company starts
with com.vogella.
- Other main reason for the usage of packages is to avoid name collisions
of classes. A name collision occurs if two programmers give the same
fully qualified name to a class. The fully qualified name of a class in Java
consists out of the package name followed by a dot (.) and the class name.
- Without packages, a programmer may create a Java class called Test.
Another programmer may create a class with the same name. With the
usage of packages you can tell the system which class to call. For
example if the first programmer puts the Test class into package report
and the second programmer puts his class into package xmlreader you can
distinguish between these classes by using the fully qualified name, e.g.
xmlreader.Test or report.Test.
Class
- Def.: Template that describes the data and behavior associated with an
instance of that class.
- In Java source code a class is defined by the class keyword and must start
with a capital letter. The body of a class is surrounded by {}.
package test;
class MyClass {
}
- The data associated with a class is stored in variables ; the behavior
associated to a class or object is implemented with methods.
- A class is contained in a Java source file with the same name as the class
plus the .java extension.
Object
- Def.: An object is an instance of a class.
- The object is the real element which has data and can perform actions.
Each object is created based on the class definition
Inheritance
- A class can be derived from another class. In this case this class is called
a subclass. Another common phrase is that a class extends another class.
- The class from which the subclass is derived is called a superclass.
- Inheritance allows a class to inherit the behavior and data definitions of
another class.
- The following codes demonstrates how a class can extend another class.
In Java a class can extend a maximum of one class.
package com.vogella.javaintro.base;
class MyBaseClass {
void hello(){
System.out.println("Hello from MyBaseClass");
}
}
package com.vogella.javaintro.base;
class MyExtensionClass extends MyBaseClass {
}
Override methods and the @override annotation
- If a class extends another class it inherits the methods from its superclass.
If it wants to change these methods it can override these methods. To
override a method you use the same method signature in the source code
of the subclass.
- To indicate to the reader of the source code and the Java compiler that
you have the intention to override a method you can use the @override
annotation.
- The following code demonstrates how you can override a method from a
superclass.
package com.vogella.javaintro.base;
class MyBaseClass {
void hello(){
System.out.println("Hello from MyBaseClass");
}
}
package com.vogella.javaintro.base;
class MyExtensionClass2 extends MyBaseClass {
}
Instance variable
Local variable
Methods
- A method is a block of code with parameters and a return value. It can be
called on the object.
package com.vogella.javaintro.base;
public class MyMethodExample {
void tester(String s) {
System.out.println("Hello World");
}
}
- Method can be declared with var-args. In this case the method declares a
parameter which accepts from zero to many arguments (syntax: type ..
name;) A method can only have one var-args parameter and this must be
the last parameter in the method.
- Overwrite of a superclass method: A method must be of the exact same
return parameter and the same arguments. Also the return parameter must
be the same. Overload methods: An overloaded method is a method with
the same name, but different arguments. The return type can not be used
to overload a method.
Main method
- A public static method with the following signature can be used to start a
Java application. Such a method is typically called main method.
public static void main(String[] args){
Constructor
- A class contains constructors that are invoked to create objects based on
the class definition. Constructor declarations look like method
declarations except that they use the name of the class and have no return
type. A class can have several constructors with different parameters.
Each class must define at least one constructor.
- In the following example the constructor of the class expects a parameter.
package com.vogella.javaintro.base;
public class MyConstructorExample2 {
String s;
public MyConstructorExample2(String s) {
this.s = s;
}
}
- If no explicit constructor is defined the compiler adds implicitly a
constructor. If the class is sub-classed then the constructor of the super
class is always implicitly called in this case.
- In the following example the definition of the constructor without
parameters (also known as the empty constructor) is unnecessary. If not
specified the compiler would create one.
package com.vogella.javaintro.base;
public class MyConstructorExample {
// Unnecessary, would be created by the compiler if left out
public MyConstructorExample() {
}
}
- The naming conversion for creating a constructor is the following:
classname (Parameter p1, ..) {} .
- Every object is created based on a constructor. This constructor method is
the first statement called before anything else can be done with the object.
JAVA NETWORKING
The term Network programming refers to writing programs that
execute across multiple devices (Computers), in which the devices are all
connected to each other using networks. The Java net package of the J2se
API contains a collection of classes and interfaces that provide the low-
level communication details, allowing you to write programs that focus
on solving problem at hand. The java net package provides support for
the two common network protocols.
1. The java.net package provides support for the two common network
protocols -
- TCP- TCP stands for transmission control protocol, which allows for
reliable communication between two applications. TCP is typically used
over the Internet Protocol, which is referred to as TCP/IP.
- UDP (User Datagram Protocol)- UDP stands for User Datagram
Protocol, a connection-less protocol that allows for packets of data to be
transmitters between applications.
import java.awt.*;
First() {
}}
SWING
Work Flow Java Swing 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.
import javax.swing.*;
} }
Output-
JAVA DATABASE CONNECTIVITY
The Java Database Connectivity (JDBC) API is the industry standard for
database-independent connectivity between the Java programming language and a
wide range of databases – SQL databases and other tabular data sources, such as
spreadsheets or flat files. The JDBC API provides a call-level API for SQL-based
database access.
1. JDBC drivers
There are commercial and free drivers available for most relational
database servers. These drivers fall into one of the following types:
- Type 1 That calls native code of the locally available ODBC driver.
- Type 2 That calls database vendor native library on a client side. This
code then talks to database over network.
- Type 3, the pure-java driver that talks with the server-side middleware
those then talks to database.
- Type 4, the pure-java driver that uses database native protocol.
2. Functionality and implementation
JDBC allows multiple implementations to exist and b e used by the
same application. The API provides a mechanism for dynamically loading
the correct Java packages and registering them with the JDBC Driver
Manager. The Driver Manager is used as a connection factory for creating
JDBC connections. JDBC connections support Creating and executing
statements. These may be update statements such as SQL's CREATE,
INSERT, UPDATE and DELETE, or they may be query statements such as
SELECT. Additionally, stored procedures may be invoked through a JDBC
connection.
It is made use to evoke the utility of the built-in functions. Moreover JSP permits
to establish and form the JSP tag libraries which operate as an extension to the
standard XML or HTML tags. These JSP tag libraries give a good technique to
widen the potentiality of the Web server by providing an independent platform.JSP
compiler compiles the JSPs into Java Servlets.
A JSP compiler may possibly create a servlet in Java code and it is later
compiled by the Java compiler. It might even directly produce the byte code for the
servlet. Java Server Pages can be examined as a high level abstraction of servlets
which is practiced as an extension of the Servlet2.1API.
Java Server Pages are HTML pages embedded with snippets of Java code.It is
an inverse of a Java Servlet
JSP Compilation
The Java Server Pages and the Servlets were initially developed at Sun
Microsystems. Opening with version 1.2 of the Java Server Page specification the
JSPs have been built under the Java Community Process. There are quite a few JSP
implicit objects that are represented by the JSP container and it could be mentioned
and indicated by the programmers
There are several actions that are performed in JSP actions. A JSP action is nothing
but a XML tags that invokes functionality of the built-in web server.
Since servlets run inside the servers, however, they do not need a
graphical user interface (GUI). In this sense, servlets are also faceless
objects.
The Java Servlet API is a set of Java classes which define a standard interface
between a Web client and a Web servlet. Client requests are made to the Web
server, which then invokes the servlet to service the request through this interface.
The API is composed of two packages:
- javax.servlet
- javax.servlet.http
To write an HTTP servlet for use on the Web, we will use an even
more specialized class of GenericServlet called HttpServlet.HttpServlet
provides additional methods for the processing of HTTP requests such as
GET (doGet method) and POST (doPost method). Although our servlets may
implement a service method, in most cases we will implement the HTTP
specific request handling methods of doGet and doPost.
Lifecycle of Servlet
The life cycle of a servlet can be categorized into four parts:
b) start − This method is automatically called after the browser calls the
init method. It is also called whenever the user returns to the page containing
the applet after having gone off to other pages.
c) stop − This method is automatically called when the user moves off the
page on which the applet sits. It can, therefore, be called repeatedly in the
same applet.
d) destroy − This method is only called when the browser shuts down
normally. Because applets are meant to live on an HTML page, you should
not normally leave resources behind after a user leaves the page that contains
the applet.
e) paint − Invoked immediately after the start() method, and also any time
the applet needs to repaint itself in the browser. The paint() method is
actually inherited from the java.awt. A "Hello, World" Applet Following is a
simple applet named HelloWorldApplet.java –
}}
Strings
We can declare string using Characters but there is limitation that we can not use
functions related with strings using array like copy of an array is difficult. For that
Java provides String class using objects.
for that two classes are used String and StringBuffer. A Java String
is an instantiated object of the String class.
String stringName;
String Array :
While dealing with the files, a source of confusion for a beginner in Java
programming is the path name. For example, consider the following path
name on a Unix/Linux machine:
/java/scjp/temp
The first forward slash represents the root directory. This path name in
Windows machines may be written as
C:\java\scjp\temp
File(String pathname)
Creates an instance of the File class by converting the path name String to an
abstract path name.
Creates an instance of the File class by concatenating the child String to the
parent String, and converting the combined String to an abstract path name.
Creates an instance of the File class by constructing an abstract path name from
the abstract path name of the parent File, and the String path name of
CONCLUSION
Books-
Website-
- www.cmcltd.com
- wikipedia.org/wiki
- www.scribd.com
- Slideshare.net
- www.tutorialspoint.com
- Javatpoint.com