Java’s javap command doesn’t show private members (by default)

As I was just reminded, Java’s javap command doesn’t show private members by default. You have to use the -p option of javap to see private members.

I was just reminded of that when using the Scala REPL. Given this Person class with a private constructor field named name:

class Person(private var name: String)

javap without the -p option shows this:

Java example: JMenuBar + KeyStroke + AbstractAction alvin July 16, 2018 - 6:54pm

As a brief note, here’s some source code that I used to create a JMenuBar in a Java application. First, I defined some fields in my main class:

private static final KeyStroke fileOpenKeystroke = KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.META_MASK);
private Action fileOpenAction;
private JMenuBar menuBar;

Later in the same class I defined this method:

A printf format reference page (cheat sheet)

Summary: This page is a printf formatting cheat sheet. I originally created this cheat sheet for my own purposes, and then thought I would share it here.

A cool thing about the printf formatting syntax is that the specifiers you can use are very similar, if not identical, between several different languages, including C, C++, Java, Perl, Ruby, and others, so your knowledge is reusable, which is a good thing.

A Java Factory Pattern example

Java Design Patterns FAQ: Can you provide an example of the Factory Pattern in Java?

Sure. In this article we'll look at a small-but-complete example of the Factory Pattern ("Factory Design Pattern") implemented in Java.

How to convert a Java Map to a Scala Map using JavaConverters

Here’s a quick look at how to convert a Java Map (such as HashMap) to a Scala Map using the JavaConverters object:

// import what you need
import java.util._
import scala.collection.JavaConverters._

// create and populate a java map
val jMap = new HashMap[String, String]()
jMap.put("first_name", "Alvin")
jMap.put("last_name",  "Alexander")

// convert the java map to a scala map
val sMap = jMap.asScala

How to use the Lightbend Config library in a Scala or Java application

Table of Contents1 - Adding the Lightbend Config dependency2 - A Scala application that uses Lightbend Config3 - The Lightbend Config configuration file4 - Discussion

If you want to use Lightbend Config configuration files in your Scala or Java application, here’s a quick example of how to configure and use Lightbend Config in your application. In this case I’m specifically using Scala and SBT.