These are suggestions for how to most effectively learn a new programming language. There are a few common steps you can take to learn most any new programming language, and I’ll describe those here along with suggestions specific to Java.

Before I say anything else, though, my primary, above-all-else suggestion is to remember you’re not learning a language on your own. When you have a question or run into something difficult, and you will, post a question in the Q&A forum and/or come to office hours. Someone else in the class has probably run into the same thing and can help, and your professors and TAs definitely can. It’s a waste of your time to try to figure everything out yourself when getting some help would be much more efficient. Don’t waste your time like that. And help each other out!

1. Getting Started

The very first thing to work out in any new language is “Hello, World!” The hello world program is basically the simplest program you can write in most languages, and your first task is to get that working. By getting hello world to work, you will have learned the basics of the language’s syntax, but more importantly, you’ll have learned how to write, store, and execute a program in the language. Does the language use an interpreter? Is it compiled? Do you run the code with a virtual machine? Etc.

Command Line

Using an IDE (below) is convenient and can offer a lot of powerful features, but it is important to be able to use the compiler directly and run things from the command line, also. Make sure to at least become familiar with this. It is how I will run and test your code if we’re using Java in a course, so you should test it that way as well.

In order to write, compile, and run a Java program on the command line, you’ll need a good text editor and the Java Development Kit (JDK).

Text Editor

A good text editor for programming will provide a lot of features that make your life easier as a programmer without being as complicated as a full IDE (below).

I recommend any of the following (all free downloads):

  • Notepad++ (Windows)
  • BBEdit (Mac)
  • VSCode (Win, Mac, Linux)
  • Vim (has a steep learning curve, but is worth learning at some point — feel free to ask me why)

JDK

The Java Development Kit (JDK) contains everything you need to compile and run your Java code on the command line. Grab the latest release from Adoptium.

Compiling and Running on the Command Line

Princeton’s Intro CS course has a good guide to these first steps.

To access the command line, you’ll need to use a terminal program:

  • MacOS comes with the “Terminal” application.
  • Windows doesn’t have a great terminal by default, but you can install Windows Terminal.

If you have trouble finding your .java file when you try to compile it on the command line, get in touch with your TA or professor for help navigating the command line.

Once you see your program running and printing out “Hello, World!”, you’ve got it working!

Integrated Development Environment (IDE)

If you want to use an IDE, there are simpler beginner-/student-friendly IDEs and full-featured professional IDEs.

Simple:

  • BlueJ [my recommendation]

Powerful:

I recommend BlueJ if you want to focus on just learning Java and not the IDE itself, and any of the others are good if you want to gain experience with a professional tool.

2. Learn the Syntax

Once you know how to write and execute a basic program, it’s time to figure out how to write other programs using the programming concepts you already know. That’s primarily a matter of learning the syntax for loops, functions, variables, conditionals, etc. in the new language.

Books & Tutorials

To start, you should take a methodical approach, working through something structured to… well, give you some structure.

There are several good Java textbooks freely available online:

It can be difficult to work through a textbook, though, and they may work better as references for looking up topics as needed. Tutorials may work better for you, in which case here are a few good ones:

Cheat Sheets

At some point, you can start looking up specific topics in a general reference. You’ll have the general idea, but you’ll run into something from time to time that you want to look up. The following references are structured for someone who already knows C++ or Python; they assume you don’t need to learn the basics of programming, and they illustrate points with example translations from the familiar language:

Those aren’t the only references out there, of course. Searching for “java cheat sheet” or similar queries can find others you might like more.

Examples

Additionally, example code is always very helpful. It’s one thing to read about a topic and see the bare syntax patterns, but it can be much more useful to see a complete, working example:

Standard Library Documentation

Java’s standard library is full of classes that solve common problems you will encounter in your own work. Don’t reinvent the wheel; use the standard library as much as possible. The textbooks and tutorials above will introduce many commonly-used classes, and again example code is an excellent resource for seeing what already exists that you can use. To check the details of any standard library class, the official API documentation is an invaluable reference:

3. Practice

You might be tempted to just start into an assignment right away, and I can’t stop you, but I’d recommend you take just a bit of time to practice with the language first. By practice, I mean work on simple problems that give you immediate feedback about whether you’ve solved it correctly or not. These sites, for example, let you submit code to solve problems online, and they give you instant feedback. Run through some exercises. Focus on specific topics you want to learn.

  • CodingBat Java
  • Advent of Code — Each year, there’s a new set of problems posted throughout December in a roughly increasing order of difficulty. You can access problems from past years on the site as well.
  • Practice-It

4. Write Lots of Code

There’s no way around it: you have to write a lot of code to become proficient with any language. The more you write, the more you’ll learn and the easier it will get.

And Don’t Forget!…

Ask for help when you need it. You will need it, and you should ask. I understand the urge to figure something out yourself, but 1) it’s a waste of time to bang your head against something for hours when you could get a quick answer to a quick question and move on, and 2) you get no extra points, figurative or otherwise, for learning something yourself. You get points, literal and otherwise, for learning something, no matter how you learn it, so make sure you’re doing so in the most effective way possible for yourself.