Stay with me here, this may sound silly unless you are a teacher or student, but a standard part of many intro programming classes is learning the traditional Command Line Interface with simple tools like System.out.println() and java.util.Scanner. This lets you learn the basics of input, output and data processing with only a few lines of code:
System.out.println("Enter two numbers:"); Scanner scan = new Scanner(System.in); int val1 = scan.nextInt(); int val2 = scan.nextInt(); System.out.println("Total value is: " + (val1 + val2));
With just these basics you can write many interesting programs:
- Calculators, formula solvers, quizzes, surveys
- String manipulation: word counting, palindromes, anagrams, etc.
- Text based adventure games, digital psychologist, etc.
This was the only way to learn when I started on the TRS-80 and Apple II, and it’s still a great way to learn today, without introducing too many concepts that overwhelm new students. The downside is that these programs tend to be locked in the IDE or a terminal.
However, using a class called SnapPane, via one extra line of code, the same app that runs at the console pops up a window instead and runs on the desktop. And with SnapTea, and another line of code, you can then run in the browser and share with the world. Here’s a command line calculator running in the browser (notice, also, a tab to view the source code):