Our biggest SALE yet. Get up to 96% off.

↓ The first 1000 to enroll get up to 96% off. ↓

Learn how to make 20 games in GameMaker.

✔ make games including: shooter, rollerball, platformer, platform shooter, cross shooter, turret, color shooter, color matcher, apple catcher, dodger, collector, double shooter, side scrolling shooter, balloon burst, penalty, flappy bird, double jumper, ricochet shooter, ship dodger, jumper, and gravity switch.
✔ get introduced to coding
✔ get 96% off

The Complete Java and Android Studio Course for Beginners

✔ learn the fundamentals of coding: variables, statements, functions
✔ build different apps, including calculators, games, and maps
✔ get 94% off

Build “The Legend of Zenda” in Unity3D and Blender.

✔ learn Unity, Blender, and C#
✔ design characters, weapons, and enemies
✔ draw video game levels
✔ get 96% off

Ultimate TVOS Guide for Beginners. Learn to code in Swift 3.

✔ be able to code in Apple’s programming language
✔ navigate the Xcode interface
✔ make a Quiz app, a Dialogue Tree app, and an Interactive Story app
✔ get 96% off

Some of the code you'll build.

Make a Ninja Survival game in Unity and Blender.

✔ learn Unity, Blender, and C#
✔ set up and code a fully functioning game from scratch
✔ draw ninjas, enemies, and other art assets
✔ get 96% off

Learn how to make a Super Marlo Run game.

✔ learn Unity, Blender, and C#
✔ make speed blocks and enemies
✔ design the background and interface
✔ get 96% off

Introduction to Java Class Constructors: Android Studio Crash Course (Free Tutorial)

Picture this: you have a user that wants to specify the details of a product. Today we’re going to be looking at a user who inputs the make, model, and manufacturing year of their car, and we want Java to display the inputs as a message.

If you want to learn more coding for FREE, check out our 30-minute beginners course here: training.mammothinteractive.com/p/learn-to-code-in-30-minutes

When an object is created, Java first executes the code in the constructor. The constructor will then invoke that object. In this example, we’ll look at both default and customized constructors in a Java class. So let’s create a class! To follow along in Android Studio, go into Project view. Then go to app > java. Right-click on the topmost com.example.zebra.demo. Select New > Java Class.

The tab “Create New Class” will pop up. Let’s name our class “Car”. You should see the following on your screen:

public class Car {

}

As you can see, we have created our new class. It will also appear in Project view inside the same folder that contains the MainActivity class.

Before we create constructors, we have to instantiate a couple of fields. In the public class Car, let’s declare some fields. Note that, unlike in this example, these fields are usually private, meaning that they can only be accessed in this class. In your public class, create two public strings named make and model. Also create a public integer variable for the year in which the car was manufactured. Name it yearManufactured. Note that each of these lines must end in a semi-colon.

public class Car {
public String make;
public String model;
public int yearManufactured;
}

Now that we have created some properties for the car object, we have to create a constructor. First let’s trying using a default constructor. Note that a constructor takes the same name as its class. Still within the public class, type the following:

//default constructor
public Car (){

}

Instantiate the fields by adding onto the constructor so it looks like this:

//default constructor
public Car (){
this.make = "";
this.model = "";
this.yearManufactured = 2000;
}

For string variables, we usually put "", signifying empty strings. For integer variables, we usually use 0. In this example, we used 2000 because it’s a much more appropriate default value for the year in which a car was manufactured.

Next go to app > java > (topmost) com.example.zebra.demo > MainActivity. Beneath setContentView(R.layout.activity_main);, create a new object called myCar. Use the default constructor Car:

Car myCar = new Car();

We also want to display a message on the screen. To set the message, on the next line, create the string message, and set it equal to the properties that we created in the Car class.

String message = "Make: " + myCar.make +
"\nModel: " + myCar.model +
"\nYear manufactured: " + myCar.yearManufactured;

Note that because we added \n to the last two lines, our message will be displayed on three separate lines.

To display our message, we can use the Toast utility in Android Studio. On the next line, type in “Toast”, select “Create a new Toast”, and hit Enter. Android Studio will auto-complete the following code:

Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show();

To specify the message we want to display, edit that code so it looks like this:

Toast.makeText(MainActivity.this, "Brand of my car: " + myVehicle.getBrand() + " Conversion rate between KM and MILES: " + Vehicle.KILOMETERS_TO_MILES, Toast.LENGTH_SHORT).show();

Run the emulator, and zoom in. Because we used the default constructor, you will see that the defaults we created will be shown on the screen:

Make:
Model:
Year manufactured: 2000

There are no values for the make or model of the car since we didn’t specify their values when we created the Car class. So let’s specify their values, shall we? To do so, we must create a customized constructor back in the Car.java tab.

Below the default constructor, add a customized one:

//customized constructor
public Car(){

}

The only difference between the default constructor and the customized constructor is that we can pass some parameters in the parentheses of the customized constructor. Let’s add these parameters into the parentheses: String make, String model, int yearManufactured.

These are the parameters that the users of our application will input. For instance, a user will specify the make of a car, such as Honda, then the model, such as Civic, and the year manufactured, such as 2013. Since these are specific values, we have to make sure that our fields store these values. In the customized constructor, type the following lines:

this.make = make;
this.model = model;
this.yearManufactured = yearManufactured;

This code means that your field that stores, for example, the make is equal to the make that the user inputs in the initialization of the object that we just specified in the parentheses.

Let’s see how this customized constructor works. Instead of having the Car instantiate the constructor without any parameters, we’ll specify for the make, model, and manufacturing year of a car. In the parentheses after Car myCar = new Car, type: "Honda", "Civic", 2013.

If you run the emulator, you will see the following:

Make: Honda
Model: Civic
Year manufactured: 2013

All done! Now we’re able to store specific values inside fields. If you want to learn even more coding for FREE, check out our 30-minute beginners course here: training.mammothinteractive.com/p/learn-to-code-in-30-minutes

Introduction to Java Static Variables: Android Studio Crash Course (Free Tutorial)

Ready to master Java? Today’s topic is static variables. Static variables extend across the entire run of a program. In this article, you’ll learn how to create static variables in Android Studio with Java.

If you need an introduction to coding and want to learn for FREE, check out our 30-minute beginners course here: training.mammothinteractive.com/p/learn-to-code-in-30-minutes

A static variable is associated with a class rather than a specific object. So let’s create a class! To follow along with this example in Android Studio, go into Project view. Then go to app > java. Right-click on the topmost com.example.zebra.demo. Select New > Java Class.

The tab “Create New Class” will pop up. Let’s name our class “Vehicle”. Follow this format:

public class Vehicle {

}

As you can see, we have created a new class called Vehicle. Next we shall set up some fields. On a line within the curly brackets of the public class, let’s declare a string brand.

private String brand;

Note that we made this field private, meaning that we can access the variable only inside this Vehicle class.

Furthermore, let’s declare a variable for the conversion rate from kilometers to miles, which is 0.621371.

public static final double KILOMETERS_TO_MILES = 0.621371

First off, the name of our variable is KILOMETERS_TO_MILES, and its value is 0.621371. We used several keywords to specify the type of variable:

  • public is used because the static variable has to be used throughout our project.
  • static is used because our conversion rate applies to all the vehicles. The rate is not specific to a certain vehicle, such as a Honda or Toyota.
  • final is used because the conversion rate is a constant that won’t change throughout the project.
  • double is used because our conversion rate has decimal places. A variable of the data type double can contain decimals.

Now we have to create a constructor for our class. Constructors are run whenever objects are created. On a new line, type in:

public Vehicle(){

}

Within the parentheses, set up the parameter String brand. As well, within the curly brackets, say:

this.brand = brand;

This means that our input field brand is equal to the value of the parameter brand.

To make sure we can retrieve brand, create a getter by coding:

public String getBrand(){
return this.brand
}

This is called the getter method because it “gets” the private field. We can’t access the private field String brand otherwise.

Now that we have created the constructor, go to app > java > (topmost) com.example.zebra.demo > MainActivity. Beneath setContentView(R.layout.activity_main);, create a new Vehicle called myVehicle. Give it the value Toyota:

Vehicle myVehicle = new Vehicle("Toyota");

We just created a variable! We also want to display a message on the screen. For this to happen, on a new line, type in “Toast”, select “Create a new Toast”, and hit Enter. Android Studio will auto-complete the following code:

Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show();

To specify the message we want to display, edit that code so it looks like this:

Toast.makeText(MainActivity.this, "Brand of my car: " + myVehicle.getBrand() + " Conversion rate between KM and MILES: " + Vehicle.KILOMETERS_TO_MILES, Toast.LENGTH_SHORT).show();

Note the difference between myVehicle.getBrand() and Vehicle. myVehicle is used because getBrand applies to a specific vehicle. When attaching the variable for the conversion rate, Vehicle is used because the conversion rate applies to all vehicles.

Run the emulator and zoom in. You should see the message “Brand of my car: Toyota Conversion rate between KM and MILES: 0.621371”.

If you want to learn even more coding for FREE, check out our 30-minute beginners course here: training.mammothinteractive.com/p/learn-to-code-in-30-minutes

Introduction to Strings Java: Android Studio Crash Course (Free Tutorial)

Are you stuck trying to display a message in your program? This is the article for you. Today we’ll be showing you how to use string variables in Java in Android Studio.

If you need an introduction to coding and want to learn for FREE, check out our 30-minute beginners course here: training.mammothinteractive.com/p/learn-to-code-in-30-minutes

To follow along with this example in Android Studio, go into Project view. Then go to app > java > (topmost) com.example.zebra.demo > MainActivity.

On a line underneath setContentView(R.layout.activity_main);, let’s declare our first string variables. Use the keyword String to do so. Then let’s declare three strings and name them firstName, lastNamename, and name.

String firstName, lastName, name;

Give firstName the value Mammoth and lastName the value Interactive. The following format is used to do so:

String firstName = "Mammoth", lastName = "Interactive", name;

For the value of name, concatenate (combine) the first two strings. Also, because we want to have a space between the words “Mammoth” and “Interactive”, add a space in quotation marks between the two strings in the concatenation. Your line of code should look like so:

String firstName = "Mammoth", lastName = "Interactive", name = firstName + " " + lastName;

To have our string actually appear on the screen, we will need to use the Toast utility. Below your strings, type in the following code:

Toast.makeText().show();

Within the parentheses of this code, we can set some parameters. In the parentheses after Toast.makeText, type in the following:

this, "The string " + name + " has " + name.length() + " characters.", Toast.LENGTH_LONG

Thus the message that shows up will tell us of how many characters our strings is made up. Toast.LENGTH_LONG means the message be displayed for a couple of seconds.

To test the code, run the emulator, and zoom in. You will see the message “The string Mammoth Interactive has 18 characters.”

That is how you use strings in Android Studio! You will now be able to provide messages for the users of your applications. For more FREE tutorials, check out our 30-minute intro course on coding: training.mammothinteractive.com/p/learn-to-code-in-30-minutes

Introduction to Nested If Statements: Android Studio Crash Course (Free Tutorial)

Is your code cluttered? You know what they say: tidy code, tidy mind! With this article, you’ll learn how to simplify your code. Specifically, we’re going to compare two ways of checking the value of an integer: using several if statements vs using one if statement.

If you need an introduction to coding and want to learn for FREE, check out our 30-minute beginners course here: training.mammothinteractive.com/p/learn-to-code-in-30-minutes

To follow along with this example in Android Studio, go into Project view. Then go to app > java > (topmost) com.example.zebra.demo > MainActivity.

Firstly we have to set up some variables. On a line underneath setContentView(R.layout.activity_main);, declare an integer number, and set it equal to 98.

int number = 98;

Below that, declare the string message, and set it equal to "This number is ". This is part of the message that we want to display on the screen.

String message = "This number is ";

Next create an if statement:

if(){

}

Within this if statement, we’ll be checking if our integer is greater than 95. In the parentheses, write number > 95.

As well, we need to code the other part of the message that will be displayed on the screen if our number is greater than 95. Within the curly brackets of the if statement, let’s add the following:

message += " greater than 95";

Still within the if statement, let’s build another if statement. We’ll use this nested if statement to check if our integer is less than 100.

if(number < 100){

}

If our integer is less than 100, let’s have the message “This number is greater than 95 and lower than 100.” appear. For this to happen, add the following line within the curly brackets of your second if statement:

message += " less than 100.";

To have our message actually appear on the screen, we will need to use the Toast utility. Below your if statements, type in “Toast”, select “Create a new Toast”, and hit Enter. Android Studio will auto-complete this code:

Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show();

Within the parentheses of this code are the parameters. Change the quotation marks to message.

If you run the emulator and zoom in, you will see the text “This number is greater than 95 and less than 100.” appear on the screen, exactly as expected.

But there’s a faster way of doing this operation without using the nested if statement. Cut number < 100 from your nested if statement, and place it into the parentheses of the first if statement. Use the AND operator (&&) to separate the two parameters in the parentheses:

if(number > 95 && number < 100){
message += " greater than 95";
}

Also add and is less than 100. after greater than 95. Now you can delete the nested if statement. As such, with only one if statement, we can check if our integer is between 95 and 100!

Run the emulator again to see the same message appear on the screen. Although most of the time you will need if statements, you were able to write this program in fewer lines of code that are easier to understand.

For more FREE tutorials, check out our 30-minute intro course on coding: training.mammothinteractive.com/p/learn-to-code-in-30-minutes