
I welcome dear and Java-programmers!
The article is devoted to preparing for the Oracle Java SE7 Professional exam with code number
1Z0-804 . About this on Habré many posts have already been written (for example,
here ,
here ,
here ,
here ,
here ,
here ,
and here ), so I will try not to repeat and add notes on what is most often met with important nuances that the view was missed or not well covered in the indicated articles, and generally in the publicly available literature (I note right away that the material does not pretend to be complete, here I just tried to identify the tricky questions from the exam and briefly outline some difficult things). I will also share my thoughts on what materials are best for preparing. From the first time the exam failed to pass, so I began to keep for myself various notes, where I wrote down everything that seemed to me difficult or difficult to remember. Which now and decided to share with you. I ask you to show understanding beforehand, if you suddenly notice an error, a defect or a bug - write in the comment.
general information
I passed the exam in Moscow, it costs $ 150, lasts 2.5 hours, I have 2 documents with me. 90 questions, 65% passing score, i.e. You can incorrectly answer about 30 questions (I'm not sure that for each question they give the same number of points). If necessary - retake only after 2 weeks. Registration for the exam on the
Pearson VUE website, where the testing center and the date are selected, payment by card (as once paid in the center in cash, but this was more expensive). This time I went to ACET (American Center for Education and Testing), Oktyabrskaya metro station. On the surrender, everything is serious here - turning the pockets upside down and forbidding to take any things with you (the phone is understandable, but for example, water is too much like that). It is allowed to leave the office, but “on receipt”, and the exam does not stop. The results are sent in about 30 minutes to the post office (or to an account on
Oracle Certview , where all exams and received certificates are displayed). The paper certificate comes on average within 1.5-2 months (Moscow region).
Recommendations for preparation
Well, of course, program, program and program again! And the joke is only partly. Since I began to learn Java recently, and there was little practical experience, I initially tried to prepare myself mainly from books and various tests, but all of this quickly got out of my head, and you really need to practice everything so that everything fits and the main thing is not forgotten. For preparation I used the following materials:
- Java SE 6 Programmer Practice Exams (Bert Bates, Kathy Sierra, 2011). In fact, a collection of tests and recommendations. True, it is a bit outdated and in version 6, but otherwise the tests and explanations for them are quite close to real questions. The only negative is that the following topics are missing: NIO.2, JDBC and Concurrency (including Executor-s and the Fork-Join Framework). No errors found in the responses, which is nice.
- Enthuware tests . They cost about $ 10 for 1 exam, and the corresponding program is downloaded. Covers all the topics of the exam, although some theoretical questions encountered in the exam are not there. Occasionally there are errors, so if you are not sure of the answer shown, be sure to check. In general, this test left a positive impression, because by the nature of the “tricks”, many questions were similar to the exam questions, there is a lot of breakdowns by topic and there are a lot of questions (I think about 300+).
- Oracle's official tutorial - Preparation for Java Programmer Language Certification Programmer Level II Exam . This is an insidious thing that I stumbled upon initially, being sure that everything should be completely and completely ... And I failed the test. But in reality it can be used more as a table of contents by topic and classes used in the exam, and even then with reservations. First, the completeness of the information and the completeness and complexity of the examples, in comparison with the exam, leaves much to be desired. Secondly, some topics (for example, JDBC, NIO2) are bloated here to unnecessary detail, which I did not meet on the exam. Thirdly, there is no theory of patterns (and Oracle, as it turned out, really loves this topic - understand it thoroughly). Well, even on trifles, like some moments of the theory of design of classes and flows, I did not see here either (I will write about what you need to know below).
- Various applications tests for Android. In my opinion, the SCJPv1 and SCJP Champ (although outdated) turned out to be the most useful / convenient.
- And of course, various Java literature, which one you like more, I used Java 7 - The Complete Reference (Herbert Schildt) , Java Philosophy (Bruce Ekkel) , official documentation and Google.
- In principle, there are still many tests on the Internet, and expensive , not very , and generally free , but since there are no guarantees for objectivity - it was decided to choose a middle ground and stop at it.
')
Main themes
Design classes, constructors, access
Exceptions
- It is very important to remember the basic hierarchy of exceptions. In the diagram below, the so-called red lines are marked in red. unckecked exceptions (not requiring processing), yellow - checked (requiring processing). Actually, the picture shows just the necessary minimum that you need to know “by teeth”, because tricky questions are quite common.

- If the exception being thrown is not handled in a catch block (or there is no catch block) and there is a finally block, then the finally block will be executed first and then an exception will be thrown.
- The method () throws construction SomeCheckedException {...} does not oblige the method to throw the SomeCheckedException (checked-type) exception inside. But at the same time the call of this method is perceived as requiring processing (in try ... catch or throws). An example for the class Exception: mechod () throws Exception does not oblige to call (throw) it inside a method (including the method can be empty), but with this external call mechod () also requires exception handling.
- Inside try {...} catch (ExceptionClass e) {...} the ExceptionClass exception should be “called”, but only if it is of type checked! Otherwise there will be a compilation error: "the exception try statement"
- The exception classes in the catch block, listed through a vertical bar ("or"), must not lie on the same branch of the inheritance hierarchy. For example, you can write catch (ClassNotFoundException | IOException e), but catch (IOException | FileNotFoundException e) does not compile.
Methods and Parameters
- Passing parameters by reference / value. Remember that in Java, parameters in procedures are passed by value (that is, when a change in the value of a parameter within a procedure does not affect the externally passed variable), but only with a reservation. For simple types (int, float, ...) this is true. For objects (including arrays), the reference is transmitted, and therefore changes in the object will be visible in the calling procedure. But for wrappers of simple types (Int, Float, ...) and String, due to the lack of an API for changing the internal state, passing them as a parameter will be similar to simple types.
- When overriding a method, you can set the result type as a subclass of the result of the base method (in the superclass), but not vice versa!
- When overriding a method, it:
a) can cause a “narrower” exception (subclass);
b) cannot cause a wider exception (superclass);
c) may not raise any exceptions at all.
Collections
The most important thing to know is syntax, class hierarchy and collection interfaces, work with elements, search / sort, work equals () and hashCode () methods. The main collections that I met at the exam: interfaces Set, Map, List, Deque, SortedMap, classes ArrayList, CopyOnWriteArrayList, ArrayDeque, TreeMap, TreeSet, HashMap, HashSet. To find an item in the Java collection, it uses the equals () and hashCode () methods. For the new class, by default, the equals () method performs a comparison of objects (i.e., pointers to them, because it inherits from Object), so if you use your own element class in the collection, then you need to redefine this method so that Java could find previously inserted item. The hashCode () method is required by Java to search for the required baketa with elements (for hash collections). Accordingly, if the method is not defined and the bakt is not found, then the element is not found. It is also desirable to know all sorts of syntax for creating collections:
Now more about the features of the collections. For convenience of memorizing the hierarchy, I found the corresponding visual diagrams, and made a small summary of the specifics of each class:


- Set - Interface. All implementations store the collection of objects. Duplicates are prohibited, but if a duplicate is added, an exception is not raised (if a duplicate is inserted, the add () method returns false). Implementations:
- HashSet - Unordered set. Permits null insertion. No support for multithreading.
- TreeSet - Order HashSet. No support for multithreading.
- Map - Interface, implementations store the <key, value> pair. All implementations prohibit duplicates:
- HashMap - Implements the storage of elements in the form of a hash table. Overwrites duplicates with new values. The put () method returns null if there is no key, and the previous value, if the key already exists). Resolves null for key and value; in the case of duplication, key replaces it with the new value without raising exceptions. No support for multithreading. Circumvention is not guaranteed.
- Hashtable - null is forbidden for key and value (in this case there will be a NullPointerException in both cases). Flow safe. The rest of the work is similar to HashMap.
- TreeMap is an analogue of HashMap, only ordered, i.e. when added, it automatically sorts the items by key (i.e., when traversing, the items will be sorted). Arranged on the principle of red and black wood.
- List - Interface, implementations store lists of objects. Resolves duplicates and null. Implementations:
- ArrayList - Dynamic array. No support for multithreading.
- Vector - Dynamic array. Flow safe.
- LinkedList - A doubly linked list. No support for multithreading. Also implements the interface Deque.
- Queue - The implementations of this interface are based on the queuing principle (FIFO) for storing objects. Null allowed. The add () method puts it at the end of the queue.
- Deque - Implementations combine the functionality of a queue (FIFO) and a stack (LIFO). The add () method is similar to the add () method for Queue, puts it at the end of the queue. The push () and addFirst () methods are equivalent and put an element at the head of the queue (at the top of the stack).
Additional information on the comparison of collections can be found here:
Search and sort collections. Comparable and Comparator Interfaces
- This is also one of the “popular” topics, the exam had ~ 5 questions about searching / sorting.
- Learn exactly how the Arrays.binarySearch and Collections.binarySearch methods work, check with examples, since in my opinion the documentation is written a little. What returns, what exceptions cause, how to work with "raw" types, etc.
- Similarly for the Collections.sort and Arrays.sort methods .
- Interface Comparable - used for the class whose instances of objects can / should be compared. All "wrappers" of simple types - Char, Integer, etc., as well as String - already implement this interface. Using:
- Interface Comparator - implemented outside the class, whose objects will be compared. The main difference from Comparable:
1) you can create several types (classes) of independent sorting;
2) used if you want to sort objects of another class, in which the comparison is not implemented.
- Examples of using:
Collections.sort (List <T> arg1, Comparator <? Super T> arg2);
Arrays.sort (T [] arg1, Comparator <? Super T> arg2);
- The methods of sort (), reverse () and binarySearch () of the class Collections do NOT work with Set (but the exception is not called)
Inner classes
- Outer class - top-level class. The file is compiled with the name Outside.class. Permitted access modifiers: [default], public
- Nested classes. They are divided into staic nested classes (static) and inner classes (all others):
- Static nested class (or interface) - Defined in the context of the upper class, static. May refer to static members of the outer class. Instances of the inner and outer classes can be created independently (create syntax: OuterClass.StaticNestedClass obj = new OuterClass.StaticNestedClass (); ). The file is compiled with the name: Outside $ Inside.class. Permitted Access Modifiers: ALL.
- Member class - Defined in the context of the upper class, not static. An instance can only be created after creating an instance of the outer class. The file is compiled with the name: Outside $ Inside.class. Permitted Access Modifiers: ALL.
- Local class - It is defined inside the code block, and is visible only inside this block. It can address only the final variables of the outer class and the final parameters of the methods. The file is compiled with the name: Outside $ 1 $ Inside.class. Allowed access modifier: [default] only.
- Anonymous class - Analogue of the local class, only untitled. The file is compiled with the name: Outside $ 1.class
Just remember:
- The non-static inner class cannot have static methods;
- The non-static inner class can have static variables (but only final!);
- The static nested class can have static and non-static variables;
Working with strings, regular expressions
- Remember that String objects are immutable, StringBuilder is changeable, StringBuffer is also changeable and still thread safe.
- StringBuilder and StringBuffer can be concatenated through '+' only with a String, and cannot with each other and other simple types (unlike String, which can be concatenated with simple types).
- Carefully learn regular expressions, there are often tricks. For example, in a string literal for Pattern-a, only one backslash ("\ s") is specified, which causes a compilation error.
- Remember the “greed” of the quantifier * , for example, for the string “abcd bla-bla-bla abcd” the expression “a. * Cd” will correspond to the entire string.
- Also do not forget that the methods of the Matcher class (find and group) begin the search for the next match from the position of the last group found, so only one match will be found for “ababa” and the expression “aba” .
- The methods String.split (), String.replaceAll () and Scanner.useDelimeter () work with regular expressions.
- Remember the basics of formatting strings: System.out.printf ("Hello java% 03d!", 7); There was one tricky problem about the order of printf parameters, I recommend to sort it out: System.out.printf ("1:% 3 $ s 2:% 2 $ s 3:% s", 1,2,3);
Streams
Another favorite topic where you need to be very attentive.
- Briefly about the main thing. synchronized method () {...} - blocks for other threads the current and all other synchronized methods of the object instance (the second part is easy to forget). And if the method is declared as static, then all synchronized methods of the class are blocked.
- And similarly: syncronized (obj) {...} - blocks:
1) all calls from other threads to the block inside syncronized on the given obj object;
2) all other blocks are syncronized with the same obj object .
- There are irregular forms of implementation of the Runnable interface, for example, private void run () {...} , public int run () {...} , or public void run (Runnable r) {...} , etc.
- It is impossible to specify synchrnozed for the methods of the interface and the abstract class, but for the methods enum - it is possible.
- After completion of the stream, it is impossible to start it again Thread.start () will throw an IllegalThreadStateException.
- Remember the differences between Runnable and Callable (the latter returns a value and may cause an exception).
- Need to know the theory (definitions):
1) deadlock - “dead” blocking, here, I hope, there are no questions;
2) stravation - when a thread cannot get access to a resource for a long time due to the fact that it is long occupied by another thread (more “greedy” or with a higher priority);
3) livelock - arises in case the exchanging or pending threads are too busy to effectively continue working. Those. they periodically release resources for each other for too short a time, by analogy, as 2 people in the corridor cannot push each other, simultaneously walking to the right, then to the left;
4) race condition - a design error of a multi-threaded system, in which the execution result depends on the order of execution of the threads (ie, unpredictable).
Wrapping types and methods with a variable number of arguments
- Widening is an automatic extension of a simple Java type to a wider one, for example byte -> int. Or an extension to a more general class, for example, Byte -> Object.
- Boxing is an automatic wrapping of a primitive Java type into its corresponding object type, for example: long -> Long. Accordingly, Long is called the wrapper type for long.
- Unboxing - reverse operation: Long -> long
There are the following rules for the compiler:
- It is impossible to widening from one wrapping type to another (for example, Byte -> Int) (IS-A fails);
- Forbidden widening, then boxing (int cannot become Long);
- But boxing is allowed, then widening (int -> Integer -> Object);
- Methods with a variable number of arguments can be combined with widening and boxing;
- In this case, the compiler will have the following priority (in descending order of priority): widening, boxing, var-args;
- Separately, boxing and var-args can also be used when overloading methods.
Innovations 7 version
- Fork-Join Framework. You need to know the minimum basic principles of building code with its use. We met a couple of questions with RecursiveTask / RecursiveAction interfaces (there was an analogue of the example with the Fibonacci series from the documentation ) and one theoretical question on how to divide the task into two.
- NIO2. Here you need to know the following:
- PathMatcher file search mask (“glob: *. Jpg”) and the principle of traversing the file tree (Files.walkFileTree);
- Path class (especially getName, subpath, relativize methods);
- Files class (methods copy, move + StandardCopyOption, newBufferedReader, newBufferedWriter, setAttribute, getAttribute);
- class WatchService. - And make sure you understand all the nuances of the AutoCloseable interface and its use in “try-with-resource” (I think it’s enough to know where and when the object declared inside the try () brackets is available, released, what happens if an exception occurs and how to separate it from other possible exceptions).
miscellanea
- Expression x instanceof Y - will not compile if x and Y belong to a different class hierarchy.
- But x instanceof SomeInterface is compiled. In general, there is no difference between an “is-a” for classes and for interfaces, i.e. "Like-a" is equivalent to "is-a".
- And instanceof does not work with generalizations.
- Remember the definitions:
coupling - coupling. This is the extent to which each software module uses other modules.
cohesion - connectivity. This is the degree of internal interconnection between parts of a single module. Or else it can be defined as a measure of class focus on its direct tasks.
- For some reason, there are a lot of questions about design patterns (can anyone tell what is so extraordinary about them?). Honestly, I have some gaps here, because Nowhere did I really find any intelligible materials (Wikipedia is lame). Here it is more or less written about DAO. And in general, I think a good programmer should himself invent patterns suitable specifically for his project, and not follow such “recommendations” everywhere. In short, singleton, DAO and factory at the exam is better to know.
- You need to remember the main arguments of the javac command line utilities (-cp, -d, -source), java (-ea, -da, -cp) and the jar utilities.
- What did not occur on the exam:
- Questions about the garbage collection. Although in all the above tests, he was very "loved".
- There was no code using all sorts of Executors. There was only one question on the theory.
- Thread Pools. Not at all.
- Code using subclasses RowSet. Only theory.
It is clear that if I did not come across some topic, this does not mean that it is not in question. But can someone simplify the already capacious training. I suspect that Oracle periodically updates the set of questions so that such posts do not make life sweeter. So dare while fresh :)
Conclusion
Of course, a lot of material remained about which I did not write (listings, work with files, JDBC, Localizarion, ResourceBundle and probably something else). On these topics, I propose to figure out for yourself, because In my opinion, they do not present any particular difficulties. And of course everyone good luck on the exam!