• 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

Hi all giving scjp 1.4 on this sat help needed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i am new to this forum , can any one tell me the solutions of this question , i found these on some mock test

Q1

package test2;
public class SyncTest{
public static void main(String[] args) {
final StringBuffer s1= new StringBuffer();
final StringBuffer s2= new StringBuffer();
new Thread () {
public void run() {
synchronized(s1) {
s2.append("A");
synchronized(s2) {
s2.append("B");
System.out.print(s1);
System.out.print(s2);
}
}
}
}.start();
new Thread() {
public void run() {
synchronized(s2) {
s2.append("C");
synchronized(s1) {
s1.append("D");
System.out.print(s2);
System.out.print(s1);
}
}
}
}.start();
}
}


Which two statements are true? (Choose Two)

A. The program prints �ABBCAD�
B. The program prints �CDDACB�
C. The program prints �ADCBADBC�
D. The output is a non-deterministic point because of a possible deadlock condition.
E. The output is dependent on the threading model of the system the program is
running on.


in my opinion the ans is D,E but in answer section of the mock it is given as A,B

Q2:

1. public class SyncTest {
2. private int x;
3. private int y;
4. private synchronized void setX( int i ) { x = i; }
5. private synchronized void setY( int i ) { y = i; }
6. public void setXY( int i ) { setX(i); setY(i); }
7. public synchronized boolean check() { return x != y; }
8. }

Under which condition will check return true when called from a different class?

A. check can never return true.
B. check can return true when setXY is called by multiple threads.
C. check can return true when multiple threads call setX and setY separately.
D. check can return true only if SyncTest is changed to allow x and y to be set separately.


a) Errors are subclasses of RuntimeEceptions
b No Exceptions are subclasses1of1XrrorsA
c} NO Errorsshould becatched1and1handledA
d}Runtime Exceptions ca

ans : In my opinion the answer should be B but it is given as C in mock answers.



Also one thing i gave 3 mocks of marcus green but scored only 78%,71% and 75% ... i am little bit worried whether i will make good score or not .
i small suggestion i need will K&B book , marcus green is enough for getting good score or i have to go for more material ...

Thanks in advance ...
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

For a discussion of the first question, see this thread.
 
I didn't say it. I'm just telling you what this tiny ad said.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic