This time, I took the Java SE 8 Programmer II (Gold) on a certain day in November and passed it successfully.
There are various passing experiences in this Qiita, and I think that I thought about taking the Gold exam around May, so I don't think I was able to study efficiently as a compliment.
However, I feel that I was able to dig deeper into the process and ideas of the operation over time. Actually, it was not a perfect score, but I was able to follow the process and solve the problem while chewing.
In getting the qualification, it was a good experience to be able to absorb the problem collection as my own knowledge without relying on the dark clouds.
In this article, I will follow the content that I found interesting regardless of the frequency.
Stream Pipeline
The Stream API is unavoidable when taking the Gold exam, but it has a mechanism that makes the operation flow seemingly misleading. However, once you understand it, I think it will be useful for Stream-related problems.
An example is shown below.
example.java
public class example{
public static void main(String[] args){
Stream<String> fruit = Stream.of("banana", "grape", "orange","apple");
.filter(s -> s.length() > 5)
.peek(System.out::print)
.map(String::toUpperCase)
.peek(System.out::print);
long l = fruit.count();
}
}
Since the termination operation count is shown, the intermediate operation defined in fruit is executed with a delay. So how are each element of the Stream processed?
At the beginning of learning, I imagined the following flow.
That is, I thought that all the elements would be verified for each intermediate operation. If this is correct, the output should be bananaorangeBANANA ORANGE
. At first glance it seems correct.
However, in reality, it was different, ** the elements defined in Stream.of were manipulated one by one to the end, and then moved to the next element **.
In other words, the execution order of peek is ② → ④ → ⑦ → ⑨, so the output is bananaBANANAorangeORANGE
.
You may not need to be aware of it when actually using Stream, but once you understand the flow of the operation order, you can unravel it without moving even if the appearance changes a little. It should be noted that if there is no termination operation count, nothing is output because Stream is only an intermediate operation. It is often asked that the termination operation is described correctly. (I feel that there were a lot of optional entanglements)
There are a few questions in the areas of exceptions and assertions, but I don't want to miss them because they are easier to remember than the other items. It is a place that cannot be avoided even in practice (I think), so I think it is a field where learning can definitely be utilized.
First, the multi-catch introduced in SE7. This is a syntax that allows exception handling to be described collectively by separating them with "|". There are two points to note here.
** 1. Exceptions in inheritance relationship (polymorphic) cannot be listed together **
For example, writing ʻIOException and ʻException
together will result in a compile error.
** 2. One variable ** Even if there are many exceptions to be listed together, there is only one variable at the end. If you write more than one, a compile error will occur.
catch(IOException e1 | InterruptedException e2){} //Compile error
Also, if you have multiple catch clauses, you can't put a subclass exception after a superclass exception (because it's caught in front and can't be checked).
Next, this is also a try-with-resource statement introduced in SE7. This is a syntax that provides a mechanism that can automatically close what was described in the finally clause (ex.FileReader
) before SE 6.
The mechanism is applied by defining the resource in the back bracket of try as shown below.
try(FileReader fr = new FileReader("sample1.txt");
FileWriter fw = new FileWriter("sample2.txt")){
//Reading and writing resources
}catch(IOException e){
//Exception handling
}
Here, ** the order of closing is the reverse of the defined order **. Also, if the resource does not implement ʻAutoClosable or
Closable, such as when the resource is defined independently, a compile error will occur. Classes commonly used in I / O can be executed without problems because they implement ʻAutoClosable
.
ForkJoinPool
ForkJoinPool defines three types of execution methods. Of these, only invoke synchronizes processing.
Also, in the case of asynchronous, the execution method changes depending on the return value. It is summarized below.
Method name | Return value | Sync/非Sync | Inheritance class |
---|---|---|---|
execute | void | asynchronous | RecursiveAction |
invoke | T | Sync | RecursiveAction/RecursiveTask<V> |
submit | ForkJoinTask<T> | asynchronous | RecursiveTask<V> |
Looking at the method you are using, if it is invoke, the result will be unique, otherwise it will be undefined.
Scrollable ResultSet
ResultSet in JDBC allows you to define a mechanism that allows you to move the cursor freely.
//Statement definition for using scrollable ResultSet
Statement createStatement(int resultType, int resultSetConcurrency) throws SQLException
The constants that can be defined for the first and second arguments are defined in the ResultSet interface.
--First argument --TYPE_FORWARD_ONLY: Move only forward --TYPE_SCROLL_INSENSITIVE: Scrollable, DB not reflected --TYPE_SCROLL_SENSITIVE: Scrollable, DB reflected --Second argument --CONCUR_READ_ONLY: Cannot be updated ResultSet --CONCUR_UPDATABLE: Updatable ResultSet
Two arguments are required, so writing only one will result in a compile error.
In case of updatable ResultSet, if the primary key is set in the target table, each operation of Insert, Update and Delete is possible, but ** ʻinsertRow / ʻupdateRow
/ deleteRow
method must be called. If it is not actually reflected in the DB **.
Compared to Silver, I feel that Gold was required to have a considerable amount of memorization and deep understanding. It was often too much and depressing. However, since it is good at my own pace, I think that it is a qualification that can be sufficiently acquired if you take the time to work on it. The exam fee is a bottleneck ... </ font>
I was able to pass the study by Kuromoto in the references. If you only consider the exam, this book and the official API check are sufficient. If you want a deeper understanding and a complete correct answer, you may want to consider purple books ...
I think there is no loss in taking on the challenge. If you are thinking of learning java, let's aim to acquire Silver and Gold!
[Thorough capture Java SE 8 Gold problem collection [1Z0-809] correspondence](https://www.amazon.co.jp/%E5%BE%B9%E5%BA%95%E6%94%BB%E7% 95% A5-Java-Gold-% E5% 95% 8F% E9% A1% 8C% E9% 9B% 86-1Z0-809 / dp / 4295000035)
Recommended Posts