mukki pandey

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

Recent posts by mukki pandey

Thanks Rekha

I got your point.
String s1 = new String("Hai");
String s2 = "Hai";
String s3 = new String("Hai").intern();
System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s2 == s3);

please tell me output with reason ..

Source:-Java Beat Mock Exams
Thanks Rekha

can't we write as for(List< ? super Dog> d : animalList)
I tried to create new files Animal class and DOg class which extends Animal and genericTesting Class which makes use of Animal and Dog class.I am facing problem in using new for loop as per Java 1.5

import java.util.ArrayList;
import java.util.List;

public class GenericTesting extends Animal {

* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
List<? super Dog> animalList= (List<? super Dog> new ArrayList<Dog>();

Animal animalObject = new Animal();


DOg Class

public class Dog extends Animal{


Animal Class where i am getting compiler error on for loop

import java.util.List;

public class Animal {

public Animal(){

System.out.println("I am animal ");

public void addAllAnimals(List<? super Dog> animalList){
animalList.add(new Dog());

for(List<Animal> d : animalList)


what should be the syntax for ..FOR loop

how do i iterate through animal list which can be dog or animal as i have used wildcard with super keyword

Thanks in advance

Source:My own
Given a properly prepared String array containing five elements, which

range of results could a
proper invocation of Arrays.binarySearch() produce?
A. 0 through 4
B. 0 through 5
C. -1 through 4
D. -1 through 5
E. -5 through 4
F. -5 through 5
G. -6 through 4
H. -6 through 5

3 G is correct. If a match is found, binarySearch()will return the
index of the element that was matched. If no match is found, binarySearch() will return a negative number that,if inverted and then decremented, gives you the insertion point (array index) at which the
value searched on should be inserted into the array to maintain a
proper sort.
A, B, C, D, E, F, and H are incorrect based on the above. (Objective

Can any one please expalin me why only G

Source KB Book
The Arrays.sort()
methods that sort primitives always sort based on natural order.

Don't be fooled by
an exam question that tries to sort a primitive array using a Comparator.

I am not able to understand above line in KB book page 256
Thanks sumi

Source is Examulator .Question a day
but then where does immutabilty comes in picture in KB book i saw e.g like

s.concat without assigning doesnt changes the value otherwise if you
do like s= s.concat("abc");

then value changes
shyam thanks alot this was wonderful explanation
public class Stngcheck {

* @param args
public static void main(String[] args) {
Stngcheck ss = new Stngcheck();
String s1="1";
String s2="2";


public void go(String s3){


Hi Javaranchers

since string is immutable object why does s2 prints 1 i know this is pretty silly but i want to know pleaseeeeee
Which of the following statements are true?
1 A reference to a primitive is eligible for garbage collection when it is set to zero.
2 A reference to a primitive is eligable for garbage collection when it is set to null.
3 An array object is eligible for garbage collection when it is no longer reachable.
4 Setting an object reference to null will guarantee the object is eligable for garbage collection.

I thought answer should be 2 and 3,4 but its just 3. ..can any one please expalin me why only 3 and not others

Thanks Javaranchers
i posted so because in my office i dnt have jdk1.5 :-(

sorry for asking such silly question
Which of the following statements are true?
Incorrect options are shown by strikethrough, any options you chose are marked by a tick
1 A variable marked as private is visible only within the current class and any child classes
2 a primitive created within a method may not be marked as private
3 A primitive variable created within a method may be marked as static
4 A constructor can never be marked as private

The Correct Answer is
2) a primitive created within a method may not be marked as private.
There is no rules against constructors being marked as private. Private variables are only visible within the current class, not child classes.

If construtor can be marked as private then how we will instantiate a class

please answer this.I think 4 was also correct option

Source is Examulator site