Help coderanch get a
new server
by contributing to the fundraiser

Yogesh Baraskar

Ranch Hand
+ Follow
since Oct 07, 2007
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 Yogesh Baraskar

toArray(Object[]) method returns an array of type object passed as parameter.

Question: Once any array is initialized its size cannot be changed.
how this is happening in below code.


Hi Keith,

public abstract boolean equals(java.lang.Object);

it has abstract keyword , that means we must provide implementation in the class which implements Comparator interface?
Hi

I ran javap java.util.Comparator and got the results as:
Compiled from "Comparator.java"
public interface java.util.Comparator{
public abstract int compare(java.lang.Object, java.lang.Object);
public abstract boolean equals(java.lang.Object);
}

IN K and B book at page number 554 line 7 says that
The comparator interface has only one method compare()

but in interface we have equals() method also.

Then i tried
class ListSorting implements Comparator<String>
{
public int compare(String ob1, String ob2){
return ob2.compareTo(ob1);
}
}


It got compiled with any error.

Where is the equals() method?
Hi

I tried the inner class of my first post in another class as

public class TestInner
{
public static void main(String... args)
{

MyOuter mo = new MyOuter();
MyInner mi = mo.new MyInner(); //Line 3
}

}


now Line 3 is giving me compiler error .
This is a catch as Line1 is not giving error.

Dear Modirators , please provide some explanation to this behaviour.

Regards,
Yogesh
public class MyOuter{
private int outer=10;

public class MyInner{
public void show(){
System.out.println("in inner class" + "Outer var is :"+outer);
}
}

public static void main(String... args)
{
MyOuter mo = new MyOuter();
MyInner mi1 = mo.new MyInner(); //Line1
MyOuter.MyInner mi2 = mo.new MyInner(); //Line2

mi1.show();
mi2.show();

}

}


Is there any difference between line1 and line2, the way
they have declared inner class reference variable m1 and m2.

Both of them are compiling well and giving the same result.
You have not mentioned what raise() is returning.

Regarding the operator precedence
both * and / has same priority.
So always evaluate your expression from left to right
Assuming raise() is returning 0, your expression
will first evaluate currentSalary / 100 this gives you 1.0
and then multiplication by 0 , so results is 0.0
Hi

This is perfectly legal.
You can declare any runtime exceptions
Hi

Plese send the complete source code which you are trying to compile
public abstract class Canine { public Bark speak();}

speak(); // the brackets and then semicolon suggests that it is an abstract method and you should declare it as
public abstract Bark speak();

or else if you dont want to declare method as abstract then make it
public Bark speak(){
}
this is a ternary if operator
Byte b1= new Byte(100);
literals like 100 are of integer type by default.

To create a Byte object using new you should pass a byte

Try this
Byte b1= new Byte((byte)(100));
This is just a coincidence.
i3 an i4 both exceeded 127 so objects reference will be used
to compare instead of the value.

Sometimes it may return false also. Try creating object i4 before i3 and then compare.
Matcher class's matches() methods in similar was as
if some body gives you a pattern and ask to find out what all the matches are.
e.g if there is list of students names
and someone asks you give me all names that starts with D and ends with H
then you need to define a pattern using
Pattern p = Pattern.compile(starts with D and ends with H) //regularexpression

Then use
Matcher m = p.matcher("List of students ");
Hi,

readObject(ObjectInputStream)/writeObject(ObjectOutputStream) is defined in a class implementing Serializable interface to customize the serialization process. Note what is the logic behind implementing this.
We need to do this when we want to save the state of a transient variable
of the class. Now you are saying we could have defined these methods in a subclass of ObjectInputStream/ObjectOutputStream but had we done that how you will be able to implement logic to save the state of your transient variable.
When we implement readObject(ObjectInputStream)/writeObject(ObjectOutputStream) methods in the class we get the oppurtunity to save / retrieve the transient variable values and then the default readObject()/writeObject() methods is called by JVM when these methods execute.

JVM just check for the Serializable Marker interface. It suggests JVM that you can serialize the object.

Hope this helps.

Regards,
Yogesh
Only objects are garbage collected.

Static belongs to class. So when class is onloaded then only
static variable will be destroyed.