Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

reg a mock exam

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Iam unable to solve the following ques please help me.Iam plamming to tkae scjp5 within a week iam unable to find mock ques related to reg expression.
thanks in advance
sankar
Question 13: There are a number of labels in the source code below. These are labeled a through j. Which label identifies the earliest point where, after that line has executed, the object referred to by the variable first may be garbage collected? class Riddle {
public static void main(String[] args) {
String first, second;
String riddle;
if (args.length < 2)
return; a: first = new String(args[0]);
b: second = new String(args[1]);
c: riddle = "When is a " + first;
d: first = null;
e: riddle += " like a " + second + "?";
f: second = null;
g: System.out.println(riddle);
h: args[0] = null;
i: args[1] = null;
j:
}
}
Select the one right answer.
d:
e:
h:
i:
j:
Question 46: If you supply a target object when you create a new Thread, as in: Thread t = new Thread(targetObject);
What test of instanceof does targetObject have to pass for this to be legal?

Select the one right answer.

targetObject instanceof Thread
targetObject instanceof Object
targetObject instanceof Applet
targetObject instanceof Runnable
targetObject instanceof String

Question 47: What appears in the standard output when you run the Dots class?
class Dots implements Runnable {
DotThread t;
public static void main(String[] args) {
Dots d = new Dots();
d.t = new DotThread();
}
public void init() {
t.start();
t = new DashThread().start();
}
}
class DotThread extends Thread {
public void run() {
for (int index = 0; index < 100; index++)
System.out.print(".");
}
}
class DashThread extends Thread {
public void run() {
for (int index = 0; index < 100; index++)
System.out.print("-");
}
}
nothing
100 dots (.)
200 dots (.)
100 dashes (-)
100 dots (.) and 100 dashes(-)

Question 55: What will happen when you attempt to compile and run the following program by passing the Test class to the Java interpreter? class Test {
public static void main() {
System.out.println("hello");
}
}
Select the one right answer.


The program does not compile because main() is not defined correctly.
The program compiles but when you try to run the interpreter complains that it cannot find the main() method it needs to run.
The program compiles but you cannot run it because the class is not declared as public.
The program compiles and runs without an error but does not display anything in the standard output.
The program compiles and displays "hello" in the standard output when you run it.
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sundar sankar:
Question 13:
Question 47:
Question 55:

What do you think is the correct answer and why?

Question 46:

Have a look at the Thread API documentation.

PS: It is helpful if you make an own thread for each question.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It could be better if you also mention what you think are the right answers.According to me following are the correct answers. If they are wrong please correct me..

Question 13: h
Question 46: targetObject instanceof Runnable
Question 47: nothing
Question 55: The program compiles but when you try to run the interpreter complains that it cannot find the main() method it needs to run.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by R Kumar:

Question 13: h



Hi R Kumar

Answer to 'Question 13' is - d: first = null;

have a look - first = new String(args[0]);

since a new object is created (using 'new' operator) and assigned to reference 'first', this object is not referred by any other object in the given code. Therefore, line 'first=null;' makes the object referred by 'first' eligible for garbage collection.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/view?UseAMeaningfulSubjectLine
http://faq.javaranch.com/view?UseOneThreadPerQuestion
http://faq.javaranch.com/view?QuoteYourSources
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic