Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
A Training Report
Submitted by:
AYUSH PARAKH
Roll no: 12115017, 5th Sem
ACKNOWLEDGMENT
I am very thankful to everyone who all supported me, for I have completed
my project effectively and moreover on time.
I would like to express my special thanks of gratitude to my teacher as well
as our principal who gave me the golden opportunity to do this wonderful
project on the topic java2 and its evolution which also helped me in doing a
lot of research and I came to know about so many new things.
I am making this project not only for marks but also to increase my
knowledge.
Thanking you
AYUSH PARAKH
12115017 , 5TH Sem
Page 1
ABSTRACT
The report consists of an overview of the famous java core
language. This project represents an in-depth tutorial of the java
language. It begins with basics, including such things as data
types, tokens (escape characters), control statements, objects
and classes. It also discusses javas Exception-Handling
mechanism, static, String, this, super, packages and interfaces.
Page 2
TABLE OF CONTENTS
Contents
I.
II.
III.
Page Number
Acknowledgement
Abstract
Table of Contents
i.
ii.
iii.
Lesson 1: Overview
I.
II.
III.
1)
2)
3)
4)
History of java
Features of java
Some java core topics
String
Static & static block
Exception-Handling
Multi-Threading
1
2
6
6
8
8
10
IV.
V.
Conclusion
References
14
15
Figures
I.
II.
Page 3
9
11
Lesson 1: Overview
1: History of Java
Java was conceived by James gosling, Patrick Naughton, Chris Warth, Ed
frank, and Mike Sheridan at sun Microsystems, inc. in 1991. It took 18
months to develop the first working version. This language was initially
called oak, but was renamed java in 1995.
Versions
2: Features of Java
Simple
Page 1
Object-Oriented
Java is an object-oriented language, which means that you focus on the data in your
application and methods that manipulate that data, rather than thinking strictly in terms
of procedures.
In an object-oriented system, a class is a collection of data and methods that operate on
that data. Taken together, the data and methods describe the state and behavior of an
object. Classes are arranged in a hierarchy, so that a subclass can inherit behavior from
its super class.
Java comes with an extensive set of classes, arranged in packages that you can use in
your programs.
Robust
Java has been designed for writing highly reliable or robust software language
restrictions (e.g. no pointer arithmetic and real arrays) to make it impossible for
applications to smash memory (e.g. overwriting memory and corrupting data).Java does
Page 2
Secure
Security is an important concern, since Java is meant to be used in networked
environments. Without some assurance of security, you certainly wouldn't want to
download an applet from a random site on the net and let it run on your computer.
Java's memory allocation model is one of its main defenses against malicious code (e.g.
can't cast integers to pointers, so can't forge access). Furthermore access restrictions
are enforced (public, private).
Byte codes are verified, which copes with the threat of a hostile compiler.
Architecture-Neutral
Compiler generates byte codes, which have nothing to do with particular computer
architecture.
It is easy to interpret on any machine.
Portable
Java goes further than just being architecture-neutral: no "implementation dependent"
notes in the specification (arithmetic and evaluation order).
Standard libraries hide system differences.
The Java environment itself is also portable: the portability boundary is POSIX
compliant.
High-Performance
Page 3
Multithreaded
Java allows multiple concurrent threads of execution to be active at once. This means
that you could be listening to an audio clip while scrolling the page and in the
background downloading an image. Java contains sophisticated synchronization
primitives (monitors and condition variables), that are integrated into the language to
make them easy to use and robust. The java.lang package provides a Thread class that
supports methods to start, run, and stop a thread, and check on its status.
Dynamic
Java was designed to adapt to an evolving environment:
Even after binaries have been released, they can adapt to a changing environment
Java loads in classes as they are needed, even from across the network
It defers many decisions (like object layout) to runtime, which solves many of the
version problems that C++ has. Dynamic linking is the only kind present.
Java Platform
Popular languages such as C, C++ follow the approach of write once, compile
anywhere approach. It means, to work on different microprocessors we are not required
to rewrite the program but are required to recompile the program for different MPs.
Java uses compile once, run anywhere approach. It means that a java program
after compilation can be run on any environment (i.e. different MPs and OS).This makes
Java programs immensely portable.
Page 4
Java achieves this compile once, run anywhere magic through a program called
Java Virtual Machine (JVM).When a java program is compiled, it is converted to byte
code instructions instead of machine language instruction for a specific MP. The byte
code instructions are interpreted by JVM.
Different JVMs are written specifically for different hardware and OS combinations. A
JVM is distributed along with a set of standard class libraries that implement java
programming interface.
Java byte code instructions are analogous to machine code, but are intended to be
interpreted by a virtual machine (VM) written specifically for the host hardware.
End-users commonly use a Java Runtime Environment (JRE) installed on their own
machine for standalone Java applications, or in a Web browser for Java applets.
Page 5
1)
2)
3)
2. Static
When a member is declared static, it can be accessed before any objects
of its class are created, and without reference to any object.
They can only call other static methods, or only static data.
They cannot refer to this or super in any way.
Class usestatic
{
Static int a=3;
Static int b;
Static void meth(int x)
{
Page 6
System.out.println(x = + x);
System.out.println(a = + a);
System.out.println(b = + b);
}
Static
{
System.out.println(static block initialised.);
b=a*4;
}
public static void main(String args[])
{
meth(42);
}
}
Static Block
static
{
b=10;
Page 7
a=0;
}
3. Exception-Handling
Every Exception in Java is sub type of Exception class which in turn is the
subclass of Throwable. And as we know everything in Java derived from
Object class Throwable also derived from class Object. Exception and Error
are two different classes that derived from Throwable. Errors represent
situation which doesnt occur because of Programming error but that might
happen at the time of program execution and these are abnormal behavior
which java program cannot handle and shouldnt bother to handle. JVM
running out of memory is a type of Error which can occur at runtime .
E
T
E
rx
h
rc
r
oe
o
p
rw
t
a
i
b
o
l
n
e
Fig. 1.1: Exception Handling in Java
Page 8
Example:
// a.java
Class a
{
public static void main(string ar[])
{
int k=0;
try
{
int i = Integer.parseInt(ar[0]);
int j = Integer.parseInt(ar[1]);
k=i/j;
System.out.println(k);
}
catch(AIOOBE e)
{
System.out.println(e);
}
catch(ArithmeticException e)
{
}
catch(NumberFormatException e)
{
}
finally
{
System.out.println(k);
Page 9
}
}
}
try:
catch:
throw:
throws:
finally :
4. Multi-Threading
Thread means independent flow of execution.
Multithreading is a concept in which program is broken into 2 or more threads and all
these threads run simultaneously.
Java's multithreading provides benefit in this area by eliminating the loop and polling
mechanism, one thread can be paused without stopping the other parts of the program.
If any thread is paused or blocked, still other threads continue to run.
As the process has several states, similarly a thread exists in several states. A thread
can be in the following states:
Under execution.
Suspended:
Blocked:
Resumed:
Terminated:
Page 10
Thread Priorities
Each thread has its own priority in Java. Thread priority is an absolute integer value.
Thread priority decides only when a thread switches from one running thread to next,
called context switching. Priority does increase the running time of the thread or gives
faster execution.
Synchronization
Java supports an asynchronous multithreading, any number of thread can run
simultaneously without disturbing other to access individual resources at different
instant of time or shareable resources. But some time it may be possible that shareable
resources are used by at least two threads or more than two threads, one has to write at
the same time, or one has to write and other thread is in the middle of reading it. For
such type of situations and circumstances Java implements synchronization model
called monitor. The monitor was first defined by C.A.R. Hoare. You can consider the
monitor as a box, in which only one thread can reside. As a thread enter in monitor, all
Page 11
other threads have to wait until that thread exits from the monitor. In such a way, a
monitor protects the shareable resources used by it being manipulated by other waiting
threads at the same instant of time. Java provides a simple methodology to implement
synchronization.
Example:
class RunnableDemo implements Runnable
{
private Thread t;
private String threadName;
RunnableDemo(String name)
{
threadName = name;
System.out.println("Creating " + threadName );
}
public void run()
{
System.out.println("Running " + threadName );
try
{
for(int i=4;i>0;i--)
{
System.out.println("Thread: " + threadName + ", " + i);
e)
+
" +
threadName );
Page 12
{
t = new Thread (this, threadName);
t.start ();
}
}
}
public class TestThread {
public static void main(String args[]) {
RunnableDemo R1 = new RunnableDemo("Thread-1");
R1.start();
RunnableDemo R2 = new RunnableDemo("Thread-2");
R2.start();
}
}
4: Conclusion
Our project is an effort to understand the working of an ATM and online
banking with the use of CORE JAVA and JDBC. The project was only for
learning basis. User friendly codes have used in process of building it. The
interface is console-based and further attempts are in continued to make it
GUI.
Page 13
5.
References
http://www.java2s.com
http://www.javaworld.com/javaworld/jw-01-1998/jw-01-bookreview.html
Database Programming with JDBC and Java by O'Reilly
Head First Java 2nd Edition
http://java.sun.com/javase/technologies/desktop/
JAVA Technologies
JAVA Complete Reference
Head First EJB Sierra Bates
Software Engineering by Roger Pressman
http://www.google.com
http://www.microsoft.com
http://www.programmer2programmer.net
http://www.codeproject.com
http://www.msdn.com.
SQL Bible, 2nd Edition
Beginning Java Objects: From Concepts to Code by Jacquie Barker)
Introduction to Java Programming (NIIIT publication)
The Complete Reference Java(McGraw-Hill, Herbert Scheldt- reprint 2008)
Page 14