Java TL;DR — The first few steps.

With examples.

Edward Green
Aug 25, 2017 · 4 min read

Contents

  1. Introduction
  2. The big picture
  3. What a page of code actually looks like
  4. Getting (basic) code to run

Introduction

What is Java?

A programming language.

What does TL;DR mean?

Too long, didn’t read.

What does TL;DR — Java mean?

The most concise guide in existence on learning Java.

Requirements/scope

Get yourself a plain text editor or IDE (like Eclipse or IntelliJ). No, I’m not teaching you how to set them up.

The Big Picture

How do programs work?

You write source code that serves x purpose.
You compile that source code.
The customer runs/uses what you compiled.

When I write “front-end” or “back-end”, read “some of the front-end purposes” and “some of the back-end purposes”.

Case-study: Snapchat

Front-end: takes your selfie, adds a dog filter, sends it to Snapchat’s servers, shows your current score.
Back-end: receives your selfie, forwards to friend, updates your score.

Case-study: Video games

Front-end: takes keyboard input, produces client output (updating the screen), maybe some client side physics calculations.
Back-end: provides network to play online, handles games, sessions etc.

Case-study: Accounting Software

Front-end: entering your data, operating on some data, sending data to database
Back-end: backing up/storing/replying to queries

Case-study: Console Application

Front-end: takes in two numbers, presents the result.
Back-end: does the math.

Lines are blurry here. Here’s the idea. We’re talking about two sets of functionality to achieve a service. Functionality that deals with user interaction and functionality that operates on data. This is an example of abstract thinking.

Different sets of functions need to be solved in different ways; this is almost always done by client-server i.e., what does the client need to do? How do we get them to achieve that?

So how do I programme?

  1. Get a problem.
  2. Break down the problem into small parts. E.g., How would you mail a letter?
  3. Understand how to solve each small part. Print your letter, get an envelope, then stamp it, post it.
  4. Express your solutions in Java syntax.
  5. Orchestrate all of these small solutions together in a way that makes sense… Then compile and rip off your customer.

What a page of code actually looks like

Let’s simulate a living room with a TV in it.

Our problem:

We want to watch TV in our living room.

Small parts:

We need a living room. We need ourselves in that living room. We need to pick up the TV remote. We turn the TV on and then turn it off.

Expressing this in Java:

2 minute exercise: see if you can spot any patterns (hint: we start on line 15), if you can’t see any, don’t worry, this is day one.

Problem solved.

Below is what we can read from the standard output (the console).

Getting code to run

Okay, so the source code is written. Now we need to learn about that Java platform and compilation.

What is the Java platform?

Resources needed to make your code run. It contains:

  1. The Java Virtual Machine (JVM) — a computer in your computer.
  2. The Java Runtime Environment (JRE) — runs your compiled code in the computer in your computer.
  3. The Java Development Kit (JDK) — is what you use to write the code that is compiled to run on the computer in your computer.

Wiki: https://en.wikipedia.org/wiki/Java_virtual_machine

Still unsure? e-mail me: ed@verygoodsoftwarecompany.com

What version are we on?

Java 8

What is compilation?

In tl;dr terms: getting (barely) human-readable code written in Java. Then turn it into a long list of 1s and 0s which the machine can read.

Have a quick read if you want more knowledge:

How do we compile Java code?

With one source code file it’s easy. We’ll cover more complex programmes later.

You need to complete this code so you get the output “hello world” from the console. Hint: look at the above examples to see what statements you need to use.

  1. Download, copy/paste, write your own HelloWorld.java file.
  2. Open up your console programme, navigate to /<parent_directory_of>/HelloWorld.java.
  3. Type in “javac HelloWorld.java” & hit enter. OMG, A wild HelloWorld.class just appeared!
  4. Type in “java HelloWorld” (N.b. case matters).
  5. Revel in your mighty control over computers.

Caveats

  1. You need a “public static void main(String[] args) {…” method to run a Java programme.
  2. Life gets more complicated with more classes, this is just a footnote because we’ll cover it in later posts.
  3. If you’re using an IDE you can press the green “run” button instead of compiling and running as taught in the last section.
  4. It’s still a foundational necessity to know how to to compile and run from the command line.
)