Java Programming Tutorial 3 - Variables
Tutorial Name: Java Programming Tutorial 3 - Variables
Category: PC Tutorials
Submitted By: Jimbo
Related Forum: PC Building Forum
Jimbo's Java Class - Tutorial 3: Variables
Previous Tutorial: Tutorials/id=23700/java-programmi...-pt-2.html
Hello and welcome to my next Java tutorial. I'm professor Jimbo, an IT student at the University of Central Florida experienced in programming especially Java. In this tutorial I will further discuss the basics of Java programming.
In the previous tutorial I went over what the two lines of code we wrote in tutorial 1 meant. As well as continuing to discuss the basics of Java programming which included comments, keywords, and more.
Since you know the basics of Java it's time to use that knowledge and learn variables. During this tutorial I will discuss what a variable is, what variables are used in Java programming, and then at the end of tutorial you will do a fun exercise.
What is a Variable?
A variable is defined as a value that can change depending on conditions or on information passed to the program.
Types of Variables
Starting out with "int" which stands for integer. Integer data types can hold whole numbers such as 5, 10, 20, 50, 100 as well as negative values. The range of the value is -2,147,483,684 to 2,147,483,647.
Here's a basic program using an integer data type:
To explain what this does is simple. First you declare the data type, which in this case is int. Then give it a name and set it equal to a number between the minimum and maximum. For this example, I chose 5. Lastly, I want it to be printed out to the console. So I wrote out a fancy System.out.println(); and placed the variable inside of it.
What's great is the remaining three integer data types all work similar. This being byte, short, and long. The only difference are the range they can hold. Here's a chart to help you memorize which data type holds how many numbers.
The next two data types are float and double. Both being floating point values they represent numbers with a fractional part. Here's another chart to help:
As for the last two variables we have char and boolean. Both very simple to understand. The variable "char" stands for character and is used when you want to use character constants. For example if you'd want to store the letter 'a' then you would use the char variable. But, char is set up differently than number data types. Here's an example:
As you can see there is a small difference between the two. When declaring char you must wrap the letter with ' '. For example, 'A'.
Finally, we have boolean. Boolean data types are used to store a value that can be either true or false.
So now that you know what each variable is and what they do you'll make a fun program with it.
To show examples of most of them and how they print I declared 5 of them at the top then made them print to the console. Here is the output:
As you can see it added both numberOne and numberTwo as well as numberThree and numberFour. Then it printed out the rest of the variables.
But what is that code at the bottom? That you'll find out in the next tutorial of Jimbo's Java Class. The next tutorial you can expect to learn about if statements and their beauty.
Feel free to PM me here OR message me on the TTG discord.
- 01. MW-HWID Ban: Change UUID and Serial of AMI BIOS Motherboard(240)
- 02. How To Mod Call of Duty Modern Warfare 2019(960)
- 03. 400+ Best Clan Names and Ideas(5,338)
- 04. Valorant Clan Name List - Best Clan Names(1,829)
- 05. Best Fortnite Clan Name Ideas(1,793)
- 06. Installing and Configuring Raspbian on Your Raspberry Pi [20(255)
- 07. How To use system Recovery in Windows 10 PC(445)
- 08. How To Fix Nvidia GeForce Experience Cannot Optimize Games(784)
- 09. Java Programming Tutorial 2 - The Basics Pt. 2(1,067)
- 10. Java Programming Tutorial 1 - The Basics(1,527)
- 11. SLADE3 Tutorial #5 - Bookmark(1,005)
- 12. Windows Basics Tutorial #2 - Navigating Windows(1,061)
- 13. Computer Basics Tutorial #11 - Getting to Know the OS(973)
- 14. Computer Basics Tutorial #8 - Understanding Applications(882)
- 15. Apache Ant Tutorial - Introduction(895)