https://www.gravatar.com/avatar/306d401b2a8c0efe0996fec60e0c90aa?s=240&d=mp

My coding journey

Disclaimer: it's just for fun

Dart for Java developers

Welcome in a new series of articles about Dart programming language.

It is not a beginner tutorial. I focus mainly on features that may be surprising and/or interesting for a Java(Script) developer.

Slides

Slide notes are available here.

The resources:

Start with these:…

  1. https://dart.dev/guides/language/language-tour (language overview)
  2. https://dartpad.dev/ (write & run in online editor)
  3. https://dart.dev/guides/language/spec (language specification page, current spec pdf: 2.10)
  4. https://dart.dev/guides/language/effective-dart (good practices)

Basics

… or look below:

Summaries of 2022 and predictions for 2023

Java predictions

Predictions by authors of Java JVM Trends focus on faster adoption of new Java features and long-term releases

  • frameworks (Helidon, Vert.x etx.) start providing Virtual Threads programming models, so the usage of this language/platform feature would grow
  • native Java could become more visible due to Project Leyden (back to life in 2022) and focus on ease of use for Spring developers
  • migration from MicroProfile Metrics to metrics and tracing by Micrometer.
  • frameworks set the baseline to Java 17 (Spring)
  • Java 11 takes over Java 8 (market): needs modernization of old stacks (libs, dependencies), challenge for many Java developers
  • adoption of Java 17 is faster than Java 11
  • Java as a language is strong (Jetbrains dev ecosystem research from 2021, waiting for 2022 one)

Resources

IT predictions

  • more focus on security
  • recognition for core value of IT Ops / Dev Ops
  • Amazon (or: Cloud) rising even more
  • optimization of development, processes, libraries in the direction of
    • containers
    • CI/CD
  • more impact of developers and engeneers on company-level decision making
  • no-code is not a threat for developers
  • GPT-4 would be a game-changer; robotics will go mainstream expected adoption of self-driving cars
  • buzzing in social platforms (Twitter, Tik-Tok), possible further content-moderation regulatory actions (esp. in Europe)
  • new trends: IoB (Internet of Behaviour) - analysis of human behaviour with analytics (security issues) and prediction of futire behavior

Resources

What I think

I’m reading about the trends in IT and expected directions for companies, inverstors and business in IT world and one theme comes again and again as a common denominator of all the predictions. This theme is: the client. But we as individuals are not “the client”: we are “the revenue stream”. The real client (the one who gives money to software companies) wants the information and needs software professionals to dig that information in order to know:

Modern Java in Action 8 - concurrency and reactive programming

Task appropriate for the job

  • high parallelization : use fork-join pool and and parallel streams for highly CPU-bound calculations
  • high interactivity: high concurrency and a need to keep a lot of IO-bound tasks on single CPU: use Future (Completable Future) or Flow API

Problems and solutions

Threads problems

  • map 1:1 to OS threads (expensive to create and of limited number)
  • much higher number than hardware threads (cores? well, it seems a core is more complex)

CPUs like the Intel i7-6900K have multiple hardware threads per core, so the CPU can execute useful instructions even for short delays such as a cache miss.

Modern Java in Action 6 - Time and Date

Reasons to abandon old API

java.util.Date

  • mutable
  • unintuitive constructor (days, months, minutes and seconds are 0-based, year represented as delta from 1900), values wrap-around
  • cannot be internationalized

java.util.Calendar

  • not thread safe
  • mutable (no clear semantics date change)
  • when to use which?

java.util.DateFormat

  • not thead-safe
  • can only parse Date, not Calendar

New API

/en/posts/modern-java-in-action-6/time.png

java.time package

Classes and interfaces in a new package java.time (modelled after Joda Time classes) provide better way of thinking about and working with time concepts. The most important classess in this package are: LocalDate, LocalTime, LocalDateTime, Instant, Duration, and Period .

Modern Java in Action 5 - Optional

Null problem

Reasons why null is problematic:

  • source of coding errors (missing checks)
  • does not correctly model absence of value (null has no meaning)
  • breaks Java philosophy of hiding pointers (null is a pointer which is NOT hidden)

Handling in other languages

Optional

Creating

Three static methods may create instances of Optional:

Modern Java in Action 4 - refactoring and testing

Refatoring

Here are three simple refactorings that can be used if you want to migrate your codebase to Java 8 (or higher). You may want to do so for many different reasons (readability, conciseness, code reuse, security).

  • Refactoring anonymous classes to lambda expressions
  • Refactoring lambda expressions to method references
  • Refactoring imperative-style data processing to streams

Recommended paper about automatic refactoing of pre-Java 8 codebases into Java8: Lambda Refactoring

Gotchas

  • different meaning of this and super (in lambda this refers to enclosing class, in inner class - to itself)
  • lambdas cannot (and anonymous inner classes can) shadow enclosing class variables

Code flexibility

Question: when to introduce functional interfaces?