Java is more than another name for coffee, it’s also one of the most popular programming languages! In this Java tutorial for beginners, we’ll uncover everything you need to know to get started with Java: what is Java, how hard is Java, a basic tutorial, and future recommendations.

Java overview

Java is a modern text based programming language. According to an article from Northeastern University, Java is the 3rd most popular programming today. Java has been around since 1995 and is most famously used in Android apps, the Minecraft desktop version, and behind the scenes code in websites and databases. Java is also the language of choice for AP Computer Science, a high school programming class that is considered equivalent to a first semester college programming class. Java is well liked because Java code can run on many types of devices and its strong community of developers.

Is Java easy or hard for a beginner?

Java is great for beginners, and in fact it is many people’s first programming language. Java is an easy language to learn, especially for kids in fifth grade and above. With that said it is recommended that students are comfortable with keyboard typing and have experience with any kind of programming before trying out Java. Python is also a great beginner text based programming language and has less strict rules than Java, check out Create & Learn’s Python guide here.

Java notes for beginners

Just like how writing sentences in English has rules, writing code in Java also has rules. Here’s some notes to keep in mind:

  • Java is case sensitive: capital letters and lowercase letters make a difference!
  • Spelling matters!
  • Punctuation matters! Almost all lines end in a semicolon (;), also pay attention to parenthesis () and curly brackets {}

All Java files are “classes” and all Java programs, which could contain multiple files, have one main method. The main method is the first code that is executed.

Get started with a fun Java tutorial for beginners

In this tutorial, we will create a simple “chat bot” like program. This program will output some text, the user can respond to it, and the program can give a custom response.

1. Let’s first create an account.

First, create an account on Replit, a web based programming environment. Replit is completely free and secure. You can create an account by signing in with your Google account or simply input a username, email, and password.

2. Create Repl.

Once you create your account, click on the “Create” button with the plus sign underneath your username:

Create Repl for Java

In the popup, search for the “Java” template, title your Repl anything you want, and click “Create Repl.”

Repl for Java for beginners

3. Get to know the interface.

You should now see an interface that looks like this. All our coding will be done in the middle panel. You can already see the “Main” class and main method. The right side shows the output of our program. We can run our program by clicking on the green “Run” button at the top middle of the screen. If you run the starter code, it will output “Hello world!” onto the screen. System.out.println is how we output text.

Java interface

4. Make a first question.

Let’s change “Hello world!” into a first question:

Make a question in Java

5. Add a response.

Let’s now add a way to respond to this question. We’re going to import the Scanner. Importing means we’re going to add someone else’s already written code into our program. In this case, we’re adding the Scanner, which will allow us to record keyboard input.

Add a response in Java

6. Create a new Scanner.

Let’s now use this Scanner. We’re going to create a new Scanner that listens to our system’s input (the keyboard) and save it as a variable called “sc”.
Unlike Python or Javascript, the data type for Java variables is required. The Scanner variable is of type “Scanner.”

Create a new scanner in Java

7. Record as a String variable.

We’re now going to record what we typed in as a String variable. The “String” data type represents text in Java. We’ll call this String variable “answer” and set it to the next line the scanner reads.

Make a string variable in Java

8. Try running your program.

It may take up to 10 seconds for the program to load. You should be able to type into the right side. Once you’re done typing, press “Enter” key (also called the “Return” key).

Run your Java program

9. Print out a greeting.

Let’s use this answer in a response. We can add strings and variables together using the plus sign. Let’s print out a greeting plus the answer variable.

Print out a greeting in Java

You should be able to run your code and see this output, of course with “Brandon” replaced with your name:

Online Java tutorial for kids

10. Let’s add some more customization.

Let’s make our program print a special message for a certain response. We can use “if” to see if the answer variable is equal to a certain string. We have to use “.equals()” to check if two strings are the same. After our if statement, there are curly braces. The code inside the curly braces will get run if the if statement is true. Of course change the special string from “Brandon” to whatever your name is!

Customize your Java chatbot

Inside of the curly braces, let’s add a special message.

Add a name

Run your code!

First, type in the name you typed in inside the .equals parenthesis: And then type a different name:

Run your code

Notice how “Brandon” prints “Cool name” but “Landon” does not!

See how it works

From here add more to your chat bot! Add more questions, riddles, or jokes. The possibilities are endless.

How can I teach myself more Java?

There is so much more to learn with Java. The best place to start would be Create & Learn’s Java Primer with Android course. In a semi-private class environment, we start with the basics and eventually learn how to create native Android apps with Android studio. Other beginner friendly free resources include CodeAcademy’s Java course and W3Schools Java guide.

In case you had trouble with this tutorial perhaps try Python or even Scratch first. Here’s a great starter tutorial for Python and here’s a great starter tutorial for Scratch.

Screen-Shot-2021-10-11-at-1.33.09-PM

Written by Brandon Lim, a Create & Learn instructor and curriculum developer. Brandon also works full-time as a software engineer and holds a BS in Computer Science from Johns Hopkins University. Brandon has experience teaching coding to students of all ages from elementary school to college and is excited to share his deep knowledge and relentless passion for coding with the next generation of technology leaders.