Preparation for Option D, Object-Oriented Programming in Java

Students going into the IB Computer Science programme, particularly if it’s HL, will benefit from an understanding of the basics of Java programming and the ability to code simple programs before class begins.

On of the best online courses I’ve found are by a guy called John Purcell from Cave of Programming. His Youtube Java course is here:

If you sign up on his site, then you get to discuss the course with other users and perhaps even ask John questions.

https://caveofprogramming.teachable.com/p/java-for-complete-beginners

If you cover these lessons before you start the IB Computer Science course you will be very well prepared. As you can see they’re not very long. You will need to have an IDE installed. John uses Eclipse, which is certainly a good IDE, but most IB teachers tend to use Netbeans in class. My personal preference is IntelliJ.

These are the videos that have most relevance to the IB course. Those with asterisks are not directly examined but are useful for making working programs.

  • A Hello World Program (4:46)
  • Using Variables (7:53)
  • Strings: Working With Text (9:21)
  • While Loops (7:15)
  • For Loops (9:28)
  • If statements (12:26)
  • Getting User Input* (8:52)
  • Do … While (8:05)
  • Switch (6:52)
  • Arrays (9:46)
  • Arrays of Strings (8:39)
  • Multi-Dimensional Arrays (13:06)
  • Classes and Objects (11:44)
  • Methods (11:05)
  • Getters and Return Values (10:31)
  • Method Parameters (15:00)
  • Setters and “this” (10:57)
  • Constructors (10:18)
  • Static (and Final) (19:46)
  • String Builder and String Formatting* (19:43)
  • The toString Method (11:06)
  • Inheritance (14:09)
  • Public, Private, Protected (19:57)
  • Polymorphism (10:04)
  • Encapsulation and the API Docs (11:17)

Using JavaFX for your IB Computer Science IA

If you are comfortable using IntelliJ with/without Gradle or Maven then fine, but I find that sometimes these tools mask what is going on behind the scenes. For that reason, I often like to use a simple text editor for small projects. To get JavaFX working without a build manager, follow these simple instructions.

Download a version of JavaFX. I downloaded the Linux SDK (version 12) from here: https://gluonhq.com/products/javafx/

Unzip it to a place on your file system that you use to store java libraries. I just put mine in my home directory.

Create Main.java with the following code:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class Main extends Application {
    public void start(Stage stage) {
        Scene scene = new Scene(new Label("Foo"));
        stage.setScene(scene);
        stage.show();
    }
}

 
In order not to have to make changes to your CLASSPATH you can add arguments to the compiler and the JVM.

Compile with

javac --module-path ~/javafx-sdk-12.0.2/lib --add-modules javafx.controls Main.java

Run with

java --module-path ~/javafx-sdk-12.0.2/lib --add-modules javafx.controls Main

Other modules may be required as you use more features of JavaFX.