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
9
votes
3 answers

Singletons, Enums and anonymous inner classes

As you may know, some people are declaring singletons with an Enum of 1 instance, because the JVM guarantees that there will always be a single instance with no concurrency problems to handle... Thus what about an Enum with multiple instances? Can…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
9
votes
6 answers

What benefit do method-local inner classes provide in Java?

I've just read through the chapter on method-local inner classes in the SCJP book, and I'm really struggling to think of any practical use for them. I've always been under the impression, that methods should be as small and specific to their task as…
Jimmy
  • 16,123
  • 39
  • 133
  • 213
8
votes
7 answers

Post and Pre increment operators

When i run the following example i get the output 0,2,1 class ZiggyTest2{ static int f1(int i) { System.out.print(i + ","); return 0; } public static void main(String[] args) { …
ziggy
  • 15,677
  • 67
  • 194
  • 287
8
votes
3 answers

Synchronized threads and locking

Can someone please explain the difference between these two examples in the context of object locking: public void method1(){ synchronized(this){ .... } } And StringBuffer aStringBufferObject = new StringBuffer("A"); public void…
ziggy
  • 15,677
  • 67
  • 194
  • 287
7
votes
3 answers

Literal string creation vs String object creation

How many String object are created I am studying for the SCJP I cant seem to get my head round this String problem. I seem to see several possible answers depending on how i look at a question. In the following initialization, how many string…
ziggy
  • 15,677
  • 67
  • 194
  • 287
7
votes
3 answers

How many String objects will be created

I have the following Java code: public String makinStrings() { String s = "Fred"; s = s + "47"; s = s.substring(2, 5); s = s.toUpperCase(); return s.toString(); } The question is somehow simple: how many String objects will be created…
Ramona
  • 167
  • 1
  • 6
7
votes
3 answers

Java, compilation error, Constructors

I have been trying a mock ocjp 6 test. I went though a question asking if the constructor is correct : 1- public Test8(){} 2- private void Test8(){} 3- protected Test8(int k){} 4- Test8(){} The correct answer was 1 and 3. I didn't understand…
oueslatibilel
  • 567
  • 1
  • 8
  • 24
7
votes
1 answer

instanceof operator in case of primitive and wrapper type array

int primitivI[] = {1,1,1}; Integer wrapperI[] = {2,22,2}; 1. System.out.println(primitivI instanceof Object);//true 2. System.out.println(primitivI instanceof Object[]);//Compilation Error Why ???? 3. System.out.println(wrapperI instanceof…
Nirav Prajapati
  • 2,987
  • 27
  • 32
7
votes
1 answer

SCJP question: Java method overloading with var-args. What is the rationale?

Why does the following program throw an exception? public class MainClass{ public static void main(String[] argv){ callMethod(2); } public static void callMethod(Integer... i){ System.out.println("Wrapper"); } public static…
Markos Fragkakis
  • 7,499
  • 18
  • 65
  • 103
7
votes
5 answers

Identifer versus keyword

I read in the book for OCJP for Java6 the part with assertions. I reached the part where it gives me an overview of how the compiler reacts if the word 'assert' is used as keyword or as an identifier. What is the difference between a Keyword and an…
Reporter
  • 3,897
  • 5
  • 33
  • 47
6
votes
2 answers

Why can we use array with generic reference

While answering to a question about that here: https://stackoverflow.com/a/9872630/82609 I tried to do the following: Comparator[] comparators = new Comparator[] {...}; It works! But the following doesn't: Comparator[] comparators =…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
6
votes
4 answers

How does Java handle String objects in memory?

I was asked this question: String s = "abc"; // creates one String object and one // reference variable In this simple case, "abc" will go in the pool and s will refer to it. String s = new String("abc"); // creates two objects, …
coder_15
  • 171
  • 1
  • 7
6
votes
3 answers

Operator precedence in Java

In one example from http://leepoint.net/notes-java/data/expressions/precedence.html The following expression 1 + 2 - 3 * 4 / 5 Is evaluated as 1 + 2 - 3 * 4 / 5 = (1 + 2) - ((3 * 4) / 5) = 3 - (12/5) = 3 - 2 The result of the integer…
ziggy
  • 15,677
  • 67
  • 194
  • 287
6
votes
4 answers

Java wildcard strange behaviour when class is generic

I thought that i have some good understanding of Java generics. This code DOES NOT COMPILE and I know why. We can pass to test method only List of type Animal or its super type (like List of Objects) package…
bary
  • 1,699
  • 2
  • 15
  • 24
6
votes
3 answers

Redefining static method in child class

I would like to know the reason why this is first allowed in Java (or oops in general) I remember that the static methods are common for both parent and child class public class Redefine extends Parent{ public static void test () { …
Sudhakar
  • 4,823
  • 2
  • 35
  • 42
1 2
3
18 19