11 Basic Java Concepts for Beginning Programmers

iD Tech
June 27, 2019

Java is a powerful, multi-platform programming language used for a number of professional and commercial applications—including every Android app and even the Android operating system itself!

With Java, kids can learn to make a tic-tac-toe game with a win algorithm, a top down shooter, or an endless runner!

But what basic concepts should you know about Java coding, specifically? How can kids get started making their own game or application? 

The goal of this post is to get you and your student thinking—does programming with Java sound like something they'd want to explore further?

Of course, after reading through, there will still be some learning holes that need filling. What follows, though, should be more than enough to nudge aspiring coders in the right direction, should they choose to do so. 

Ready?

1. 2D jump physics

 

To simulate gravity, kids can code their own physics!

They can manually check and set the height of a character to simulate a jumping motion, and in order to achieve a smooth jump, they’ll need to keep track of the frames in the game. Sound fun?

2. Win algorithms

A win algorithm can do things like check a board in tic-tac-toe to see who has won.

This can be achieved with a “for loop” and “if statements” (more on each to follow!). 

3. Complex data structures

Can you imagine managing the large music library at Spotify?

With Java, kids can learn how to code a data structure that can hold the queued music on a Spotify playlist!

4. Enemy AI

A basic type of AI in games is one that finds and seeks the player.

To achieve this, coders must get the enemy object and then move it towards the player object.

In addition to randomly spawning enemies in a game, you can also increase the difficulty by upping the spawn rate.

Take a look!

5. Class files

All Java code is contained within class files, so, your child will need to create a class file in their newly-created project.

Important: Class names should be capitalized, and each new word in the title should also be capitalized. The names cannot contain spaces. 

Example of a correctly-named class: “AdventureGame”

6. Main method

Before your child can begin coding, they’ll need to add a method inside of the class, which is the first bit of code that’s called when you run your program. Think of it like a starting point for the rest of the code!

To create a main method in IntelliJ, underneath “public class [ClassName]” your child can type “psvm” and then press the tab button.

(psvm is a shortcut that creates the main method.)

7. Variables

A variable stores information about a program while it's running. 

Example: In an RPG (a type of video game), a character's name, level, and hit points are all stored in their own variable.

Any time your child is playing a game and they level up (or take damage), a variable changes to reflect what happened.

To use a variable, a coder must declare the proper variable type:

Integers: An integer is a type of variable and represents a whole number. For example, -17, 4, 0, and 42 are all integers. You declare an integer in Java using the “int”  keyword.

Doubles: A double is a number that can have a decimal. For example, -12.5, 4.0, 0.001, and 4.2 are all doubles. You declare a double in Java using the “double”  keyword.

Strings: You use a String to store text. For example, "carrot," "apple pie," "pear," and "orange juice" are all Strings. You declare a String in Java by typing  “String” followed by the variable name.

Important: It's considered good practice to declare all variables at the beginning of the code. When everyone codes this way, they know exactly where to look to find them!

8. Order of Operations

Operators perform mathematical calculations while a program is running.

Example: Say, for instance, if a character earns experience, the action needs to be added to the total experience count. If an arrow hits an enemy, the damage it takes needs to be subtracted. 

So, operators are used for whenever a value needs to be changed. 

Multiple operators can be performed at once, and Java arithmetic operators follow the mathematical order of operations

Some basic operators and their order of precedence are listed in the table below.

9. If Statements

An if statement allows coders to execute code if some condition is met.

Example: When a monster is attacked in an RPG, they’ll need to check if that monster has been defeated.

Using if statements, kids can write a program in which they determine if a character is strong enough to slay a dragon.

10. For loops

A for loop runs a section of code repeatedly until a condition is met, like a while loop. However, they use a different syntax and are useful when you're using an array.

Example: In an RPG, a player's inventory could be stored as an array of strings. While exploring a dungeon, they encounter a locked door—a for loop can be used to determine if the player is carrying a key to the door.

11. While loops

The programs explained so far have run in a straight line from start to finish. In an adventure game, once a player makes a choice, there is no way they can turn back and make another choice.

A while loop is code that repeats itself based on a condition.

Example: A while loop can continue to run until monster health is equal to 0. Now, players will continue to descend into the depths of the dungeon until they run out of health!

Ready to put it all together?

With the above basics, you and your kids should have a better idea on whether or not embarking on an adventure into the world of Java programming fits their interests.  

So, next steps? 

One, here is a list of ways to practice Java online

After that, online coding courses and summer coding camps are great options, allowing students to dive into the details en route to building a lifelong passion for tech, like Java, alongside new friends in a pressure-free, creative environment. 

And kids who might thrive in a more personal atmosphere? Java tutoring is available for a 1-on-1 learning experience with curriculum customized to their unique interests and skill level. 

So, again—know of someone who enjoys something like playing Pokémon? Maybe learning how to make a text adventure RPG is in their future. Or, if they are interested in social media, perhaps they can try to recreate an algorithm for different user search functions. 

With hands-on exposure to Java fundamentals and the opportunity to dig deep into programming logic, instruction in any form can help students build the confidence needed to keep learning during summer and long after summer ends.

Meet iD Tech!

Sign up for our emails to learn more about why iD Tech is #1 in STEM education! Be the first to hear about new courses, locations, programs, and partnerships–plus receive exclusive promotions! AI summer camps, coding classes for kids, and more!

By signing up you agree to our Privacy policy
#1 in STEM Education

Meet iD Tech!

Sign up for our emails to learn more about why iD Tech is #1 in STEM education! Be the first to hear about new courses, locations, programs, and partnerships–plus receive exclusive promotions! AI summer camps, coding classes for kids, and more!

By signing up you agree to our Privacy policy

Meet iD Tech!

Sign up for our emails to learn more about why iD Tech is #1 in STEM education! Be the first to hear about new courses, locations, programs, and partnerships–plus receive exclusive promotions! AI summer camps, coding classes for kids, and more!

By signing up you agree to our Privacy policy
#1 in STEM Education

Meet iD Tech!

Sign up for our emails to learn more about why iD Tech is #1 in STEM education! Be the first to hear about new courses, locations, programs, and partnerships–plus receive exclusive promotions! AI summer camps, coding classes for kids, and more!

By signing up you agree to our Privacy policy