Professional Documents
Culture Documents
in
Core Java
By
Rahul karmakar
2813231
ECE(4th year)
JAVA FUNDAMENTALS
Introduction to java
Principle of OOPs
JDK and JRE
Byte Code and JVM (Java Virtual Machine)
Platform Independent
Applications and Applets
Features of Java :
Contents
Fundamental Principles of OOP
1. Inheritance
2. Encapsulation
3. Polymorphism
Inheritance
Encapsulation
Polymorphism
Access a class through its parent interface
Inheritance
Encapsulation
Encapsulation hides the implementation details
Class announces some operations (methods) available
for its clients its public interface
All data members (fields) of a class should be hidden
Accessed
Polymorphism
1.
2.
Exact
Java Program
Java Compiler
Source Code
Virtual Machine
Bytecode
Process of Compilation
Bytecode
Virtual Machine
Java Interpreter
Machine Code
Real Machine
Java
Source
Code
Java Compiler
Application Type
Applet Type
Java
Enabled
Browser
Output
Java
Interpreter
Output
JAVA CONTROLS
Selection Statement
if
If-else
Iteration Statement
switch
Jump Statement
break
while
do
for
conti
nue
return
JAVA Classes
NSIT ,Jetalpur
Multithreading
Multitheading is specialized form of multitasking. like windows and other os uses multitasking
technique i.e. they handled more than one process at a time, the same thing we can do in Java
using multithreading technique.
A thread is similar to a program that has a single flow of control. It has a beginning, a body, and
an end,and executes commands sequentially. Java enables us to use multiple flows of control in
developing programs.
Each flow of control is represented by thread that runs parallel to others. i.e. a program that
contains multiple flows of control is known as multithreaded program.Threads in Java are
subprograms of a main application program and share the same memory space, known as
lightweight threads or lightweight process.
Threds running in parallel does not mean that they actually run at the same time. Since all the
threads are running on the same processor, the flow of execution is shared between the threads.
The Java interpreter handles the switching of control between the threads in such a way that it
appears they are running concurrently.
Creating Threads :
Threads are implemented in the form of objects that contain a method called run(). The run()
method
is the heart and soul of any thread.
New Thread
stop
start
stop
Running
Active
Thread
yield
Runnable
Dead
Killed
Thread
suspend
sleep
wait
Idle Thread
(Not Runnable
resume
notify
Blocked
stop
APPLET
An applet is a program that can be referenced by the html source code of web page. It is
dynamically downloaded from a Web Server to a browser. The applet then executes within the
environment provided by the browser. Alternatively you may use a tool such as the appletviewer
to run it.
It is important to recognize that downloading code from the Internet and executing it on your
computer is inherently dangerous. Therefore, applet do not have the same capabilities as Java
applications. They are restricted to operating within the confines of a sandbox. In other words
code that is untrusted is not allowed to operate outside certain boundaries.
For Example, applets are normally not allowed to read or write to your local disk. This would
obviously be risky because they could accidentally or maliciously destroy any data stored on that
device.Applet can not execute any native code.
An applet may open a socket connection back to the host from which it was downloaded, but not
to any other host. The reason for this restriction can be understood if you imagine a configuration
in which a firewall protects a corporate Intranet from computer hackers. Assume that an employee
has downloaded an applet from internet to an PC or workstation. If that applet is allowed to open
sockets to any machine, it would then have the potential to steal proprietary information and send
back to the hackers machine. This must be prevented. Therefore, an applet is not allowed to
contact any of those private machines.
Applet do not use main() method for initiating the execution of the code. Applets,
when
loaded, automatically call certain methods of Applet class to start and execute the applet code.
Unlike stand-alone applications, applet can not be run independently. They are
run from inside a web page using a special feature known as HTML tag.
Applets cannot red from or write to the files in the local computer.
2.
3.
4.
Preparing <Applet> tag, Incorporating <applet> tag into the Web Page.
5.
Begin Applet
Initialization
Born
(Load Applet)
stop()
start()
Display
paint()
Running
Idle
destroy()
start()
Destroyed
Stopped
Dead
End
Initialization State : Applet enters the initialization state when it is first loaded. This is achieved by calling
the init() method of Applet Class.The applet is born. We required following at this stage :
Create objects needed by the applet.
Set up initial values
Load images or fonts
Set up colors