Software Engineering - SE101 1. JDK Documentation
Software Engineering - SE101 1. JDK Documentation
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
1. JDK Documentation
The on-line JavaTM Platform, Standard Edition (Java SE) Documentation contains API
specifications, feature descriptions, developer guides, reference pages for JDK tools and utilities,
demos, and links to related information. This documentation is also available in a download
bundle which you can install on your machine.
2. Compatibility
See Compatibility with Previous Releases on the Java Software web site for the list of known
compatibility issues. Every effort has been made to support programs written for previous
versions of the Java platform. Although some incompatible changes were necessary, most
software should migrate to the current version with no reprogramming. Any failure to do so is
considered a bug, except for a small number of cases where compatibility was deliberately
broken, as described on our compatibility web page. Some compatibility-breaking changes were
required to close potential security holes or to fix implementation or design bugs.
This section contains a general summary of the files and directories in the JDKTM. For details on
the files and directories, see the JDK File Structure section of the Java SE documentation for
your platform.
Development Tools
(In the bin/ subdirectory) Tools and utilities that will help you develop, execute, debug,
and document programs written in the JavaTM programming language. For further
information, see the tool documentation.
Runtime Environment
(In the jre/ subdirectory) An implementation of the Java Runtime Environment for use
by the JDK. The JRE includes a Java Virtual Machine , class libraries, and other files that
support the execution of programs written in the Java programming language.
Additional Libraries
(In the lib/ subdirectory) Additional class libraries and support files required by the
development tools.
1
Date: 21 Aug 2010
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
Sample Code
(In the sample subdirectory) Samples, with source code, of programming for certain Java
API's.
C header Files
(In the include/ subdirectory) Header files that support native-code programming using
the Java Native Interface, the JVM Tool Interface, and other functionality of the Java
platform.
Source Code
(In src.zip) Java programming language source files for all classes that make up the
Java core API (that is, sources files for the java.*, javax.* and some org.* packages, but
not for com.sun.* packages). This source code is provided for informational purposes
only, to help developers learn and use the Java programming language. These files do not
include platform-specific implementation code and cannot be used to rebuild the class
libraries. To extract these file, use any common zip utility. Or, you may use the Jar utility
in the JDK's bin/ directory:
class Point{
int x,y;
void offset(int ox,int oy){
x = x + ox;
y = y + oy;
}
}
class Program{
public static void main(String[] args){
Point p1 = new Point();
2
Date: 21 Aug 2010
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
p1.x = 10;
p1.y = 10;
p1.offset(2,2);
}
}
When this program runs, the reference variables ‘p1’ and ‘p2’ are present on the stack whereas
the actual objects of type ‘Point’ are created on the heap by the JVM. This is as shown in the
figure.
The instruction new Point() tells JVM to create an object of type Point. JVM always
creates these objects on the heap, and returns the reference to the reference variable (p1 and p2 in
this example). The members of the createde objects can now be accessed using the reference
variable. The referecne variable p1 and p2 are created on the stack because they part of the
main() function.
3
Date: 21 Aug 2010
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
6. –classpath option
Whenever the java command is invoked the JVM searches for the class files using the
CLASSPATH environment variable .By default this is set to the current directory .If the –
classpath is given explicitly in the command line then we need to type the current directory as
“.”” .The following is the syntax for the java command
java –classpath
classpath <classpath1>;<classpath2>
7. Example of –classpath
classpath usage
Lets consider our simple example Example1.java
Source code:
4
Date: 21 Aug 2010
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
class Point {
int x,y;
x = x+ox;
y=y+oy;
Class Program{
javac Example1.java creates two class files Program.class and Point.class in the same
directory.
java Program.java
gives …
x= 0, y= 0
Lets create a directory called Lib and put the Point.class in it. So the final structure of our
directories looks like this.
5
Date: 21 Aug 2010
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
C:\JavaProjects
Program.class
Lib
Point.class
This is because the java command is not able to find the Point.class in the current directory. So
what we can do to correct this error is to add -classpath option with the Lib as well as the
current directory “.”
Note that we did not have to give the classpath for the class System which prints the
output because the command ,by default adds the rt.jar into the classpath.
6
Date: 21 Aug 2010
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
Ø The method offset() will be there in the memory only once and all the refernces uses this
method only.
Ø Now the problem is when we have more than one reference objects how do the offset()
method know on which reference it is performing operations.
Ø To remove this conflict what JIT compiler do is it will introduce a new argument in the
method which holds the information of the reference which is calling the method.
this.x+=ox;
this.y+=oy;
now there will be no confusion and the single copy of method works on all the objects of that
7
Date: 21 Aug 2010
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
8. Constructor
When an object is created, compiler performs 2 main functions
functions-
Ø memory allocation.
Ø initialization of object.(done by calling constructors).
JAVA virtual machine(JVM) allocates memory to the object, and then the constructors are
called. In JAVA, objects are created on heap, as they are allocated dynamically. Constructors are
used to instantiate
stantiate and possibly initializ
initialize an object.
For eg.
class Area
{
int radius;
Area(int radius)
{
this.radius = radius;
}
}
In JAVA, if you do not define a constructor when you define a new class, a default constructor
that takes no parameters is defined on your behalf by source code compiler.
8
Date: 21 Aug 2010
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
class Circle
{
private int radius;
Circle(int radius)
{
this.radius = radius;
}
int area(void)
{
return (22/7)*radius*radius;
}
}
int getRadius(){
return radius;
}
class Program
{
public static void main(String a[])
{
Circle circle1=new Circle(5);
Circle circle2=new Circle(15);
int area1 = circle1.area();
//at the run time compiler will pass it as: circle.area(/*value of
circle1*/).
int area2 = circle2.area();
}
}
In case, we have not made any constructor, the compiler makes an inbuilt constuctor.
Area(/*radius this*/,int radius)
{
this.radius=radius;// this is used to tell to use 'this ' object
value.
}
9
Date: 21 Aug 2010
Session No: 1
Name of the Instructor: Shakeel
Group No: 1
Ø Here the radius is accessible only using getRadius and the setRadius method. This helps
in adding any new constraints in the future and also prevents direct access of the data
members.
10