nishant vats

Greenhorn
+ Follow
since Feb 11, 2005
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 nishant vats

i am also interested mail me at vatsanishant@yahoo.co.in
18 years ago
int k=944444444;
float f2=k;
System.out.println("f2 "+f2);
output is :f2 9.4444442E8

int k=94444444;
float f2=k;
System.out.println("f2 "+f2);
output is :f2 9.4444448E7

Note that in frist case there are 9 digits while in second case its 8 digits..
pls explain the output
public class AQuestion
{
private int i = j;
private int j = 10;
public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}

Answers

a)Compiler error complaining about access restriction of private variables of AQuestion.
b)Compiler error complaining about forward referencing
c)No error - The output is 0;
d)No error - The output is 10;

answer b

Q2)public class AQuestion
{
private int i = giveMeJ();
private int j = 10;

private int giveMeJ()
{
return j;
}

public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}

Answers

a)Compiler error complaining about access restriction of private variables of AQuestion.
b)Compiler error complaining about forward referencing.
c)No Compilation error - The output is 0;
d) No Compilation error - The output is 10;

Answer c

these are 2 questions i found in one of the mock exams.The first once answer is b.i thgt the second onces answer would also be b.But its c.Please do explain why the answer for the 2nd question is c.
code
char s1 = (char)78890;
int i1 = s1;
System.out.println(i1);

output
13354


while downcasting there is modulo divison..
am nt able to get the above value
1)while(false){
System.out.println("n");
}
Compile time error "Unreachable statement:"

2)
if(false){
System.out.println("h");
}

No compile time error

i cant understand why there is no complie time error for second case
Am confused abt locks...can u explain what is concept of lock...in following code i have two thread objects _th1,_th2 can anyone explain who will acquire the lock becoz they themselves are thread object...i am nt still able to get that "thread will acquire the lock on object.." here what is thread and object ? pls clearly distnguish between thread and object..

class ThreadExample extends Thread{
public void run(){
System.out.println("Execting run");
}
}
public class ThreadSim {
public static void main(String args[]){
ThreadExample _th1 = new ThreadExample();
_th1.start();
ThreadExample _th2 = new ThreadExample();
_th2.start();
}

}
Am confused abt locks...can u explain what is concept of lock...in following code i have two thread objects _th1,_th2 can anyone explain who will acquire the lock becoz they themselves are thread object...i am nt still able to get that "thread will acquire the lock on object.." here what is thread and object ? pls clearly distnguish between thread and object..

class ThreadExample extends Thread{
public void run(){
System.out.println("Execting run");
}
}
public class ThreadSim {
public static void main(String args[]){
ThreadExample _th1 = new ThreadExample();
_th1.start();
ThreadExample _th2 = new ThreadExample();
_th2.start();
}

}
Trying dis code

URL url = new URL("http://www.yahoo.com/");
URLConnection conn = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

but getting exception as
java.net.UnknownHostException: www.yahoo.com

Is there some error in code
18 years ago
i have tried this also

File _file = new File(""..\\Nishant.properties");
System.out.println("*******Canonical path******"+ _file.getCanonicalPath());

but before exception is thrown while getting the handle of file so unable to see the SOP Message...

Nw Can you Clarify that.. :roll:
18 years ago
i want to open a file using realtive path...code goes here

new FileInputStream("..\\Nishant.properties")

but i am getting error
java.io.FileNotFoundException: ..\Nishant.properties (The system cannot find the file specified)


i have to acess the file using relative path ...Can I do that.
18 years ago
This is regarding threads.I am nt able to understand how threads can be helpful on single processor with respect to execution time.Because if we drill down to processor level(Single processor) then only one task can be executed at particular point.I am nt able to get how threads can reduce the execution time .i have searched a lot but unable to get satisfactory answer.

Can anyone explain with the help of web Server or download accelator.they are best examples of multithreading
According to me only one object will be elgible for garbage collection..i.e
new Integer(10);
this object has refernce count =0;as u can check .Intially this object was refrenced by x but when x=y is executed .This object is no longer refrenced.
new Integer(99) is being still refernced by y.so only one object is elgible for garbage collection
Can anyone explain with the help of web Server or download accelator.they are best examples of multithreading
This is regarding threads.I am nt able to understand how threads can be helpful on single processor with respect to execution time.Because if we drill down to processor level(Single processor) then only one task can be executed at particular point.I am nt able to get how threads can reduce the execution time .i have searched a lot but unable to get satisfactory answer.