How to Get Started With Java (as a Beginner)

For better or worse, Java is one of the dominant languages in the software engineering industry. As a software engineering professional, you’ll quite possibly have to work with a Java code base at one point in your career. I am not a big fan of Java, and I don’t think it’s a good first language in the computer science curriculum. Sadly, this is often the case. In fact, Java is a horrible first language. The first two “real” languages I learnt were Python and Scheme (Lisp), and thus I was used to elegance and expressiveness. Java felt like a big step back. For instance, here are a few lines of Python code that print the numbers from 1 to 5:

for i in range(1, 5):
    print i

Here is the equivalent in Java:

package demo;

public class RangeDemo {

	public static void main(String[] args) {
		
		for (int i = 1; i < 5; i++) {
			System.out.println(i);
		}
	}
}

Following Java style guides, you end up with a staggering 11 lines of code instead of 2. Just look at all the wasted horizontal space and the baroque syntax! Proponents of Java like to point out that their language was never designed to write simple “scripts”, but Java bloat is a factor no matter how large your program is. You’ll end up writing reams of code that do very little, and you quickly end up wondering why the code base is metastasizing in front of your eyes. What Python could do in, say, 100 lines could easily require about 1,000 lines in Java. This is not an exaggeration.

I could write a couple of blog posts on the downsides of Java, but my point is merely that there are better languages to learn as a beginner. You are probably better off checking out Python first if you are new to programming. But let’s say you’ve got no choice because you have enrolled in a computer science program, and now you find yourself sitting in an intro class, confused that CS isn’t about playing video games, web design, or using MS Office. Your instructor wields a 1,500 page tome on Java and pontificates about its “industrial strength” and the marvels of object-orientation.

Let’s start with textbooks first. Textbooks seem to get bigger and bigger so that they can be sold for more and more money. Yet, didactically, they only get worse. In case of Java, though, I do think that common textbooks mirror the verbosity of the language they describe in a wondrous way. The OOP course at university I attended used Liang’s Introduction to Java Programming. Just like other similar books, it lacks proper structure, and has absolutely no qualms about wasting the student’s time. The exercises were dull, repetitive and uninspiring. Fortunately, there is a free alternative out there that covers all bases, at least as far as introductory courses are concerned. It is Allen B. Downey’s Think Java: How to Think Like a Computer Scientist. In less than 300 (small) pages, you’ll get acquainted with the basics of the language. If you go through this book in a week or two, then a semester-long course on OOP with Java will teach you barely anything new. It will just take five times longer.

Some teachers tell beginning students to start programming in a text editor first, and to compile and execute their code via the command line. In the case of Java, this is seriously misguided advice. You do not want to spend hours looking for a missing curly bracket because you thought you were “hardcore” and turned off syntax highlighting in your editor. Likewise, tasks like compiling and executing your program are simply repetitive time wasters that should be automated. There is no learning experience in saddling yourself with that kind of manual labor. So, instead of an editor use an IDE. Eclipse is as just bloated as Java, and overkill for what you do in your typical first- or second-year CS course. A more lightweight (and free) alternative is DrJava.

Lastly, you’ll want to do plenty of exercises to get proficient at, well, writing code in Java. Unlike some textbook authors I see little point in going through exercises that have you write classes that don’t do anything but make you resent “object orientation” à la Java. After you’ve written a handful of those, you know how this works. Instead, you should practice programmatic thinking. For this purpose, the Java section on CodingBat is an excellent resource, providing a few hundred exercises. They won’t teach you everything you need to learn, but they will put you well ahead of the pack. If you get stuck, you are welcome to consult the solutions on my website.

Lastly, you might want to check out Stanford’s CS106A: Programming Methodology, which is a free online course that offers an introduction to programming with Java. This course and its associated textbook, The Art and Science of Java by Eric Roberts, start out with a special set of Java libraries, the ACM Java Libraries. Those hide some of the complexities of the language. They allow you to write more concise code, and they also lead to a gentle introduction to object-orientation with Java. The course itself is your standard-fare remedial programming course.

The lecturer, Mehran Sahami, is entertaining and competent, and the course focusses on pretty interesting programming tasks. One of the first bigger projects consists of writing a Breakout clone, for instance. Also, I really liked the introductory sequence, which covers “Karel the Robot”. If you’ve never programmed before and have to get started with Java, this would indeed be a very good starting point. Using those resources, you’ll be well on your way to becoming competent in Java, but I hope you’ll explore some other programming languages too.

7 thoughts on “How to Get Started With Java (as a Beginner)

    1. Gregor Ulm Post author

      What is your goal? If you’re looking for some kind of certification that is recognized in the working world, then the exams offered by Oracle are probably a good choice. There are several books available that will specifically prepare you for those.

      Regarding C, I’d recommend you look into some other language first. You will find it much more challenging than Java if you’ve got no previous background.

      The six-week course you linked to looks like a complete waste of money. There is no way you’ll move “from absolute beginners to expert proficiency” in such a short amount of time. Further, the list of topics is staggering. If everything is covered, then it will only happen on a surface level. There is also a lot of nonsense in the syllabus. You won’t write a device driver or design a compiler in a project based on this course. It’s dishonest if not fraudulent to make such a claim. Also, whoever wrote the syllabus seems to know very little about Java. For instance, you don’t teach classes before methods, and you certainly won’t ever pass anything by reference since this is impossible to do so in Java, which only supports passing by value.

      By the way, Udacity is going to offer a free intro to Java course very soon: https://www.udacity.com/course/cs046
      Judging from their high-quality Python-based intro to CS course, it should be well worth your time.

      Reply
  1. Gaius Gracchus

    I have always thought Java was an absolute horror of a language. I really feel alone in my assessment since everyone else seems to think the cycle of creation and deprecation of a language that grows exponentially each year is normal. Picture little oracle elves (used to be sun elves) in a dungeon spinning out new code and standards as fast as they possibly can — new java parts and pieces to hoist on complacent (or in some cases, eager) consumers….

    Java is the absolute antithesis of an elegant, well-designed language/platform.

    Reply
    1. Gregor Ulm Post author

      I wonder how many people were turned off programming permanently because Java was the first language they were exposed to. I find it irresponsible that introductory CS courses are taught in that language since you spend so much time wrestling with Java’s bloated interpretation of OOP and baroque syntax, instead of practicing programmatic thinking. The only people I ever heard saying that they liked Java simply didn’t know any other language (and were not even particularly competent in Java either.) It’s really sad.

      Reply
  2. Fooby

    I wish CS languages were harder to learn and more opaque so that there would be less competition for entry level positions.

    Reply
  3. Wim

    Thank you for your thoughts!

    The link to the Stanford course is dead, this one works:
    see.stanford.edu/Course/CS106A

    Reply
  4. Bob Vo

    I can’t stop reading your fascinating articles in this blog. It’s amazing that you put a thoughtful and critical tone in your article while maintaining entertaining elements to keep readers’ engagements. Also, I went through similar pains during my introductory programming courses with text editors. I wish I read your blog post sooner to avoid these problems. On top of that, your unique experiences as an autodidact shine through all of your writings. Avid autodidact MOOC learner may run into serious problems to complete a course if they don’t have sufficient prerequisites, following dangerous advice or using an inappropriate tool.
    This blog is a treasure for CS self-learners.

    Reply

Leave a Reply to Gaius Gracchus Cancel reply

Your email address will not be published. Required fields are marked *

Spammer prevention; the answer is an integer: * Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.