(AN AUTONOMOUS UNIT OF RANCHI UNIVERSITY FROM 2009)
- Prakash Kumar, Dept. of CA
-Raju Manjhi, Dept of CA
__________________________________________________________________________________
Java:
What
happens at compile time?
Java:
What
happens at compile time?
At compile time, java file is compiled by Java Compiler (It does
not interact with OS) and converts the java code into bytecode.
What
happens at runtime?
At runtime, following steps are performed:
|
How to set path in Java
The path is required to be set for using tools such as javac, java
etc.
If you are saving the java source file inside the jdk/bin
directory, path is not required to be set because all the tools will be
available in the current directory.
But If you are having your java file outside the jdk/bin folder,
it is necessary to set path of JDK.
There are 2 ways to set java path:
1. temporary
2. permanent
Set
Temporary Path of JDK in Windows
For Example:
set path=C:\Program Files\Java\jdk1.X.XXXXX\bin
Set Permanent Path of JDK in Windows
For Example:
set path=C:\Program Files\Java\jdk1.X.XXXXX\bin
Set Permanent Path of JDK in Windows
To set the temporary path of JDK, you need to follow following
steps:
·
Open command prompt
·
copy the path of jdk/bin directory
·
write in command prompt: set path=copied_path
For setting the permanent path of JDK, you need to follow these
steps:
Go to:
1. MyComputer properties
-> advanced tab -> environment variables -> new tab of user variable
-> write path in variable name -> write path of bin folder in variable
value -> ok -> ok -> ok
A Glance at JVM, JRE,
JDK
JVM
JVM (Java Virtual Machine) is an abstract machine. It is a
specification that provides runtime environment in which java bytecode can be
executed.
|
JVMs are available for many hardware and software platforms.
JVM, JRE and JDK are platform dependent because configuration of each OS
differs. But, Java is platform independent.
|
The JVM performs following main tasks:
·
Loads code
·
Verifies code
·
Executes code
·
Provides runtime environment
|
JRE
JRE is an acronym for Java Runtime Environment. It is used to
provide runtime environment. It is the implementation of JVM. It physically exists.
It contains set of libraries + other files that JVM uses at runtime.
|
Implementation of JVMs is also actively released by other
companies besides Sun Micro Systems.
|
JDK
JDK is an acronym for Java Development Kit.It physically
exists.It contains JRE + development tools.
JVM (Java Virtual Machine)
JVM (Java Virtual Machine) is an abstract
machine. It is a specification that provides runtime environment in which java
bytecode can be executed.
JVMs are available for many hardware and
software platforms (i.e.JVM is platform dependent).
JVM is:
1.
A specification where working of Java
Virtual Machine is specified. But implementation provider is independent to
choose the algorithm. Its implementation has been provided by Sun and other
companies.
2.
An implementation Its implementation is
known as JRE (Java Runtime Environment).
3.
Runtime Instance Whenever you write java
command on the command prompt to run the java class, and instance of JVM is created.
The JVM performs following operation:
·
Loads code
·
Verifies code
·
Executes code
·
Provides runtime environment
JVM provides definitions for the:
·
Memory area
·
Class file format
·
Register set
·
Garbage-collected heap
·
Fatal error reporting etc.
Internal Architecture
of JVM
Data Types
in Java
|
Encapsulation
|
Binding (or wrapping) code and data together into a single unit is known as encapsulation. For example: capsule, it is wrapped with different medicines.
A java class is the example of encapsulation. Java bean is the fully encapsulated class because all the data members are private here.
Advantage of OOPs over Procedure-oriented programming language
1) OOPs makes development and maintenance easier where as in
Procedure-oriented programming language it is not easy to manage if code
grows as project size grows.
|
||||||||||||||||||||
2) OOPs provides data hiding whereas in Procedure-oriented programming
language a global data can be accessed from anywhere.
|
||||||||||||||||||||
3) OOPs provide ability to simulate real-world event much more
effectively. We can provide the solution of real word problem if we are using
the Object-Oriented Programming language.
Java
Support System:-
Java Development
Kit:- The java development kit comes with a
collection of tools that are used for developing and running Java programs.
They include:-
·
applet
viewer(for viewing java applets)
·
javac(java
compiler)
· java (java
interpreter)
· javap(java
disassembler)
· javah(for C header
files)
· javadoc(for
creating HTML documents)
· jdb(java debugger)
COMPARISON B/W JAVA AND C++
1) Java does not support operator
overloading.
2) Java does not support multiple
inheritance for this we use new feature called interface.
3) Java does not support global variable.
4)
Java does not support pointers.
5)
Java uses finalize () is case of destructor. There is no use of header
files.
JAVA OFFERS TWO FLAVOUR OF
1)
Application
programming
2)
Applet
programming.
Simple application programs:
1.
class A
{
public
static void main(String args[])
{
int
x;
x=10;
System.out.println("Value
of x="+x);
}
}
2.
class Leap
{
public static void main(String args[])
{
int y;
y=1600;
if(y%4==0&&y%100!=0||y%400==0)
{
System.out.println("Year is Leap
year");
}
else
{
System.out.println("Year is not Leap
year");
}
}
}
Go through the video:
|
No comments:
Post a Comment