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
5
votes
1 answer

Reference comparison using == operator

public class AutoBoxingAndUnBoxing { public static void main(String[] args) { Integer x = 127; Integer y = 127; System.out.println(x == y);//true Integer a = 128; Integer b = 128; …
kittu
  • 6,662
  • 21
  • 91
  • 185
5
votes
3 answers

char and byte with final access modifier - java

Please take a look at below example i cant understand the relation between char and byte byte b = 1; char c = 2; c = b; // line 1 Give me compilation Error because c is type of char and b is type of byte so casting is must in such condition but…
Nirav Prajapati
  • 2,987
  • 27
  • 32
5
votes
1 answer

Interface is not allowed inside methods

I have studied some books for OCPJP 7 certification and in the inner classes chapter there were some strange/incomplete informations. I've tried to create an interface inside a method, but it seems you can't do that, you can only create classes…
Silviu Burcea
  • 5,103
  • 1
  • 29
  • 43
5
votes
1 answer

Codes on the same thread executed in unusual order

This is a piece of code in a SCJP practice question: public class Threads2 implements Runnable { public void run() { System.out.println("run."); throw new RuntimeException("Problem"); } public static void main(String[]…
kwkt
  • 1,058
  • 3
  • 10
  • 19
5
votes
2 answers

Why do static and instance init blocks in Enums behave differently from those in Classes

In studying for the Java certification test I learned that static initialization blocks run once when the class is loaded, in order of appearance within the source code, that instance initialization blocks run each time an instance is created, and…
paniclater
  • 903
  • 1
  • 12
  • 18
5
votes
3 answers

Inconsistent behaviour of primitive integer types in Java

Can someone explain to me like I'm five why I get different behaviour for two of four primitive types representing integers in Java? AFAIK all four are signed and they all use the most significant bit as a sign bit, so why do byte and short behave…
Moyshe
  • 1,122
  • 1
  • 11
  • 19
5
votes
1 answer

eclipse java multithread program debugging

while debugging the java Multithreading program i put breakpoints. after start method is invoking the control is not going to run menthod can you please let me know the debug procedure. sample code class Test extends Thread { public static…
rama
  • 173
  • 1
  • 2
  • 7
5
votes
3 answers

What is a Contract in Java

I was solving some questions for my OCA prepration. I found this problem at Oracle's website listing sample questions for exam. Code: public class MyStuff { MyStuff(String n) { name = n; } String name; public static void main(String[]…
Prateek Singla
  • 679
  • 2
  • 10
  • 22
5
votes
2 answers

Do strings used in a System.out.println also create new immutable objects?

So I'm studying for the SCJP from the Kathy Sierra book. In the chapter for strings, this is a question: String s1 = "spring "; String s2 = s1 + "summer "; s1.concat( "fall "); s2.concat(s1); s1 += "winter"; System.out.println(s1+"…
Nilay Panchal
  • 541
  • 6
  • 17
5
votes
5 answers

Thread object constructed by runnable overrides the run method

Given this sample code: Runnable r = new Runnable() { public void run() { System.out.print("Cat"); } }; Thread t = new Thread(r) { public void run() { System.out.print("Dog"); } }; t.start(); why is the output Dog and not Cat??
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
5
votes
2 answers

Var-arg of object arrays vs. object array -- trying to understand a SCJP self test question

I'm having trouble understanding this question, and the explanation of the answer for an SCJP 1.6 self test question. Here is the problem: class A { } class B extends A { } public class ComingThru { static String s = "-"; public static void…
user4903
4
votes
3 answers

Does Arrays.BinarySearch require that the array is sorted in ascending order

According to the documentation: public static int binarySearch(T[] a, T key, Comparator c) Searches the specified array for the specified object using the binary search algorithm. The array must be sorted into ascending…
ziggy
  • 15,677
  • 67
  • 194
  • 287
4
votes
2 answers

Compiler warnings when declaring Generic types

Why does the compiler issue a warning when declaring a variable as List list = new LinkedList(); Warning: Note: ZiggyTest.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. But it…
ziggy
  • 15,677
  • 67
  • 194
  • 287
4
votes
4 answers

Exceptions and errors report order

What rules applies to the following code: try { assert (false) : "jane"; } catch (Exception e2) { System.out.print("ae2 "); } finally { throw new IllegalArgumentException(); } Assetions are enabled. Why…
mmatloka
  • 1,986
  • 1
  • 20
  • 46
4
votes
4 answers

x = x++ doesn't increment because the ++ is applied after the assignment?

From page 280 of OCP Java SE 6 Programmer Practice Exams, question 9: int x = 3; x = x++; // x is still 3 In the explanation we can read that: The x = x++; line doesn't leave x == 4 because the ++ is applied after the assignment has occurred. I…
Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110