Professional Documents
Culture Documents
java.lang
Nguyen Viet Dung ITITIU14020
Tran Thach Tran ITITIU14119
Nguyen Minh Tri ITITIU14098
Pham Do Minh Quan
ITITIU14083
Pham Tuan Hai ITITIU13019
1. General
1.
General
The
Java package java.lang contains fundamental
classes and interfaces closely tied to the language and
runtime system.
This includes the root classes that form the class
system, types tied to the language definition, basic
exceptions, math functions, threading, security
functions, as well as some information on the underlying
native system.
public boolean
equals(Object obj)
public String
toString()
public Object clone()
throws
CloneNotSuppotedExcep
protected
tion
void
finalize()
throws Throwable
public native int
hashCode() public Class
getClass()
class
String s;
MyClass{
public MyClass(String s) {
this.s = s;
}
public void
throws finalize()
Throwable {
cleanupAllResources(); //
The method that cleans up
}
private
cleanupAllResources() {
void
// do some relavant
task
System.out.println("I
am
dying....
: says
"+s);
}
}
This method is
overridden to free up
extra resources when
they are no longer in use
and subject to Garbage
Collection once the
object is eligible to be
swallowed up by the
garbage collector
This works very much
These
like the
methods
destructors
is only
in C+
for
+ system purpose
and optimization and
its execution is subject
to GC, depending on
the VM and platform
and Execution
Environment and
timeline
class MC
{ int
marks;
String name;
publicMC(int marks, String
name)
{ super();
this.marks =
this.name = name;
marks;
}
void show()
{
System.out.println(name
+
" scored " +
marks);
}
this.marks
Void
setMarks(int
marks) {
=
}
marks;
}
class
MyClass{
}
public class Main1 {
public staticvoid
main(String[] args) {
MyClass obj=new MyClass();
System.out.println(obj.toString()
);
}
}
Output:MyClass@addbf1
System.out.println("The
Math.floor(i));
System.out.println("The
Math.floor(j));
System.out.println("The
Math.floor(x));
System.out.println("The
Math.floor(y));
System.out.println(
the square root of " + i + " is " + Math.sqrt(i)); }
System.out.println("Here's one random number: " +
Math.random());
System.out.println("Here's another random number:
" + Math.random());
Finally there's one Random method that returns a
pseudo-random number between 0.0 and 1.0;
* command
public staticObjectcommand(Objectany)
Examines the argument type and its fields and perform some
documented operation. No specific operations are required.
*Enable
public staticvoidenable()
Cause the Compiler to resume operation.
*Disable
public staticvoiddisable()
Cause the Compiler to cease operation.
System.out.println(abc);
String cde = cde;
System.out.println(abc + cde);
String c = abc.substring(2,3);
String d = cde.substring(1,2);
1
public class Product{
@Override
public String toString() {
return "Product{ " + code + ", " + name + ", " + price + '}';
}
}
//Sort list
java.util.Collections.sort(products);
oduct{code=1,
price=300.0}Product{code=2, name=Iphone,
//print sortedname=TV,
list
for (Product p : products) {
System.out.println(p);
}
}
price=
RESULT
Product{code=3, name=Sony Vaio E, price=200.0}
300.0}Product{code=2,
name=Iphone,
price=600.0}Product{code=4, name=As
Product{code=1, name=TV,
price=300.0}
Product{code=2, name=Iphone, price=600.0}
Product{code=4, name=Asus E, price=800.0}