Munish Dabra

Greenhorn
+ Follow
since Jan 07, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Munish Dabra

import java.lang.Math;
class MathAbsSup
{
public static void main(String args[])
{
System.out.println(Math.abs(Integer.MIN_VALUE));

}
}
//Why Math.abs() is giving negative output??? (-2147483648)
Acually
f=a statement is equalent to
GenericFruit f = new Apple();
that means f is a super class reference to subclass object a.
Now Acoording to superclass refrence rules
--Superclass refrence determines the varible.
--Subclass object determines the method.
Note: here if u call a method which has been overridden by ur subclass
Apple.and u did same i.e
f=a;
f.amethod();
then overridden method of subclass will execute.because method is determined by
underlying subclass object.
i hope u will get it.
regards
-------
Munish Dabra
--------
class MyGC
{
static int num;
MyGC(int n)
{
num=n;
}
public static void main(String ar[])
{
MyGC var1=new MyGC(2);
var1=null;
System.gc();
double array[]=new double[999999]; //Suggestion for gc to run
MyGC var2=new MyGC(1);
var2=null;
System.out.println("Yahoo! i am exiting main()");
}
protected void finalize() throws Throwable
{
System.out.println("i am known as Mr. finalize "+num);
}
}

output:
-------
Yahoo! i am exiting main()
i am known as Mr. finalize 1
i am known as Mr. finalize 1
waht's happening.it is executing finalize for avr2 twice.it just can'nt possible.
--------------------------------------------------------------------------------
constructing like
RandomaccessFile raf=new RandomAccessFile("xxx","rw");
what will happen if the file xxx is read-only and we try to write.
if the file xxx exist it is opened in append mode true or false
Also if we wrap a string fxx
as
File f=new File("fxx");
it will compile but when run it will throw exception if fxx
doesnot exist true or false
if true where the file fxx is looked for in current directory or
else
pls clarify my confusion.or i am missing something.
-----------------------------------------------------------------------
Ans. File f=new File("fxx");
Yeah if there is n't any such file exists then at run time iit will throw an IOException.
ya amrit ofcourse fxx file is looked in current directory by default.
if u wanna this it to look in some particular directory.then u have to use a different
constructor of File-----
File f=new File(String path,String filename)
or
File f=new File(File dir , String filename)
here plz note that File object can be a directory or file.ucan check it by
calling boolean method of File class
boolean isFile() or isDirectory().
i hope it will serve the purpose.
------
Munish Dabra
------
i found that
-first by calling System.gc() and suggesting GC to garbage collect th object by allocating some free memory.
-immediate after that i declare the object to be null.
-then print statement in the finalize executed 2 times.Why?
No Tom Object serialization and Reflection both r not covered in the Scjp 's exam.
They both did the same job.what actually makes them different at back end