Shaili Merchant

Greenhorn
+ Follow
since Nov 20, 2007
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 Shaili Merchant

Thanks..but pls let me know when generally ppl receive the mail from sun
11 years ago
Hello All,

I cleared the test last week on 19th with 83%.
I read the K&B book just once and gave all free mock test available on net.
It took me 2 mnths to prepare.
However I have still not received any mail from sun regarding the same.
Please let me know hw long it takes for the mail to come??
11 years ago
Assume that in the current directory test.txt file is already exist. What will happen when you execute the following code?

import java.io.*;
class Test
{
public static void main(String args[])
{
try
{
File file = new File("test.txt");
file.createNewFile();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}

a)text.txt will be created and overwrite the old file
b)file will not be created
c)exception will be thrown
d)none of the above.

When I tried the code on my machine no new file is created and no exception also thrown. But the answer provided is C. Please let me know whether option B is correct or option C
Answer that they have provided is c&d
Please do provide me an explanation hw to go bout solving this .
Question 14:The question is about arrays and generics. Which of the following lines can be compiled?
a)Basket<Apple>[] b = new Basket<Apple>[10];
b)Basket<?>[] b = new Basket<Apple>[10];
c)Basket<?>[] b = new Basket<?>[10];
d)public <T> T[] test() {return null;}
e)public <T> T[] test() {return new T[10];}


All of them seem to be correct to me except C
Please explain me the concept
Don't we require to sort the array prior to searching according to pg no 557 of K&B book ???Otherwise it gives unpredictable results

Or is it that this is not applicable in the above code because it is already sorted??
[ December 12, 2007: Message edited by: Shaili Merchant ]
I have encountered another doubt.
Please help me out.

new Short("0x1") ;// This gives a runtime exception because Short constructor takes only short or String but the argument (0x1) is an int.

new Short("011") ;//Then the same reasoning should apply here too since (011) being an octal no is an int.
Why doesnt this give me an exception??
Yes..I feel I wud hav to go through the API again..
Thanks.
Ok so if that is the case then
here is my next doubt:
1)
Byte b=new Byte(10);// This gives Compiler error
because by default 10 is considered to be an int.so it requires typecasting to a byte to compile correctly.
2)
Float f=new Float(3.5);
This should also give compiler error because 3.5 by default is a double.
But there is no error .
What is the reason for that.
I am sorry for this doubt but jus gettin my basics clear.
Thank you.
Look at this piece of code taken from http://www.geocities.com/sahirshah/applets/mocktest.html

char c = 4 * 4;
String s = "b";
System.out.println(Byte.parseByte(s,c));
My Doubt:
According to the API, parseByte method takes String and int as the parameters.So in the above code how does the compiler allow char to be passed as the second argument??
Alrite...thanks..but I hope such kind of questions wont b there in the real test.
I m currently takin mock tests and in every test I found atleast question that is a lil' dodgy to answer like the one I hav mentioned above.
I hope we wont have problems with the language used in the real test.
Hello Kelvin,
So does that mean that whenever the JVM is low on memory, the garbage collector for sure runs??At that point in time its behaviour is guaranteed??
This question belongs to http://www.jchq.net/phezam/showquestion.php mock test


class Box{
private int iVolume;
Box(int iVolume){
this.iVolume=iVolume;
}
public void finalize(){
System.out.println("finalizing a Box");
}
}

public class EdGrundy{
boolean stop = false;
public static void main(String argv[]){
new EdGrundy();
}
EdGrundy(){
while(stop==false){
new Box(99);
}
}
}
OPTIONS:

1 Compilation but no output at runtime
2 Compilation and eventually multiple outputs of "finalizing a Box"
3 Compilation error, faulty use of new operator within method main.
4 Compilation, but runtime Exception
Correct Ans:2

My Doubt:As much as I have read and understood from K&B book is that
finalize method must run once and only once if at all it runs.
So Is finalize method guaranteed to run?? If it is not guaranteed that finalize would run then hw 2 would turn out to be correct option??
Alrite..Now I have finally understood the question completely and correctly.
Earlier interpretation of mine didnt consider the other alternatives...
Now I suppose the answer should be C only.
Please confirm it.
Thanks