Questions tagged [ocpjp]

OCPJP (Oracle Certified Professional, Java Programmer), formerly Sun Certified Java Programmer (SCJP), is a certification for programmers experienced using the Java programming language. Achieving this certification provides clear evidence that a programmer understands the basic syntax and structure of the Java programming language.

http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=320&p_org_id=28&lang=US

80 questions
8
votes
1 answer

Metacharacter \B matches (OCP exam)

I am studying for the Java OCP certificate. I am taking mock exams to prepare. Example program: public class Quetico { public static void main(String[] args) { Pattern p = Pattern.compile(args[0]); Matcher m =…
Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
8
votes
5 answers

Real life use and explanation of the AtomicLongFieldUpdate class

Is anybody aware of any real life use of the class AtomicLongFieldUpdate? I have read the description but I have not quite grasped the meaning of it. Why do I want to know that? Curiosity and for OCPJP preparation. Thanks in advance.
Rollerball
  • 12,618
  • 23
  • 92
  • 161
7
votes
1 answer

How exactly does String.split() method in Java work when regex is provided?

I'm preparing for OCPJP exam and I ran into the following example: class Test { public static void main(String args[]) { String test = "I am preparing for OCPJP"; String[] tokens = test.split("\\S"); …
peterremec
  • 488
  • 1
  • 15
  • 46
6
votes
2 answers

Does static modifier change the access level of a class member in java?

I am reading the book of OCA & OCP for java 7 certification and I am trying the exercises of the book with java 8 and I noticed something wired. I have Class1 class as follows: package cert; public class Class1{ protected static void…
Arber Hoxha
  • 73
  • 10
6
votes
1 answer

Throw runtime exception in Closable.close()

During my studies to the OCPJP8 I've encountered one question which doesn't have very clear answer to me. Consider following code: public class Animals { class Lamb implements Closeable { public void close() { throw new…
kukis
  • 4,489
  • 6
  • 27
  • 50
6
votes
2 answers

java.sql.SQLException: No suitable driver found

I am trying to execute simple query using below DbQuery.java class which uses DbConnector to get a Connection from DriverManager. note: I have already included "mysql-connector-java-5.1.25-bin.jar" on my classpath via:…
rohtakdev
  • 956
  • 1
  • 13
  • 16
6
votes
3 answers

Eligible variables for garbage collection in Java

I am preparing for OCPJP, and I got stuck at the following mock exam question: Given: 3. interface Animal { void makeNoise(); } 4. class Horse implements Animal { 5. Long weight = 1200L; 6. public void makeNoise() {…
user998692
  • 5,172
  • 7
  • 40
  • 63
6
votes
4 answers

Why is a boolean expression valid in a case block, when booleans are not supported data types for switches?

After reading some of the SCJP certification last night, I got thinking about switch statements and how the expressions are evaluated, and I'm a little puzzled by something. Java won't let you switch on a boolean, so the following will not compile…
Jimmy
  • 16,123
  • 39
  • 133
  • 213
5
votes
2 answers

Confusion over Java's pass-by-value and immutability

In preparation for the SCJP (or OCPJP as it's now known) exam, I'm being caught out by some mock questions regarding pass-by-(reference)value and immutability. My understanding, is that when you pass a variable into a method, you pass a copy of the…
Jimmy
  • 16,123
  • 39
  • 133
  • 213
5
votes
3 answers

Passing method argument through ternary operator in java

Code: public class Foo { static void test(String s){ System.out.println("String called"); } static void test(int s){ System.out.println("int called"); } public static void main(String[] args) throws Exception…
Anj Jo
  • 137
  • 2
  • 8
4
votes
2 answers

Why bounds work so strange in Java?

I'm using Java 8. During training to passing Java OCP 8 I find some snippets of code that I don't understand and want to know, why it so strange for me. I have next hierarchy: class A {} class B extends A {} class C extends B {} The first one, this…
badCoder
  • 730
  • 1
  • 5
  • 13
4
votes
2 answers

Comparator Interface implemented in a nested class

I'm new on stackoverflow.com but I often used it to search for answers whenever I had a problem, but now I can't find any result searching for my problem so I'm asking here :) I'm studying for the OCPJP SE 7 certification, exam 1Z0-804, and I'm…
RaffoSorr
  • 405
  • 1
  • 5
  • 14
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
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
1 answer

Does the Java 11 jar command support the classpath parameter?

I am currently studying for the OCP Java 11 certification and I am currently playing around with the basic JDK commands. In the study guide there's a review question mentioning that the jar command also supports the -cp option (the classpath). Is…
Adrian Pop
  • 215
  • 1
  • 3
  • 12