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
4
votes
6 answers

Understanding join()

Suppose a thread A is running. I have another thread, B, who's not. B has been started, is on runnable state. What happens if I call: B.join()? Will it suspend the execution of A or will it wait for A's run() method to complete?
andandandand
  • 21,946
  • 60
  • 170
  • 271
4
votes
4 answers

What is the effect of the dot (.) in the Java classpath?

This is an example question from "SCJP mock exam": Given the default classpath: /foo And this directory structure: foo | test | xcom |--A.class |--B.java And these two files: package xcom; public class A { } package…
andandandand
  • 21,946
  • 60
  • 170
  • 271
4
votes
1 answer

SCJP6 regex issue

I have issue with following example: import java.util.regex.*; class Regex2 { public static void main(String[] args) { Pattern p = Pattern.compile(args[0]); Matcher m = p.matcher(args[1]); boolean b = false; …
Karlo
  • 65
  • 5
4
votes
2 answers

Java compiler behaviour during narrowing primitive conversion

K.Sierra and B.Bates in their book "SCJP Study Guide" write "The following is legal byte b = 27; but only because the compiler automatically narrows the literal value to a byte. In other words, the compiler puts in the cast. The preceding code is…
kapandron
  • 3,546
  • 2
  • 25
  • 38
4
votes
4 answers

Generics super vs. extends

Just when I thought I finally understood generics, I came across the following example: public class Organic { void react(E e) { } static void main(String[] args) { //1: Organic compound =…
Maggie
  • 7,823
  • 7
  • 45
  • 66
4
votes
1 answer

Arguments and Parameters

I am reading the SCJP 6 book by Sierra and Bates. In the first chapter there is a section on "Final Arguments" (page 41). In this section it refers to "method arguments" as "variable declarations that appear in between the parentheses in a method…
souser
  • 5,868
  • 5
  • 35
  • 50
4
votes
2 answers

when an object is eligible for a garbage collector?

consider this sample code: 1. public class GC { 2. private Object o; 3. private void doSomethingElse(Object obj) { o = obj; } 4. public void doSomething() { 5. Object o = new Object(); 6. doSomethingElse(o); 7. …
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
4
votes
3 answers

override hashCode() and equals() to store an object inside hashMap not working properly

i overrided hashCode() and equals() in a class (Dog) in order to store and retrieve it's instances from a hashMap, the code is as follows: class Dog { public Dog(String n) { name = n; } public String name; public boolean equals(Object o) { …
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
3
votes
3 answers

How many objects eligible for Garbage Collector

class A{ A aob; public static void main(String args[]){ A a=new A(); A b=new A(); A c=new A(); a.aob=b; b.aob=a; c.aob=a.aob; A d=new A().aob=new A(); //tricky…
Joe
  • 7,749
  • 19
  • 60
  • 110
3
votes
2 answers

Is it true that if you don't specify an access modifier for an interface, that interface will have default access

I'm reading SCJP by Kathy Sierra and Bert Bates and it says on pg. 21 that "The public modifier is required if you want the interface to have public rather than default access". Is this true? If yes, then the interface methods (which are always…
user1142130
  • 1,617
  • 3
  • 20
  • 34
3
votes
3 answers

Java Generic method/parameter types

In the following code example: interface Eatable{ public void printMe();} class Animal { public void printMe(){System.out.println("Animal object");}} class Dog extends Animal implements Eatable{ public void printMe(){System.out.println("Dog…
ziggy
  • 15,677
  • 67
  • 194
  • 287
3
votes
3 answers

String objects created by a method

I'm doing a few mock test for my Oracle Certified Java Programmer certification. One of the question I found in a test is this one: public String makinStrings() { String s = “Fred”; s = s + “47”; s = s.substring(2, 5); s = s.toUpperCase(); …
Averroes
  • 4,168
  • 6
  • 50
  • 63
3
votes
5 answers

Way to init a generic collection since Java5 + diamond operator

As far as i know, the generics are only useful at compilation time. Thus it is possible to declare: private Set set = new HashSet(); And then, in this string hashset, to add dogs or anything to that set, without any problem since there is…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
3
votes
2 answers

Use of a Comparable with indexOf

I tried the following simple test. class ZiggyTest{ public static void main(String[] args){ List cities3 = new ArrayList(); Cities city = new Cities("London"); cities3.add(new Cities("Manchester")); …
ziggy
  • 15,677
  • 67
  • 194
  • 287
3
votes
6 answers

How are java arrays really working

Can someone explain me how arrays really work in Java. I was surprised by the following code: Object test = new Object[2][2]; Object test2 = new Object[] { new Object[2],new Object[2] }; Object test3 =…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419