Pandey Gautam

Greenhorn
+ Follow
since Nov 05, 2008
Merit badge: grant badges
For More
Bangalore,India
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Pandey Gautam

Hi Ankit,
I read somewhere that import.lang is implicit import for any java file.
Is it correct?
sorry typo error

Without giving comma between two curly braces we can't define the size of an array in above type of declaration. If comma will be not their, it will be syntax error.
Without giving comma between two curly braces we can define the size of an array in above type of declaration. If comma will be not their, it will be syntax error.
Originally by Punit


main(){
...
t1.start();
t1.join();// here main thread is calling join() on t1 thread, so main thread will wait until t1 thread completes its work.
...

}



ya you are right punit and what the question is asking.


Original question is
Which of the method causes the currently executing thread object to temporarily pause and allow other threads to execute???

sleep()
wait()
notify()
yield()
join().


join() will stop current executing thread for sure in which it is called and start new thread which is calling join(). it is different thing if other thread is calling wait() or went to deadlock etc.
Hi,
Comma has meaning here. It determines the number of entry in the array.
lets example
int[][] abc = {{1,2},{1,2}}
// here array abc is something like int[][] a = new int[2][2] with values.
Hi,
join() is only method which stop currently executing thread and allow other thread to execute.
wait() may stop thread forever if notify is not called or time is not passed as arguments to wait(long time).

yield() didn't guarantee of executing other thread, it just preempted the current executing thread from running state to runnable.

sleep() make current thread to stop for given time and let other thread to execute.

So from my view only join and sleep are correct answer.
Hi Ganesh,
It is caught and handled in method() so why it will be caught in main() again.
11) Imagine that you have directory called test1 in C drive containing some files,
within which there is a directory called test2 (sub-directory of test1) containing
some other set of files. Considering this, what statements are true about the
following program?

1. The program will list down all the files within the directory test1 and test2
2. The program will list down only the files in directory test1
3. The program will list down only the files in directory test2
4. The program will run infinitely.

Hi Campbell,
I have chosen 2nd option but answer was given 1st one. I have run the code and I got 2nd option only. So it means I was right.

Thanks
Imagine that you have directory called test1 in C drive containing some files,within which there is a directory called test2 (sub-directory of test1) containing some other set of files. Considering this, what statements are true about the following program?

package io;
import java.io.File;
import java.io.FileFilter;
public class DirLister {
public static void main(String[] args) {
String path = "C:\\test1";
list(path);
}
static void list(String path){
File fileObject = new File(path);
if (fileObject.exists()){
if (fileObject.isDirectory()){
System.out.println("Dir-->" + fileObject.getAbsolutePath());
File allFiles[] = fileObject.listFiles(new MyFileLister());
for (File aFile : allFiles){
list(aFile.getAbsolutePath());
}
}else{
System.out.println("File-->" + fileObject.getAbsolutePath());
}
}
}
}
class MyFileLister implements FileFilter{
@Override
public boolean accept(File pathname) {
return pathname.getAbsolutePath().endsWith(".bmp");
}
}
1. The program will list down all the files within the directory test1 and test2
2. The program will list down only the files in directory test1
3. The program will list down only the files in directory test2
4. The program will run infinitely.
Answer is right and Source is javabeat.
Could you explain please?
First thing fruit is method variable and local to method1. So it cannot be modify by other method i.e. transform (String fruit) without returning value to that method. Main region of not getting modify is the void return type of transform method.
I tried this question but I could not find the satisfying explanation of answer of below question.

List <? super Integer> al = new ArrayList<Number>(); //line 1
al.add(12); //line 2
al.add(12+ 13); //line 3
for (Number no:al) //line 4
{
System.out.println(no);
}

What will be the possible result of the above program?

a) Error at Line 1
b) Error at Line 2
c) Error at Line 3
d) Error at Line 4
e) Compile and execute Sucuessfully