Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

CodeOne Talks – Day One

2 min read

Here are my notes from the talks I attended on Day One of OracleCodeOne. Some excellent content – feel free to engage me on twitter at @markee174 if you have any questions.

A Dozen Cool Things You Can Do with JVM Languages [DEV3888]

JVM lets us pick and choose multiple languages to solve our problems.
1. Accessing a file – Groovy and Scala
Only languages which insist file exists with the checked exception is Java (not JVM),
2. Interacting with a process – Groovy
println ‘git help’.execute().text
3. Execute around Method Pattern – Java8
finalize() called on GC so not – not need even be called if lots of memory. Very bad place to call code
Java7 added Automatic Resource Management via Try with Resources as a partial solution
Never trust a feature with Management in its name
4. Traits in Scala
Can stack traits
5. Joining Strings in Java8
Example of printing comma separated strings in order creates complex code but simple in Stream.
6. Lazy in Scala and Kotlin
lazy keyword allows lazy evaluation temp = compute(x) will only be called if temp accessed.
Kotlin uses delegates
7. Argument matching in Kotlin
Nice feature Java will get with switch changes in Java13
Do you work for Compiler or Compiler works for you
8. Auto-casting in Kotlin
Smart casting in Kotlin with is String then understands the object is String
9. Creating XML documents in Groovy
Builder and languages make it easy to create XML
10. Tail call optimization in Scala
Kotlin makes it easy to extend
fun String.shout() = toUpperCase()
11. Extension methods in Kotlin
12. Fluency in Kotlin
Ran out of time….

Code examples can be downloaded.

Java Keynote: The Future of Java Is Now [KEY1099]

Separate post here.

 Java Modules: Why and How? [DEV3873]

Why do we need modules?

Created to make Java modular

No hands up for question do you need Corba.
java –list-modules shows all available modules (70 in Java11 alone)
Gives better boundaries and security
Make it easier to fail fast.
What’s a module?
modules require other modules
modules export their packages – reuse release equivalency principle

Simple Demo with First and Second class with and without modules. Classpath and modulepath -p for modulepath setting and can just take a directory.

jar can use -d to derive automatic module.
3 types of modules – unnamed module (everything in classpath combined), automatic jar (old jar on module path), explicitly named modules (has a module descriptor and on module path)
Adding to example
Once module files added, exports and require needed.
Advice to use transitive for breaking up code inhouse not for 3rd party libraries
-d with jar will show module name
Anything in classpath will be in unnamed module even if has a module-info file.

Modules cannot share packages

Modules check requires so will not run if missing jars.
Unnamed modules can talk to other unnamed modules
Automatic modules can talk to other automatic modules.
Automatic modules can talk to unnamed modules but not the other way round
Explicit modules can be talked to automatic modules but not the unnamed module. Has to require any module it needs.
You can add automatic module names in the manifest file

All this means you need the care to transition and refactor code. What is in classpath cannot talk to modulepath.
1. Start with legacy
2. Run all in classpath in modern java to make sure it works (missing libraries)
3. Run all in modulepath (split packages)
4. Give names for all automatic modules
5. Convert from top to bottom to explicit modules

Code examples can be downloaded.

Better Test Assertions with Truth [DEV1298]

Open-source library from Google

Aimed at experienced Java developers who use JUnit.
3 big features in Truth
Makes code and messages clearer
Fluent API
More assertions, especially for collections
Clearer assertion failure messages
Nice assertThat tools in Truth (is isSameInstanceAs)
Meaningful error messages
Makes it easy to work with Sets and Lists in tests – can also test inOrder()
Extra truth8 jar adds assertions for streams and options

JavaFX 12 and Beyond [DEV4112]

Removed from Oracle JDK in JDK11 (was not in OpenJDK build).
Can be added in using module from or via Maven and Gradle.
As with JDK, train model to release every 6 months.
Will run with OpenJFX N runs on JDK N-1 and later.
JavaFX12 release – 9 enhancements and 41 bug fixes. The biggest feature, allow 3rd party controls.
Image smoothing in Canvas in JavaFX 12
JavaFX13 – 8 enhancements and 54 bug fixes

View PDF files in a web application →

Parse PDF files as HTML →

Display PDF Forms in a web browser →

View PDF Documents in Java Applications →

Rasterize PDF Documents to image →

Read/Write images (including HEIC, JPG and WEBP) →

Convert Image files to PDF Documents →

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2022. All rights reserved.