Announcing new Java 11 OCP Books!

Update (11/05/2020): Read The 1Z0-819 Exam page to learn how you can easily our Java 11 Study Guides to prepare for Oracle’s 1Z0-819 Exam, as well as the 1Z0-817 Upgrade Exam.

Jeanne and I are thrilled to announce that we are releasing Java 11 OCP books early next year. Yes, you heard that right, books plural, as in more than one! In fact, we’ll be releasing two new books, along with a complete set edition.

We’ll post links where you can preorder the books as soon as they are available!

These books have been carefully written and include the most important information you need to know for the Java 11 OCP exams. While we are quite proud of our Java 8 books, there’s a lot of new material required for the exams including modules, var, and custom annotations just to name a few.

If you’re thinking of taking the new exams prior to the books’ release, we recommend reading our posts detailing our experiences taking the exams:

In short, if you’re comparing the first exam (1Z0-815) to the older OCA 8 (1Z0-808) exam, don’t. They are quite different and the difficulty level has definitely been increased. We expect both books to be available in early 2020. In fact, we’re nearly done writing the first book already!

OCA/OCP 8 Programmer Practice Tests AVAILABLE NOW!

Jeanne and I are really excited to announce that our new book OCA / OCP Practice Tests: Exam 1Z0-808 and Exam 1Z0-809 is now shipping. In fact, we just received our copies today! The book is available in both print and digital formats from Amazon and other major book retailers. In addition, purchasing this book grants the holder access to Sybex’s interactive test bank!

This book serves as worthwhile companion to our previous two books, now available as set, The OCA / OCP Certification Kit. With this book you are really getting two books in one, as Jeanne and I packed over 1000+ questions into this text, covering both the OCA and OCP exams. To better prepare you for test day, we also threw in two simulated OCA/OCP exams. Whether your taking the OCA exam now and thinking about the OCP exam down the road, or taking the OCP exam and need a refresher on the cumulative material, this book has got you covered!

This book covers 100% of all exam objectives in these practice tests, which means you’ll be ready for:

  • Java basics, class design, and data types
  • Using decision and loop constructs
  • Building and using arrays
  • Methods, encapsulation, and inheritance
  • Mastering Java Streams
  • Working with the Date/Time API and Localization
  • Understanding design patterns and principles
  • Writing Lambda expressions and functional interfaces
  • Exceptions and assertions
  • Java File I/O (NIO.2)
  • Concurrency and localization
  • JDBC and database applications

Jeanne and I put a lot of time, energy, and planning into this new book and we really hope our reader enjoy it!

OCP 8 – working with autocommit vs savepoints

You might want to know more about JDBC than is covered by Chapter 10 of our book, OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide: Exam 1Z0-809. This blog post teaches you about autocommit and savepoints and assumes you have completed reading chapter 10 of our OCP 8 book and are looking to learn more. (Note: we’ve heard rumors this topic is in fact on the exam. It wasn’t when we took the beta but was on the Java 7 exam. So either the questions are left over or it was added back.)

In the book, you saw how to run one statement at a time and have the database automatically see the changes right away. This is called automatic commit or auto-commit for short. A commit updates the database. JDBC provides options for more control by running your code in transactions. A transaction allows a group of statements to go together.

Rollback/Commit

By default, auto-commit is set to true which means each statement is committed in the database as soon as it is run. You can set it to false so statements and prepared statements do not automatically commit data.

The following example gives that control. If anything goes wrong update either of the rows, the entire transaction is rolled back and the database doesn’t change either row. If both are successful, the database sees both.

conn.setAutoCommit(false);
String sql = "update species name = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
try {
  ps.setString(1, "Elephant");
  ps.setInt(2, 1);
  ps.executeUpdate();
  ps.setString(1, "Monkey");
  ps.setInt(2, 4);
  ps.executeUpdate();
  
  conn.commit();      // send data to database
} catch (SQLException e) {
  conn.rollback();    // don't update database
}

Let’s rewrite this example to focus more on the commit/rollback code:

conn.setAutoCommit(false);
String sql = "update species name = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
try {
  updateRecord(1);
  updateRecord(2);
  conn.commit(); // send data to database 
} catch (SQLException e) {
  conn.rollback(); // don't update database 
} 

Setting a Rollback point

JDBC has a type called a Savepoint which is like putting a bookmark in a book so you can easily get back there.

conn.setAutoCommit(false);
String sql = "update species name = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
try {
  updateRecord(1);
  Savepoint sp = conn.setSavepoint();
  updateRecord(2);
  updateRecord(3);
  // oops - let's go back like this didn't happen
  conn.rollback(sp);
  // proceed from there
  updateRecord(4);
  conn.commit(); // send data to database 
} catch (SQLException e) { 
  conn.rollback(); // don't update database 
}