Questions tagged [scjp]

SCJP is a certification for programmers experienced using the Java programming language. SCJP affirms that the programmer really knows how to code in Java. However the ability to design and implement a complete application is not affirmed by this test (it is affirmed by the second step certification, SCJD).

SCJP (Sun Certified Java Programmer) is a certification for programmers experienced using the Java programming language. Achieving this certification provides clear evidence that a programmer understands the syntax and structure of the Java programming language and knows enough about J2SE system library.

During the test, the programmer needs to solve multiple short programming tasks in a limited time. Unlike the second level (SCJD) test, the SCJP test does not require to implement and demonstrate a complex working application.

285 questions
1
vote
1 answer

Why can not I use toString().length() as a hashCode() return?

public class Dog { int collarID; String name; public static void main(String[] args){ Dog d = new Dog(); d.name="hose"; System.out.print(d.hashCode()); } public boolean equals(Object arg0) …
Joe
  • 7,749
  • 19
  • 60
  • 110
1
vote
3 answers

how to determine objects eligible for garbage collection in the given program?

Given: public class Trees { Trees t; public static void main(String[] args) { Trees t = new Trees(); Trees t2 = t.go(t); t2 = null; // more code here : LINE 11 } Trees go(Trees t) { Trees t1…
1
vote
1 answer

Instantiate an Inner class from within a static method of its enclosing Class

we know that Static contexts can't reference any instance of any type, but what happens with main method, how the following code sample compiles with no problem: public class MyOuter { public static void main(String[] args) { …
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
1
vote
5 answers

method-local inner class cannot use variables declared within the method

Why a method-local inner class can't use variables declared inside the enclosing method except those marked final, i know that the variables declared inside the enclosing method might vanishes while the inner class instance remains valid, but what…
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
1
vote
1 answer

SCJP program giving output 8 2 how?

class Foozit { public static void main(String[] args) { Integer x = 0; Integer y = 0; for (Short z = 0; z < 5; z++) { if ((++x > 2) || ++y > 2) x++; } System.out.println(x +…
1
vote
3 answers

Why do we need a static lock for synchronizing system.out.println()?

I am studying for java certification, and I see this example from Mughal's book: public class Smiley extends Thread { @Override public void run() { while(true) { synchronized(this) { …
user1006375
  • 351
  • 1
  • 3
  • 12
0
votes
2 answers

Need an explanation for the output

Why are "Hi1" and "Hi3" displayed twice by the following code? static int a=1; public static void main(String[] args) { if (a==2) { System.out.println(args[0]); a = 3;} if (a==1) { main(); } …
Manav Bhanot
  • 113
  • 3
  • 16
0
votes
5 answers

Do classes have to be on the same inheritance tree for them to have a Has-A relationship

class Employee { private String name; void setName(String n) { name = n; } String getName() { return name; } } interface Mungeable { void doMunging(); } public class MyApp implements Mungeable { public void doMunging() { ; } …
ziggy
  • 15,677
  • 67
  • 194
  • 287
0
votes
1 answer

Thread concurrency - synchronisation and locks.

import java.util.*; import java.io.*; import java.util.regex.*; class ZiggyTest2 extends Thread{ String sa; public ZiggyTest2(String sa){ this.sa = sa; } public void run(){ synchronized(sa){ …
ziggy
  • 15,677
  • 67
  • 194
  • 287
0
votes
3 answers

Java - ArrayList removal of duplicate items

In the following example: public static void main(String[] args){ List list = new ArrayList(); list.add("hi"); list.add("hi"); list.add("hi"); list.remove("hi"); …
ziggy
  • 15,677
  • 67
  • 194
  • 287
0
votes
4 answers

scjp passing object

public class Hotel { private int roomNr; public Hotel(int roomNr) { this.roomNr = roomNr; } public int getRoomNr() { return this.roomNr; } static Hotel doStuff(Hotel hotel) { hotel = new Hotel(1); …
0
votes
3 answers

SCJP - number format

Given: public class LineUp { public static void main(String[] args) { double d = 12.345; // insert code here } } Which code fragment, inserted at line 4, produces the output | 12.345|? A. System.out.printf("|%7d| \n",…
jyo
  • 345
  • 1
  • 7
  • 22
0
votes
1 answer

SCJP Sierra Bates Chapter 2 Question 2 Default constructor calls

Background info I have a query regarding a questions from Sierra & Bates, SCJP v6 book. Namely Chapter 2 question 2. The answer given is that the "compilation fails". However when I tried this in neBeans, the code compiled and ran without error. It…
Scott
  • 5
  • 2
0
votes
2 answers

SCJP v6 (Sierra,Bates) Chapter 2, Question 12 Interpretations of constructor calls

Could I have some feedback on this Given "new House("x ")" sends a string I had expected that the "House(String name)" constructor would have called the Building super class constructor "Building(String name)". In which case the answer would have…
Scott
  • 5
  • 2
0
votes
1 answer

scjp question on enum

public enum Scale2 { GOOD('C') { public char getGrade() { return grade; } }, BETTER('B') { public char getGrade() { return grade; } }, BEST('A') { public…
yagnya
  • 549
  • 1
  • 4
  • 18