Here are some of my latest thoughts on java… such as thread-first and loop (•̀ᴗ•́)و
Java CheatSheet
Modern Java is a strongly-typed, eagery evaluated, case sensative, yet whitespace insensative language. It uses hierarchies of classes/types to structure data, but also has first-class support for functional-style algebraic datatypes.
Java programs are made up of ‘classes’, classes contain methods, and methods contain commands. To just try out a snippet of code, we can
Open a terminal and enter
jshell
; then enter:1 + 2 // The jshell lets you try things out! // Say hello in a fancy way import javax.swing.*; JOptionPane.showMessageDialog(new JFrame(), "Hello, World!");
- Alternatively, in IntelliJ, click Tools then Groovy Console to try things out!
- Finally, VSCode allows arbitrary Java code to be sent to a
jshell
in the background(!) and it echoes the result in a friendly way.
💐 Repl Driven Development: /Editor Integrated REPLs for all languages/ 🔁
The package makes the philosophy of REPL Driven Development (RDD) accessible to any language that has a primitive CLI repl: The result is an Emacs interface for the language, where code of your choosing is evaluated, and results are echoed at your cursor in overlays.
That is, with Repl aided development, you make software by starting with an already working program (i.e., the repl) then incrementlly “teach it” to be the program you want, by defining & redefining things. Until satisfied, loop: Type/modify code in your editor, press some keys to evaluate what you wrote/modified in the currently running system, and explore/test the resulting runtime.
RDD is programming emphasising fast & rich feedback from a running system. RDD is fantastic for quickly teaching/exploring an idea; as such, the running example of this article will be on servers —no prior experience with servers is assumed. The main examples will be in JavaScript, Python, and Java. (Since JavaScript is just Lisp in C clothing, we will not discuss Lisp.) Since Java is verbose, the power of REPLs really pays off when exploring a new idea. We see how many imports and setup-code simply disappear in the RDD approach, letting you focus on the core idea you're exploring/teaching. For comparison, a traditional self-contained Java server program is ~30 lines long whereas the focused RDD approach is ~4 lines long.
tdlr: This library provides the Emacs built-in C-x C-e behaviour for arbitrary languages, provided they have a primitive cli REPL.
💐 Making VSCode itself a Java REPL 🔁
VSCode evaluates Java code wherever it sees it, by sending it to a JShell in the background, and echos the results in a friendly way!
This is achieved with a meta-extension for VSCode that makes VSCode into a living, breathing, JS interpreter: It can execute arbitrary JS that alters VSCode on-the-fly. (Inspired by using Emacs and Lisp!)
The relevant docs show how to make a similar REPL for Python, Ruby, Clojure, Common Lisp, JavaScript, Typescript, Haskell, and of-course Java.
Life & Computing Science by Musa Al-hassy is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License