My good friend Mark is doing Java. It brings back memories. Great to see that people are still using the command-line to compile and execute Java classes (command-line is back, y’all!).

Entering a javac (compile) and a java (execution) command seems tedious, so I wondered if those could be scripted into a good old .bat file. It has been a while since I’ve been playing around with batch files. I’ve seen my father do it… it still looks like a dark – and ancient – art to me.

Batch me!

I’ve created a file called yall.bat which looks like:


IF '%1'=='' GOTO error
IF NOT EXIST %1 GOTO notfound

ECHO Compiling '%1'...
javac "%~f1"
ECHO done!

ECHO Executing '%~n1':
java %~n1

GOTO end

ECHO Invalid syntax. Please use:
ECHO yall {filename}
GOTO end

ECHO File '%1' not found.
GOTO end


Say what!?

There are some weird variable modifiers that should be explained:

  • %1 is the variable name of the first argument that is passed to the batch script.
  • %~f1 is the first argument turned into a fully qualified file name.
  • %~n1 is the first argument turned into the file name without the extension.

Yep… dark arts indeed. Here is a list of arguments I’ve found on StackOverflow:

[table “” not found /]

Might be handy as a reference for building future batch script (although one ought to move to PowerShell).

Final thoughts

Batch. Still. Cool. Java. Still. Runs.