Java is one of the most important of all computer programming languages. But learning Java can seem like a daunting task. Not any longer! With this course you will learn Java step-by-step, from the basics right through to advanced topics. This course is, quite simply, the fastest, easiest way to learn Java programming.
The course instructor Huw Collingbourne has already taught over 22,000 people to program on Udemy. This Java Programming Master Course includes over 85 videos to explain every topic in detail. All the source code is provided in sample programs ready-to-run on a PC or a Mac. And there is even a 125-page eBook, The Little Book Of Java, to provide even more information on all the topics discussed.
If you want to master Java programming quickly and easily, this is course for you.
What you will learn
Who should take the course
First install Java and an IDE (Integrated Development Environment) to help you write programs. This video explains how to do this on a Mac or on Windows.
An overview of the Java language.
Download the Source Code Archive from the Download page of the Resources...
This is the course text – an eBook of 125 pages, which covers the same topics as the video tutorials. Use this book to revise the lessons and study Java in more depth.
A short overview of the NetBeans IDE. Find out how to create Project groups to load and build the projects from the source code archive.
The Java language and the NetBeans Integrated Development Environment (IDE)
In this lesson I’ll show you how to create a simple ‘Hello world’ Java program step-by-step using the NetBeans IDE.
Let’s take a closer look at my ‘Hello world’ program in order to identify some important features of the Java language.
Sometimes you may want to run your programs from the ‘command prompt’ or Terminal. Here I explain some simple ways of doing that on a Mac and on Windows.
It is sometimes useful to pass arguments to a program when it first starts. Here I show how to do this at the commandline or within NetBeans.
Many of the projects in this course will be created as ‘visual’ applications with a windowed user interface. This video explains how to create visual Java programs.
How does your Java code get compiled? And what happens when it is run? Here I explain the basics of the Java compiler and the Java Virtual Machine.
When you want to display text at the system prompt, you will need to be familiar with the print, println and printf methods. Here I explain what these are and how to use them.
When you want to display text in visual components such as text fields and buttons, you need to use special methods such as setText(), as we’ll discover in this lesson.
The basic building-blocks of Java code
By now you should be familiar with the basics of writing, compiling and running simple Java programs. In this step we’ll be find out more about the building blocks of those programs – and here I want to take a first look at data types and variables.
Variables give you a way of storing values that can be changed. But sometimes you want to make sure that certain values cannot be changed. That’s what constants are for.
In this hands-on lesson I show you exactly how I designed and coded my Tax Calculator application. If you are new to NetBeans you might find this step-by-step guide useful.
Packages give you a way of grouping together related classes. Once you create a package you will need to import its contents to other code files. This lesson explains how.
Often you will need to convert numbers to strings and vice versa. Here I explain the difference between numeric and string data types and show how Java can help convert one to the other.
What’s the difference between and int and an Integer or a double and a Double? In this lesson I explain primitive data types and Java’s corresponding ‘wrapper’ classes.
Sometimes it may be useful to tell the Java compiler to treat one data type as another data type – you can do that by ‘type casting’.
Numbers that you enter in your code are ‘numeric literals’ – here I explain how Java treats these.
You don’t always have to convert numbers (and other types of data) to strings – sometimes Java does it for you.
Java provides a shorthand way of converting number primitives into number objects. Here I explain ‘boxing’ and ‘unboxing’.
We use strings all the time in our programs so it’s worth considering what a string actually is.
More core features of Java
Java is an object oriented programming language. What does that mean and why does it matter?
What are classes and how are they used to create objects? That’s the subject of this lesson.
Here we find out how to create a ‘family tree’ of classes in such a way that one or more classes inherit the features of another class.
In this hands-on session I’ll show you, step-by-step, how to create a Java subclass in NetBeans.
Methods are object-oriented functions. Here we look at methods in some detail and I explain method signatures and method overloading.
Sometimes it is useful to call a method without having to create an object first. In this video I explain how to do this using static or ‘class’ methods.
Java's object orientation
Operators are special symbols that are used to do specific operations such as the addition and multiplication of numbers. Here we look at some of the most important operators.
Here I show some examples of using the addition, subtraction, multiplication, division and remainder (modulo) operators.
How do you test if one string is the same as another string? It’s not quite as simple as it may appear.
There are exceptions to the rule that two identical strings compared using == will return false. Here I explain why.
Here I explain how to take different actions by using if, else and else if to perform a series of different tests.
If you need to perform many tests, it is often quicker to write them as ‘switch statements’. This lesson explains how to do that.
In some of the examples in this step, I have used the && operator to mean ‘and’ and the || operator to mean ‘or’. Here I explain these logical operators and the Boolean values they test.
You can combine arithmetic and assignment operations using ‘compound assignment operators’ such as += and -=, as I explain in this lesson.
You can increment and decrement values using the ++ and -- operators. But be careful: when you assign the results of these operations, the value may differ according to the position of the operator!
Operations to change and test values
Many programs need to work with collections of objects. Here we look at the most basic type of collection, a sequential list or ‘array’ of elements.
In Java, the first element of an array is at index 0. It is vital that you understand the importance of this fact, and that is the topic of this lesson.
In this lesson I show a simple way of creating arrays and filling them with data items all in a single line of code.
You can do operations on the items in an array using a ‘for’ loop to handle each item one by one. Here I explain the basics of ‘for’ loops in Java.
Java automatically frees up memory that is no longer needed. This is called garbage collection.
Fixed size arrays may not be the best solution for programs in which lists of objects may grow in size. For such programs, Java’s ArrayList class may be a better choice.
Interfaces are like abstract classes that contain method definitions but omit the code needed to implement the methods. This lesson explains the basics of Java interfaces.
Java ‘Generics’ allow the same methods to operate on objects of various types while giving your code the benefit of type-checking. Here I explain the basics. We’ll look at generics in more depth in Step Nine.
Sometimes it may be useful to index a collection of objects by something other than their numerical positions in a list. Associative arrays, hashes or Maps let you do just that.
If you need to ensure that only keys and values of specific types are permitted to be added to hashes or Maps you can used a typed HashMap.
How to enforce type-checking on list elements
When you want to repeat actions, you may need to ‘loop’ over some blocks of code. Here I take a closer look at for loops to count up and down or iterate through array items.
Here we look at another type of for loop that lets you process the items in a linear collection or array in a similar way to ‘foreach’ loops in other languages.
When you need to loop an unknown number of times, a while loop may be a good choice. A while loop continues to execute as long as some test condition remains true.
Here is an example of how you might use a while loop to read data from files of various sizes stored on your computer’s disk.
Sometimes you may want to be sure that the code in a loop is run at least once. In such a case you might want to use a do..while loop.
You can even create an array containing arrays as its elements. In this lesson I explain the essential feature of multidimensional arrays in Java.
When one array contains ‘nested arrays’ as its elements, how can you get at the elements inside each nested array? That’s the subject of this lesson.
Sometimes you may want to break out of a loop immediately. One way of doing that is by using the break keyword.
Sometimes you may want to break out of a loop once only and then carry on running the loop. One way of doing that is by using the continue keyword.
Using break or continue can change the logic of your code. Here I explain the problem and consider one way of avoiding it.
If you break out of one loop nested inside another loop, which of the two loops do you break from? That’s explained in this lesson.
If you want to break out of both an inner loop and an outer loop you can use labelled breaks. But use with extreme caution or you may regret it!
The art of repetition
You can clarify your code by creating lists of named constants – for example, Hearts, Diamonds, Clubs and Spades in a gambling program. Here I explain how to do that using enums.
Sometimes you may want to give specific values to the constants in an enum. Here I show how I created an int constant in the Directions enum of my adventure game.
In Java, unlike in many other languages, Enums are classes. You can even give them their own methods! This video explains.
I’ve created a project from example code supplied by Oracle. But I can’t understand exactly how it works. Now is a good time to use the NetBeans debugger.
We looked very briefly at Interfaces in Step 6. Interfaces may declare ‘empty’ methods that define a ‘contract’ with the classes that implement the Interface. Here I explain how this works.
There may be occasions when you want to create your own interfaces to be implemented by various different classes. Here I explain how to do that.
Variables in your Java programs are all ‘visible’ within certain limits. Those limits define their ‘scope’.
What happens when a variable name is repeated in different ‘scope’ levels? Let’s find out!
You can restrict the visibility of methods by declaring them using the keywords private, public or protected.
Enumerated types and abstract classes
Generic classes let you work safely with lists of objects of a specified type. Amongst other things, this can help avoid problem that might occur when you add objects of mixed types to a list.
If you want to use an ArrayList which will only accept elements of a certain type – for example, Strings but not Integers – you can do so. That’s what this lesson is about.
Generic ‘type parameters’ are placeholders that can be replaced with real types when you create objects from a generic class.
You can write your own generic classes from which objects can be created to call the same generic methods on different types of data.
Generics are often used to manipulate the elements of lists and other types of collection. Here I explain how to create a custom generic list class.
Sometimes you may want different methods with the same name in ancestor and descendent classes – that’s method overriding.
Sometimes you may want different methods with the same name but different arguments in the same class – that’s method overloading.
Sometimes an error may occur when the program is running. You can deal with many types of error by handling exceptions.
You can ‘catch’ an exception object to access its methods and properties.
Here I explain how to catch specific types of exception.
More on generic collections - and handling errors
Most programs need to write and read data to and from files. That’s this lesson’s topic.
Random-access files let you find data by ‘seeking’ to a specific position.
A stream is a flow of bytes from one place to another. Java lets us save all kinds of data into streams.
Serialization is a powerful technique which lets you save an object data into streams.
Let’s see if we can save all the objects and their links to other objects in my adventure game into a file.
Having saved a network of object data to disk we now need to find a way of restoring that data and recreating the objects.
Saving and loading data
So that’s it. We’ve come to the end of this Java course. Let me wish you success in your future Java programming.
Huw Collingbourne is the technology director at SapphireSteel Software, developers of the “Sapphire” Ruby IDE for Visual Studio and the “Amethyst” IDE for the Adobe Flash Platform. He is author of The Book Of Ruby from No Starch Press. He runs Bitwise Courses and teaches courses on a range of programming topics.
Huw has been a programmer for more than 30 years. He is a well-known technology writer in the UK. For over ten years he wrote the Delphi and Java programming column for PC Plus Magazine. He has also written numerous opinion and programming columns (including tutorials on C#, Smalltalk, ActionScript and Ruby) for a number of computer magazines, such as Computer Shopper, Flash & Flex Developer’s Magazine, PC Pro, and PC Plus. He is the author of the free ebook The Little Book of Ruby and is the editor of the online computing magazine Bitwise.
In the 1980s he was a pop music journalist and interviewed most of the New Romantic stars, such as Duran Duran, Spandau Ballet, Adam Ant, Boy George, and Depeche Mode. He is now writing a series of New Romantic murder mysteries.
At various times Huw has been a magazine publisher, editor, and TV broadcaster. He has an MA in English from the University of Cambridge and holds a 2nd dan black belt in aikido, a martial art which he teaches in North Devon, UK. The aikido comes in useful when trying (usually unsuccessfully) to keep his Pyrenean Mountain Dogs under some semblance of control.