Tuesday, January 29, 2019

Java User's Group - Jan 29th, 2019 - The Future of Java

Simon Ritter, Deputy CTO, from Azul Systems gave a great presentation to 100 java developers about new things in Java 9,10,11, and 12. Slides are at www.slideshare.net/SimonRitter/moving-towards-jdk-12.

I did java programming 12 years ago and it was great fun to come back to the Java User's Group to see old friends again. Currently I'm doing C# .Net Core work, but I wanted to see what Java has been faring.

TL;DR: My impressions: Java is going to face headwinds with Oracle requiring money for licenses for production versions of JDK and beyond. Especially for small shops it's just easier to spin up a container with all open source and not worry about payments. Many organizations will stick with older free versions of Java (which is where Azul can make some money and help the community), but after a while, do you want to be on older versions of a language while the world is moving forward? It will be like watching ice melt on a 33 degree day, but we will see a slow abandonment of Java.

Java is still playing catchup with C# on features like "var", expanding switch statements, and raw string literals, but it's good to see the progress.

Here's my random, jumbled notes:

JDK 9, September 2017 86 new items. Oracle says JDK 9 was the last big release.

Java Platform Module System (JPMS) (JEP 220) breaks the 4,500 classes in Java into smaller chunks; with Modules you can create a runtime specific for your application only including modules needed for the app.

jlink (JEP 282) creates the java hierarchy with a smaller set of modules.

Instead of a release every two years, Oracle will release new JDKs twice a year, once in March and once in September. With so many releases, only certain ones will have long term support.

In JDK 11, some parts of the JDK will be open sourced like Flight recorder and Mission control. Some commercial features will be removed like JavaFX.

Java 8 had 350 methods deprecated, but never removed. JDK 9 removed six methods and one class (JavaBeans had a dependency on the desktop). JDK 10 removed 1 package, 6 classes, 9 methods and 1 field.

Compatibility not guaranteed in the future. Developers will have one release (six months) warning of deprecated.

Oracle JDK binary has LTS versions like 11, 17; Oracle OpenJDK does not.

Oracle JDK 11 has new license. Must have a paid-for license from Oracle for production for JavaSE. JDK 8 can be used forever for free, but without any further security patches and bug fixes.

What's new in JDK 10

Local Variable Type Inference (JEP 286) Java gets "var", infers type (like C#). "var" is not a reserved word, just a reserved type (meaning you can't create a class named "var").

JEP 307: Parallel Full GC for G1

JEP 310: Application Class-Data Sharing. Write java "schema" info to a file, to be read next time to speed startup.

JEP 317: JIT compiler (Graal)

Root Certificates, Heap allocation on other devices, remove javah tool, Garbage Collector Interface (Red Hat), Thread-Local Handshakes.

73 New APIs, like the collections List, Set, Map get a static copyOf() method to get an immutable copy.

What's new in JDK 11

17 JEPs, 3 from outside Oracle, like Red Hat's JEP 318 Epsilon garbage collector.

JEP 323: Local-variable syntax for lambda parameters.

JEP 327: new Unicode 10 Support for 8,518 new characters.

JEP 330: Launch Single file source code. Can launch a single file like "$java Factorial.java 4"

Many security features

Nashorn JavaScript engine deprecated

New I/O methods like nullInuptStream

String has new methods like isBlank(), repeat(int), strip()

Predicate now has Predicate.not()

What's new in JDK 11

Six modules removed, including java.corba, java.transaction, java.activation, java.xml.bind, java.xml.ws, java.xml.ws.annotation

Removes 27 command line flags and added 53

JDK 12 - A Small Release

JEP 325: Switch Expressions (Preview)

JEP 189: Shenandoah GC

JEP 334, 230, 341

New APIs: teeing(Collector, Collector, joinerFunc)

Class - describeConstable

Long Term Future

Project Amber, how to simplifying Java Language syntax. Kotlin is popular due to its clean syntax.

JEP 302: Lambda bits, single underscore for unused jparameters in lambda

JEP 326: Raw string literals, use backtick to start raw strings

JEP 305: Pattern Matching

Project Valhalla

Primitives are good for performance, objects good for OO concepts

Can have collections of primitives

Value types, are immutable, really

Project Loom

Loom introduces "fibres" which are lighter weight threads, less memory used, lower overhead

Zulu Java

Zulu community - Free versions of Open versions.

Zulu Enterprise - For money you can get backports of bug fixes and security patches from latest OpenJDK to previous releases.

Questions?

What is the effect of Oracle's new licensing pricing on the cloud? Cloud providers will provide support.

No more free JDK 11 from Oracle.

<

Thursday, January 17, 2019

Random Cheatsheet (mostly C# .net core)

Latest endpoint to connect Visual Studio to the Nuget.org repository is

https://api.nuget.org/v3/index.json

.Net Core 2.0, to include an HTML fragment into a .cshtml page:

    @await Html.PartialAsync("~/Views/Shared/_Address.cshtml")

To prepare for Dependency Injection in .Net Core 2.0

public void ConfigureServices(IServiceCollection services)
 {
     services.AddSingleton(provider => Configuration);
     services.AddTransient<IUserRepository, UserRepository>();
     services.AddSingleton<IMailer, SmtpMailer>();
 }

How to convert a json string to a C# Object

var myObject= JsonConvert.DeserializeObject(jsonString);

How to create a log4net factory outside of Startup.cs for unit testing.

public static ILoggerFactory GetLoggerFactory()
{
    var loggerFactory = new LoggerFactory();
    loggerFactory.AddProvider(new Log4NetProvider());
    loggerFactory.AddDebug();
    loggerFactory.AddConsole(GetTestConfiguration().GetSection("Logging"));
    loggerFactory.AddLog4Net("log4net.config");

    return loggerFactory;
}

Create simple Moq object in C#

var imailerMoq = new Mock();
imailerMoq.Setup(x => x.SendEmail(It.IsAny(), It.IsAny())).Returns(true);

How to return async task for a unit test

public async Task GetAwesomeString() {
   return await Task.FromResult("I'm the awesome returned text");
}

sudo -s //makes the entire session root

In C# you cannot downcast an object, only cast an object upwards:

wrong    Sheep sheep = (sheep)mammal;
right  Mammal mammal = (Mammal)sheep;

C# -- to get prettyprint of json object with indentation:

var json = JsonConvert.SerializeObject(myObject, Formatting.Indented);

C# to get a key from a value:

Dictionary dictionary = GetMyDictionary();
var name = dictionary.FirstOrDefault(x => x.Value == id).Key;

To change the prompt in linux:

echo "PS1='\w\$ '" >> ~/.bash_profile; source ~/.bash_profile

Wednesday, January 16, 2019

A TestDriven Workshop Example Using C# and NUnit

I've done this workshop multiple times at work to teach developers Test Driven Development using C# and NUnit.

You can clone it at https://github.com/fincher42/TDDWorkshopNunit.git

The theme of the workshop is from the movie "We Bought A Zoo".

Enjoy and leave me feedback below on how to improve the workshop.


Here's an outline of my notes:

Essence of TDD: Write failing tests **first**, before coding the functionality.

Ping Pong

  1. Bob writes a failing test
  2. Ashley writes just enough functionality in the method so it will pass.
  3. The code may then be refactored to make it cleaner.
  4. Bob and Ashley now switch roles and continue.

This is the Red/Green/Refactor cycle.

One method of arranging your code is to have Arrange/Act/Assert sections in your test.

Benefits of Test Driven Development:

  1. Encourages better architectural design
  2. Makes debugging easier
  3. Guarantees tests are written
  4. Encourages us to think about requirements and edge cases
  5. Let's you be courageous and refactor code

Drawbacks of Test Driven Development:

  1. Tests are expensive. They are expensive to write and more expensive to maintain.
  2. Perfect Unit Tests with 100% coverage do not offer any guarantees on overall code quality. Don't be lulled into a sense of false security.
  3. GUI, Integration, Performance, and Endurance tests are also needed.

Thursday, January 10, 2019

The Four Biggest Changes in Software Development in the Last 40 Years

I was giving a workshop on Test Driven Development today. Being a history nerd (don't get me started about the causes of the fall of the Roman Empire), I was reflecting back on how much has changed in software and how much hasn't. I started programming 42 years ago on punched cards. Here's my list of the most game changing developments in software in the last 40 years.

  1. Duh, It's the Internet
  2. Being able to use Stackoverflow and its kin, we can peruse the minds of thousands of people and find a solution quickly. Online training courses are available to teach us the latest software. It's simply amazing how much more we can create and learn.

  3. Computers are so much faster.
  4. With punched cards at Texas Tech University in the fall of 1976, a diligent student could get in five compile/executes cycles a day. Five. Now you can do that in a few minutes. This changes the way we develop software. Instead of mapping out your entire program on quadral paper using the IBM flowchart template with a Pentel mechanical pencil, we can start programming and build the software iteratively.

  5. Interactive Development Environments (IDE)
  6. Having an IDE that can pop-up all the available methods on an object is such a time saver. Having Resharper to refactor code on the fly, perfectly, is such an asset.

  7. Test Driven Development (TDD)
  8. Test Driven Development encourages us to write software that is easy to test, but more importantly, it demands a layered architecture and encourages small modules. TDD gives us the courage to do massive refactoring. Thank you Kent Beck.

My major professor at Tech use to tell us about a principle of good software engineering, but follow it up with "But, of course, this doesn't matter if you have really good people." That is still true today. The heart of producing good software is excellent people with small egos who have a passion to hone their craft and cooperate with their peers.

Wednesday, November 28, 2018

Retirement Planning and Financial Safety

I gave a presentation recently about saving and Financial Safety.
Here's a link to the slides: prezi.com/p/drbqcvfppehl. Use your right-arrow key to progress through the topics.
Let me know if you have any suggestions.

Wednesday, November 21, 2018

Logitech Mouse Buttons Not Working In Visual Studio 2017 or 2019

I love my Logitech Dark Field Performance MX mouse, but in Windows 10 using Visual Studio 2017 or 2019, the buttons won't work.  (Make a sad face with me).

The problem is that the logitech program needs to run with Admin privilege.
To fix:
0. In the System Tray, right click on the "SetPoint" icon and select "exit"
1. In a file browser open "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Logitech\Mouse and Keyboard"
2. Right click on "Mouse and Keyboard Settings" and select "Properties"
3. Select the "Compatibility" tab.
4. In the "Privilege Level" (or may be named "Settings") panel, select "Run the program as an Administrator".
5. Select "OK"
6. Restart "Mouse and Keyboard Settings" via the start menu.
7. Enjoy the buttons on your mouse in Visual Studio 2017/2019.


Wednesday, October 10, 2018

Agile Austin - Can Selflessness Lead to Collaboration?

This month's Agile Austin featured Erin Randall from Schwab talking on "How Building a Foundation of Selflessness Can Make You -- and Your Company Successful."

Here's my notes:

30% of collaboration in a company comes from 3-5% of the people.

Psychological Safety
  - Team members need to feel accepted and respected
  - They need the shared belief that the team is safe for interpersonal risk taking

Use words carefully

Victim Consciousness/Whole Body Yes:   "I have to ..." / "I get to ..."

"Be kind and full of love... but have boundaries ..."

Chunk your work to see its impact - do things for an extended period of time, not just a few minutes, to feel the impact.

Make certain to do things that fill you up.

Collin Powell said when the troops stop bringing you problems it's because they think you don't care or they think you can't help.

Erin is a big fan of storycubes.com

Give generously.
Acknowledge help.