vini singh

Greenhorn
+ Follow
since Dec 04, 2008
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 vini singh

tomcat stdout and stderr logs are overwritten on application start, which destroys any data they might contain as to the cause of the issue that required a restart. Can we either make these rolling, or at least back up the previous one on app restart automatically, to allow for easier investigation of the root cause of issues?

13 years ago

Gave SCJP today and cleared it .now its party time....
15 years ago

its said that in order to use object as a key in map we must override equals and hashCode method.i think this makes my question clear that why is it so.

why is it required to override equals or hashCode method for hashing


please explain

class TestSer
{
public static void main(String[] m)
{
SpecialSerial s=new SpecialSerial();
try{ObjectOutputStream os=new ObjectOutputStream(new FileOutputStream("myFile"));
os.writeObject(s);
os.close();
System.out.println(++s.z + " ");
ObjectInputStream is=new ObjectInputStream(new FileInputStream("myFile");
SpecialSerial s2=(SpecialSerial)is.readObject();
is.close();
System.out.println(s2.y+ " "+s2.z);
}catch(Exception x){System.out.println("exec");}
}
}
}
class SpecialSerial implements Serializable
{
transient int y=7;
static int z=9;

}

output is:10 0 10 how as we know transient and static dont serialize therefore i think it should be 10 0 0


}
}
Pattern p=Pattern.compile("\\d*");
Matcher m=p.matcher("ab34ef");
boolean b=false;
while(b=m.find())
{System.out.println(m.start() + m.group());
}

please explain i cant follow the output of this its
0
1
2 34
4
5
6
class A{}
class B extends A{}
class C extends A{}

final class D extends B{
public void doMethod(){
A a=new B();
B b=new D();
C c=new C();
D d=null;
//Insert Here
}
}


d=(D)(B)a //how can thisline cause classcastexception
class Bird
{System.out.println("b1");
public Bird(){System.out.println("b2");
}
class Raptor extends Bird
{
static{System.out.println("r1");}
public Raptor(){System.out.println("r2");}
{System.out.println("r3");}
static{System.out.println("r4");}
}

class Hawk extends Raptor
{
public static void main(String s[])
{
System.out.println("pre");
new Hawk();
System.out.println("hawk");
}
}

can you please tell me when exaclty is the class loaded in the memory and after which statement
15 years ago
Assume that there is a class MyClass and it have 2 functions f() and g().

MyClass c1=new MyClass();
MyClass c2=new MyClass();
f(c1);
c1=null;
c2=c1;
g();

How many objects will be eligible for garbage collection by the time method g() is invoked?

output: information is insufficient to predict the result.

please explain.
class Casting
{ public static void main(String []s)
{
long l=130L;
byte b=(byte)l;
System.out.println("the byte is:"+b);
}
}
compiles fine and output is :the byte is -126

how is that possible i converted 130 to binary it came out to be '10000010' then how the answer is -126 please explain step by step.


output: DoX(s,s)=4 doX(7,7)=3
as boxing is preffered against widening i think answer should be doX(s,s)=3 but then why its dox(s,s)=4 and the reason given is boxing and then widening as its a one step process. i really cant understand help me out please explain.what do they mean by one step process

(Jesper Young: Added code tags)
[ December 11, 2008: Message edited by: Jesper Young ]
why local inner classes can be abstract/final.?look i know they cant be same at both the time.

why local class can acess only the final variable declared in the enclosing method and not other variables?

output: DoX(s,s)=4 doX(7,7)=3

according to me doX(s,s) must be 3 i.e widen and then boxing then why its 4 i.e boxing and then widening.
[edit]Add code tags and disable smilies. CR[/edit]
[ December 06, 2008: Message edited by: Campbell Ritchie ]
15 years ago
hey you are right,

something wrong with the question.

question is:


class A
{
int x=5;
}
class B extends A
{
int x=6;
}

class CT
{
public A getObject()
{
return(new A());
}
public static void main(String args[])
{
CT c=new SCT();
System.out.println(c.getObject().x);

}

}
class SCT extends CT
{
public B getObject()
{
return(new B());
}
}

output is:5 how?
15 years ago
At what point only a single object is eligible for garbage collection?

class Eco
{
public static void main(String []args)
{
Eco e1=new Eco();
Eco e2=new Eco();
Eco e3=new Eco();
e3.e=e2;
e1.e=e3;
e2=null;
e3=null;
e1=null;
}

Eco e;

}


output is:Never in this program as until last refernce is null none of the objects is eligible and when last refernce is nulled all three are eleigible.

what is meant by last refernce.n xplain the output
15 years ago