JavaRanch Home    
 
This page:         last edited 28 February 2014         What's Changed?         Edit

OCPJP FAQ   

Please use the Programmer Certification (SCJP/OCPJP) forum to post your own question. See SCJP-FAQ for Java 6 and earlier specific content.

OCPJP FAQ Contents

Questions about Oracle Resources

General Questions about the Exams

Questions about Exam Preparation (Books, Notes, Mock Exams, etc.)

Questions on Specific Topics



Where can I find the official OCPJP FAQ from Oracle?  

http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=82#5Q1Ahead



What are the OCPJP objectives?  



What are the upgrade exams?  

The upgrade exams are for candidates who already hold an SCJP certification under a prior version and want to be certified under a more recent version. For example, if you have already passed the SCJP 1.4 exam and want to upgrade your certification to version 7, then you can take the OCPJP 7 Upgrade exam.

For more information see:



If my last OCPJP was 1.4 can I take the 7 upgrade or do I have to take the full 7 exam?  

No. You can just take the upgrade exam. As long as you have OCPJP in any previous version you can take any OCPJP upgrade.



Is the upgrade exam easier than the full exam?  

Well there are less questions but the pass mark is slightly higher. The upgrade has 80 questions, a 60% pass mark and allows 150 minutes. The full exam has 90 questions, a 64% pass mark and still allows 150 minutes. However, the upgrade exam focuses on the new content.



What is the best way to prepare for the OCPJP exam?  

  • Familiarize yourself with Sun's exam process, including objectives, registration, testing, etc. See Sun's SCJP page for details.
  • If you are new to Java programming, start with a good introductory book such as Head First Java or Thinking in Java. Check the JavaRanch Bunkhouse for additional recommendations and reviews. Refer to the API documentation and the Java Language Specifications along the way. (See links in this FAQ.)
  • Once you have a foundation, study at least one good (and current) certification preparation book. (See recommendations in this FAQ.)
  • Use the OCPJP forum to post questions, and reinforce your own understanding by answering other people's questions.
  • Take as many mock exams as possible. (See links in this FAQ.) Use these to determine where additional study is needed, and as a guide to when you are ready.

Contributed by Mike Van...

In my dark and horrid past, I ran an organization that prepared newcomers for the Java Cert exam. As such, I have some insight you may find useful.

  1. Go through one book at a time, don't skip around between books because it will confuse you. Specifically with regard to the certification objectives, areas like Threads may be taught differently in different books. As such, its best to have one teacher at-a-time instead of numerous. Learning it multiple ways AT THE SAME TIME, will lead to confusion.
  2. If you're brand-spanking new to Java, don't go directly to a Java Cert book. These books were not created for beginners, they were created for people who understand the basics of Java programming. Instead, spend a month or so getting to know the language with a "Learning Java" type book. If you are new to programming altogether, you may want to precede the learning java type book with a basic computer programming book.
  3. Code Code Code. There is a lesson to be learned in every code example of every book you read. Learn the lessons and learn to code at the same time. The difference between someone who has spent the time to code and someone who is merely memorizing answers is immediately apparent in thier test progress. Someone who codes regularly will quickly pick-up on the intricate questions being asked on the exam. Someone who is memorizing answers will get lost easily once the questions deviate from what they've memorized. On the job, the memorized-no-coding person will be quickly fired, while also proving the test to be inneffective in the minds of the employer who f/hired them.
  4. Study with friends. There's an old axiom that goes: "if you put 100 programmers in a room and give them 1 problem, you'll get 100 different answers, and most will work." By studying with others you'll be able to see how others approach the questions and exercises you'll be studying. When I study for a certification, my initial approach to a problem is rarely the best one. But if I'm studying with others, I can see many approaches and find out which one is best for me.
  5. Use Mnemonic Devices. The thing about memorable mnemonics is that they help put information into your long-term memory instead of your near-short term memory. This means you won't be "brain-dumping" your newly learned lessons after the test. My favorite mnemonics are acronyms. Its amazing how memorable a lasciviously written acronym is. :-) Make 'em dirty to make 'em last.
  6. Don't try to learn the entire language in a week/month, take your time. There's the French cognitive psychologist name Piaget who postulated that adults learn sequentially and cumulatively. Basically what this means is that before you can learn how to write an inner class, you first need to learn how to write a regular class. You can try and skip right to the inner class if you want, but you won't learn the "whys" of it. Its just as important for us human beings to learn the background of something as it is to learn the thing itself. Now, if you're a martian, venusian, or uranusian, that may not apply. if you are a venusian learning Java, I say welcome to our new Venusian Overlords!
  7. Learn "why" something works a given way, not just that it works one way. Other psychologists have postulated that there are three stages to learning. There's recognizing something, rote memorization, and being able to create something new from your memorized material. This is usually applied to the learning of human languages, but it applied to Java Certification prep as well. Here's how they differ. Being able to recognize that something is written in Java is nice, but you have to know how to use the language also. Recognizing but not really being able to use is the first level. Not really useful. Being able to recite all parts of the Java Language is certainly better than just recognizing it. Unfortunately, being able to recite the number of bits in an Integer doesn't mean you'll be able to use it in code. Finally, being able to create algorithms in the language, that's where you want to be before you take your certification exam. That's what employers are looking for. That's why K&M ask you questions that make you think. And that's why the people that can use the language most effectively are the ones who don't get laid off.

Contributed by Rahul Bhattacharjee, SCJP1.4...

Apart from the programming questions one should also concentrate on the theory (encapsulation...) also. As the basic theory questions would also have the same weightage.

Check this link for the features new to JDK 1.5.



What books should I refer to when studying for the OCPJP?   SCJP Sun Certified Programmer for Java 6 Study Guide by Katherine Sierra and Bert Bates (K&B) is One of the most popular (and recommended) book for SCJP -- ISBN 0071591060. The Java 5 Study Guide is also available -- ISBN 0072253606. - plus read the Java 7 topics on Oracle's website. The updated book for Java 7 comes out in 2014.

OCP Java SE 7 Programmer II Certification Guide - prints in 2014

"Oracle Certified Professional Java SE 7 Programmer Exams" by Ganesh and Sharma -- ISBN 1430247649


Check the JavaRanch Bunkhouse for additional recommendations and reviews.



Where can I find the Java Language Specification?  



Where can I find the Java API documentation?  



What are some mock exams available?  



Where can I find preparation notes?  

OCPJP 7:

Various Versions:



Are there supporting courses for preparing the exam?  



Are there any mock exams that allow Exam Objectives section-wise tests?  



Can I bring something to write on?  

You cannot bring anything with you into the testing room. You will be provided with something to write on and something to write with. This varies by testing center, but often it is a small erasable white board and a marker. You cannot take anything with you from the testing room when you leave.

If you have any doubts or concerns about this policy, please verify with your testing center before appearing for the exam.



How important are the scores?  

Scores are not displayed on certificates (passing is passing), but scores can look impressive on resumes.



If I fail, can I take the exam again?  

Yes, but you will need to purchase another voucher and wait 1 week before retesting. See Sun's FAQs for more details.



How long will my certification last before expiring?  

  • "If a Sun certified professional has already received a certificate and ID card with the printed expiration date, can that professional request another certificate and ID card without an expiration date? Yes. The certified professional will need to send an email to the who2contact@sun.com alias to request a new certificate and ID card. Include your name and Prometric Candidate ID number."

  • "Beginning with all Sun certification exams taken on or after August 1, 2003, certification offerings from Sun no longer have an expiration date. Rather, certification offerings are based on a version of technology."
  • For exams taken after September 1, 2002, but prior to August 1, 2003, "Recertification was required to maintain one's status as a certified Sun professional after two years."

See Sun's Certification FAQ for details.



Where can I find information about OCPJP testing outside of the U.S.?  

In the top navigation of Oracle's OCPJP page there is an option of "Training Locations" from where you can select your country and find contact information.



What is the pattern of the expiration date on the exam voucher?  

The pattern of the date on the voucher is MM/DD/YYYY. So if it says 5/10/2009, it means the voucher expires on May 10th, 2009.



Will I be told how many options to choose in a multiple choice question?  

Yes in the real exam you'll be told how many options to select. The real exam won't have questions like in most mock exams which say "Choose All That Apply". That is done in mock exams to make them difficult.



Are there any marks for partially right answers?  

There are no points for partially correct answers. If there is a question where you have to select 3 options and you select 2 right and 1 wrong, you'll get no marks for that question.



What are some potential trips/traps in the OCPJP exam?  

  • Two top-level public classes cannot be in the same source file.
  • main() cannot call an instance (non-static) method.
  • Methods can have the same name as the constructor(s).
  • Watch for thread initiation with classes that don't have a run() method.
  • Local classes cannot access non-final variables.
  • Case statements must have values within permissible range.
  • Watch for Math class being an option for immutable classes.
  • instanceOf is not the same as instanceof.
  • Constructors can be private.
  • Assignment statements can be mistaken for a comparison; e.g., if(a=true)...
  • Watch for System.exit() in try-catch-finally blocks.
  • Watch for uninitialized variable references with no path of proper initialization.
  • Order of try-catch-finally blocks matters.
  • main() can be declared final.
  • -0.0 == 0.0 is true.
  • A class without abstract methods can still be declared abstract.
  • Map does not implement Collection.
  • Dictionary is a class, not an interface.
  • Collection (singular) is an Interface, but Collections (plural) is a helper class.
  • Class declarations can come in any order (e.g., derived first, base next, etc.).
  • Forward references to variables gives a compiler error.
  • Multi-dimensional arrays can be "sparse" -- i.e., if you imagine the array as a matrix, every row need not have the same number of columns.
  • Arrays, whether local or class-level, are always initialized
  • Strings are initialized to null, not empty string.
  • An empty string is not the same as a null reference.
  • A declaration cannot be labelled.
  • continue must be in a loop (e.g., for, do, while). It cannot appear in case constructs.
  • Primitive array types can never be assigned to each other, even though the primitives themselves can be assigned. For example, ArrayofLongPrimitives = ArrayofIntegerPrimitives gives compiler error even though longvar = intvar is perfectly valid.
  • A constructor can throw any exception.
  • Initializer blocks are executed in the order of declaration.
  • Instance initializers are executed only if an object is constructed.
  • All comparisons involving NaN and a non-NaN always result in false.
  • Default type of a numeric literal with a decimal point is double.
  • int and long operations / and % can throw an ArithmeticException, while float and double / and % never will (even in case of division by zero).
  • == gives compiler error if the operands are cast-incompatible.
  • You can never cast objects of sibling classes (sharing the same parent).
  • equals() returns false if the object types are different. It does not raise a compiler error.
  • No inner class (non-static inner class) can have a static member.
  • File class has no methods to deal with the contents of the file.
  • InputStream and OutputStream are abstract classes

Also see Top Ten Errors Java Programmers Make by David Reilly.



Am I ready to take the exam?  

The best way to convince yourself that you are ready is to consistently score well on mock exams. In general, most mock exams provide a good indication of how you will score on the real exam. (If anything, the real exams are said to be slightly less difficult than the mock exams. But since the real exam is usually the last one taken after a series of several mock exams, candidates are most prepared for that one.) As a general guideline for confidence, you should consistently score about 10 points higher on the mock exams as you hope to score on the real exam.



What resources should I study to meet the Objectives for SCJP 310-025 exam?  

SCJP resources based on Sun's objectives, PLEASE NOTE: These are resources based on an older exam, much of the material is still of great use but bear in mind Cavaet Emptor!

Section 1 Declarations and Access Control

Section 2 Flow control and exception handling

  1. Exceptions in Java (July 1998) This article gives an in-depth account of exceptions in the Java language and virtual machine.
  2. Designing with Exceptions (July 1998) This article discusses design guidelines concerning when and how to use exceptions.

Section 3 Garbage Collection

  1. Bill Venners Object finalization and cleanup

Section 4 Language Fundamentals

  1. Object Initialization in Java (March 1998) -- This article describes in detail the process of object initialization in Java programs. It discusses constructors, initializers, instance initialization (init) methods, initialization and inheritance, object images on the heap, and the order in which an object's variables get initialized. It serves as a companion to the regular Design Techniques installment, "Designing object Initialization."
  2. Designing Object Initialization (March 1998) -- This installment of Design Techniques begins with a quick look at object design fundamentals, then goes on to discuss various approaches to designing initializers and constructors so as to facilitate the proper initialization of objects.
  3. Designing with Static Members (March 1999) -- This article discusses how to use static fields and methods.
  4. Inner classes. So what are inner classes good for anyway? (JavaWorld?)
  5. Java Tip 106: Static inner classes for fun and profit This tip provides an example of using static inner classes to add separate, optional, supplemental functionality to your classes for such things as testing and example code. By John D. Mitchell

Section 6 Overloading, Overriding, Runtime Type, and Object Orientation

Section 7 Threads

  1. Sun's tutorial
  2. Synchronizing threads in Java
  3. Java Threads, By Scott Oaks & Henry Wong Chapter 1. Introduction to Threading

Section 8 The java.awt PACKAGE

  1. The Event Generator Idiom (September 1998) -- This article discusses how and when to make a Java class observable.

Section 9 The java.lang PACKAGE

Section 10 The java.util PACKAGE

  1. Introduction to the Collections Framework. Short Course By MageLang? Institute
  2. Using Collections with JDK1.2 by Glen McCluskey?

Section 11 The java.io PACKAGE

  1. Top Ten Myths about Java I/O by Elliotte Rusty Harold
  2. Examples from Java I/O (from "Java I/O" By Elliotte Rusty Harold)



char a = '\u000A'. Why is this invalid?  

Unicode escape characters of the form '\Uxxxx', where xxxx is a hexadecimal value, are processed very early in the translation process (see JLS 3.10.4 ). As a result, the special characters '0A' (line feed) and '0D' (carriage return) are interpreted literally as "end of line."

For example, the expression...

 char A = '\u000A';

...therefore becomes...

 char A =;

...which results in a compile-time error.

To avoid this error, always use the special escape characters '\n' (line feed) and '\r' (carriage return).



What are the Java standard keywords? Are true, false, and null keywords?  

Java keywords are listed in the Java Tutorial: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html

"true, false, and null are not keywords but they are reserved words, so you cannot use them as names..."



What does strictfp mean?  

The strictfp modifier can be used with top-level classes, nested classes, nested interfaces, and method declarations. It can not be used with variables, constructors, or initializer blocks. It also cannot be combined with the abstract modifier.

If an expression is FP-strict, all intermediate values should fit into the range for float or double variables. If an expression is not FP-strict, there are no such restrictions.

A non-constant expression is considered FP-strict if any of the class, interface or method declarations that contain the expression have the strictfp modifier.



Is it allowed to declare the main method private?  

Former JVM versions (pre-1.4) allowed the main method to have any accessibility (private, etc). This incompatibility with Section 12.1.4 of the Java Language Specification has been fixed as of version 1.4. In order to invoke a main method from the command-line, it is now mandatory to declare the main method as follows:

   public static void main (String[] args)

If the main method has any access level other than public, it will no longer run from the command-line.



Can I have more than one class in a .java source file?  

Yes. However, each .java source file can contain at most one top-level class (or interface) definition that is public. If a top-level public class (or interface) definition is present, then the .java source file must share that name exactly (matching case).



Can static methods be overridden?  

static methods cannot be overridden, but they can be hidden (if not final). See Overriding vs Hiding for details.



How can you compare NaN values?  

Except for NaN, floating-point values are ordered; arranged from smallest to largest, they are negative infinity, negative finite nonzero values, negative zero, positive zero, positive finite nonzero values, and positive infinity.

NaN is unordered, so the numerical comparison operators <, <=, >, and >= always return false if either or both operands are NaN. The equality operator == returns false if either operand is NaN. The inequality operator != returns true if either operand is NaN. In particular, x != x is true if and only if x is NaN, and (x == y) will be false if x or y is NaN.

For any value of x, including NaN itself, each of the following comparisons will return false.

 x < Double.NaN
 x <= Double.NaN
 x == Double.NaN
 x > Double.NaN
 x >= Double.NaN

Double.NaN != Double.NaN will always return true.

Note: The above relationships involving Double.NaN also apply to Float.NaN.



Are string literals eligible for GC?  

The objects created in the String pool are not subjected to GC until the class is unloaded by the JVM. They get discarded at that time or just before the virtual machine unloads the class' bytecode. For the purpose of the SCJP exam, you are not required to know the details of String pool memory management.



How does InterruptedException affect a thread?  

All InterruptedExceptions are caused by interrupt() method calls, (although not all interrupt() calls cause InterruptedExceptions). The effect differs depending upon in which state a target thread is. When a thread is:

  • in running state: No exception is thrown. However the interrupted flag is set, which means that if you call interrupted() or isInterrupted(), they will return true. It is up to the running target thread to check the flag and to take some action, but it is perfectly possible to ignore this flag. If the thread later goes from running state to waiting or sleeping state before interrupted flag is cleared via interrupted() method, then an InterruptedException will be thrown and the flag will be cleared.
  • in waiting/sleeping state: The thread moves into ready state, and when it next gets a chance to execute an InterruptedException is thrown. No flag is set, so interrupted() returns false.
  • in ready state: If an interrupt() is called while a thread is in ready state, nothing happens until the thread moves back to running state. Once the thread has moved to running state, then see answer for running state, above.

Summarizing, interrupt() does not stop the target thread, in other words, there is no guarantee that a thread on which interrupt() was invoked will be stopped. Nevertheless, interrupt() method call may stop a thread, depending on circumstances listed above.



What are the important I/O constructors and methods?  

  • Hierarchy of IO classes.
  • The interfaces and abstract classes, as well as the concrete classes implementing these.
  • The "chaining" of one stream to another to achieve the desired result. (Given a requirement, you should be able to choose the best possible way to chain streams together.)
  • Different character encodings, and the IO classes capable of making use of the encoding specifications.
  • How FileInputStream, FileOutputStream, RandomAccessFile may be constructed using File or String arguments.
  • The PrintStream class and the overloaded println() methods defined in it. The autoflush mechanism.
  • The RandomAccessFile class (pay attention to the constructor and the methods to move your file pointer back and forth). You should be able to calculate how many bytes the pointer moves when you read/write different data types. Know the two possible arguments that control read/read-write access to a RandomAccessFile.
  • The hierarchy of IOExceptions, and the methods in the IO classes that throw exceptions.
  • The File class, including all the overloaded constructors and various methods that permanently affect the underlying file system, and that determine various properties of the underlying file.



getCanonicalPath() returns an absolute pathname in which all relative references and references to the current user directory have been completely resolved.

getAbsolutePath() returns the absolute pathname which is a concatenation of the current user directory, the separator character, and the pathname of the file object.

The absolute path includes the drive name and the top-level directories, as well as the file name itself. All canonical paths are absolute (but not all absolute paths are canonical). A single file existing on a system can have many different paths that refer to it, but only one canonical path.

Let's suppose there are two directories in Windows:

 c:\OneDirectory 
and
 c:\AnotherDirectory 

And there is a file in OneDirectory named MyFile. Then we can specify this file in a variety of ways (note that the File class interprets the Unix and Windows path separators '/' and '\' the same, except that '\' must be represented with the escape sequence '\\' in a String):

 c:\OneDirectory\MyFile
 c:\AnotherDirectory\..\OneDirectory?\MyFile?
 c:/OneDirectory/MyFile
 C:\ONEDIRECTORY\MyFile 

In Java under Windows, all the above are possible absolute paths for the same file. But since they all refer to the same file, that file is represented by one and only one canonical path:

 C:\OneDirectory\MyFile 

The canonical form ensures that you can compare safely two file paths, i.e. if they point to the same file or directory, they will be equal.

Also note that getCanonicalPath() method may throw an IOException because the construction of the canonical pathname may require file system queries, whereas getAbsolutePath() never throws an exception.



Could someone explain the Regex2 class from K&B's Java 5 Study Guide?  

There is some confusion regarding the following class (from the SCJP Sun Certified Programmer for Java 5 Study Guide by Katherine Sierra and Bert Bates)...

import java.util.regex.*;

class Regex2 {
  public static void main(String [] arg) {
    Pattern p = Pattern.compile(arg[0]);
    Matcher m = p.matcher(arg[1]);
    boolean b = false;
    while(b = m.find()) {
      System.out.print(m.start() + m.group());
    }
  }
}

When this is compiled and run with java Regex2 "\d*" ab34ef the output is 01234456, which prompts the question: "Where does the '6' come from?"

The asterisk (*) is a "greedy quantifier," specifying that whatever preceeds it (in this case, any digit) should be matched zero or more times. By allowing for zero occurrances, a match of zero length is possible. Because a match of zero length is possible, the find() method will check the index following the last character of input.

Note that for a match of zero length, the matcher's start() and end() methods both return the same index. In these cases, the group() method returns an empty String (i.e., the substring from start() to end()).

So in the above example, the find() method locates the following matches:

start   end    group
index  index
  0      0     empty
  1      1     empty
  2      4      34
  4      4     empty
  5      5     empty
  6      6     empty

For more detailed information, see this Sun/Oracle tutorial on regex quantifiers.



How many String objects are there? What is the String pool?  

See Corey McGlone's article Strings, Literally .



Why do separate autoboxing conversions sometimes return the same reference?  

Two autoboxing conversions of a primitive value p will yield an identical reference (that is, the == comparison will return true) if p is:

  • true or false
  • a byte
  • a short or int in the range of a byte (-128 to 127)
  • a char in the range of \u0000 to \u007f (0 to 127)

Note: The Java Language Specification does not explicitly guarantee this behavior for long values within the range of a byte.

For additional details, see JLS section 5.1.7 Boxing Conversion .



What is a most-specific method?  

Suppose that more than one version of an overloaded method applies to a particular call. For example, suppose that Cat extends Animal, and a method is overloaded to take either of these types as an argument.

 void method(Animal animal) {...}
 void method(Cat cat) {...}

Further, suppose that "milton" references an instance of Cat. That is...

 Cat milton = new Cat();

Now, since a Cat is also an Animal, which method will be invoked with the following call?

 method(milton);

In this situation, Java invokes the "most-specific" method, as detailed in section 15.12.2.2 of the Java Language Specification. In general, one method is considered more specific than another if its argument types are subtypes of the other method's respective argument types. So because Cat is a subtype of Animal, the method overloaded to accept a Cat is more specific than the method overloaded to accept an Animal. Therefore, method(Cat cat) will be invoked by the call method(milton).

If it's not possible to identify a most-specific method from among the applicable methods, then the invocation is considered "ambiguous" and results in a compile-time error.

Note, however, that a null reference could apply to any object type. Therefore, the call method(null) would also invoke the most specific method -- in this case, method(Cat cat).


  Why are the notify, notifyAll and wait methods defined in the Object class instead of the Thread class?

See this thread and this thread for answers.


ToDo

  • Add question about Sun logo use: How to register, how long it takes, etc.
  • Add question about using Sun's Certification Manager.


CategoryFaq CategoryCertification

JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton