Tutorials Navigation
Java Programming Tutorial 3 - Variables
Tutorial Name: Java Programming Tutorial 3 - Variables
Category: PC Tutorials
Submitted By: Jimbo
Date Added:
Comments: 1
Views: 2,037
Related Forum: PC Building Forum
Share:
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.
Summary
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.
Getting Started
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.
Variables
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
int
short
long
float
double
char
boolean
Examples
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:
[ Register or Signin to view external links. ]
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.
[ Register or Signin to view external links. ]
source: [ Register or Signin to view external links. ]
Moving on..
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:
[ Register or Signin to view external links. ]
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:
[ Register or Signin to view external links. ]
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.
Final Example
So now that you know what each variable is and what they do you'll make a fun program with it.
[ Register or Signin to view external links. ]
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:
[ Register or Signin to view external links. ]
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.
Conclusion
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.
Questions?
Feel free to PM me here OR message me on the TTG discord.
Ratings
Comments
Related Tutorials
- 01. Emulating Xbox 360 on PC for Running COD4 With Mods(3,492)
- 02. How to: Matrix Numbers | Batch File(1,903)
- 03. How to Password Protect Files on Windows(857)
- 04. How to play Socom 2/3/ and Combined Assault on PC(6,705)
- 05. Modern Warfare 2 Vac Ban Bypass Tutorial(6,133)
- 06. How to embed an image on TheTechGame(3,098)
- 07. [PC] NIOH 2 OTHER USER SAVE RESIGN(12,981)
- 08. Host bot lobbies! Full Tutorial!(11,241)
- 09. Unban yourself [Plutonium BO2](14,240)
- 10. Fall Guys - How to Change Your Name Color on Fall Guys(8,385)
- 11. Best Crosshair Settings for Valorant(6,525)
- 12. Othercide The Surgeon Boss Guide(2,539)
- 13. Othercide Remembrances Unlock Guide(4,460)
- 14. Othercide Beginners Tips and Tricks(2,708)
- 15. How to Fix Grounded Crashes, Loading Time, Low FPS and Other(4,843)
"Java Programming Tutorial 3 - Variables" :: Login/Create an Account :: 1 comment