Java For Absolute Beginners: Lesson 1: Different Data Types
triple-catch

Java For Absolute Beginners: Lesson 1: Different Data Types

Hello visitor! This is a tutorial I made for people who want to learn Java. In this tutorial, you will learn about different data types in Java. If you go on to enjoy these tutorials, I will edit this post and link new lessons that I make. Please let me know how I can improve these and if you have any questions, I will try my best to answer them (I'm not a Java pro 😀).

A Few Things About Java That You Should Know Before We Get Started

  • Basically all lines of code end with a semicolon.
  • Java is case sensitive, so make sure that certain words are capitalized and not capitalized, make sure not to add spaces in case sensitive places, and more!

Different Data Types

If you know any other programming language, you probably know these data types already. Data types or also known as variables. A variable is basically something that you can store some sort of data in, and there are different types of variables, hence the idea of "data types".

The five different data types in Java are:

  • Strings
  • Chars
  • Integers
  • Doubles
  • Booleans

All of these data types are used to store different types of data, so let's go into detail on how to declare these different variables and what they are used to store!

Strings

Strings are the first type of variables we are going to talk about! Strings are used to store multiple words. For example, if I wanted to store a greeting message that would be deployed whenever a user joined, you could store that message in a String variable.
An important thing you should know is that strings are always stored in double quotation marks (“”).

Steps to declaring a String:
1. Type the word “String” and make sure to have a capital S.
2. Put a space and type the name of your variable (it can be whatever you want it to be).
3. Put an equal sign and then put double quotation marks after the equal sign.
4. Type whatever you want in the double quotation signs.
5. Put a semicolon after the whole line and then you are done!

This is what that would look like:

String greeting = “Hello there visitor!”;
Remember, you can only use double quotation marks because single quotation marks are used for something else.

Chars

Chars are the second type of variables we are going to talk about. Chars are used to store a single character. For example, if I wanted to store the grade that a student got like an A, I could store it in a char variable.
An important thing you should know is that chars are always stored in single quotation marks (‘’).

Steps To Declaring a String:
1. Type the word “char” and make sure to have a lowercase c.
2. Put a space and type the name of your variable (it can be whatever you want it to be).
3. Put an equal sign and then put single quotation marks after the equal sign.
4. Type whatever you want in the single quotation signs.
5. Put a semicolon after the whole line and then you are done!

This is what that would look like:
char grade = ‘A’;
Remember to use single quotation marks, not double quotation marks because double quotation marks are used for strings!

Integers

Integers are the third type of variable we are going to talk about! Integers are used to store whole numbers. For example, if I wanted to store my age in a variable, I could store it in an int variable.
Integers are not stored in single or double quotations. There are no quotations used for integers.

Steps To Declaring a Integer:
1. Type the word “int” and make sure to have a lowercase i.
2. Put a space and type the name of your variable (it can be whatever you want it to be).
3. Put an equal sign after the name of your variable.
4. Type any whole number.
5. Put a semicolon after the whole line and then you are done!

This is what that would look like:
int age = 15;
Remember, there are no single or double quotation marks.

Doubles

Doubles are the fourth type of variable we are going to talk about! Doubles are used to store numbers that have decimals. For example, if I wanted to store my precise age (15 and a half years), I could store it in a double variable.
Doubles are not stored in single or double quotations, just like integers.

Steps To Declaring a Double:
1. Type the word “double” and make sure to have a lowercase d.
2. Put a space and type the name of your variable (it can be whatever you want it to be).
3. Put an equal sign after the name of your variable.
4. Type any number that has a decimal.
5. Put a semicolon after the whole line and then you are done!

This is what that would look like:
double preciseAge = 15.5
Remember, there are no single or double quotation marks.

Booleans

Booleans are the fifth type of variable we are going to talk about! Booleans are used to store either true or false. For example, if I wanted a variable that would keep track of whether a button was pressed, I could store that in a booolean.

Steps To Declaring a Boolean:
1. Type the word “boolean” and make sure to have a lowercase b
2. Put a space and type the name of your variable (it can be whatever you want it to be).
3. Put an equal sign after the name of your variable.
4. Either type true or false with a lowercase letter at the beginning.
5. Put a semicolon after the whole line and then you are done!

This is what that would look like:
boolean buttonPressed = true;
Remember, in a boolean, there is only true and false!

Printing Things Onto The Console

This does not have anything to do with data types, but this is important to know.
If you want to print something out onto the console, use the line System.out.println(“Blah blah blah”);. You can print variables as well using these as long as you get rid of the quotation marks. You can combine different things using string concatenation. This is basically when you combine different strings and variables and print them together. For example, if I wanted to print my age without just typing it manually, I can use this line of code:
int age = 15; System.out.println(“My age is ” + age);
As you can see, I used a plus sign to display two different things next to each other on the console! Make sure to put a space after a sentence if you are putting variables next too words like I did in the example above.
Another way you can print things is by using System.out.print(“Blah blah blah”); The difference is that the end now says .print instead of .println.This does the same job but however, whenever you have multiple print statements, instead of putting each one on a separate line when displayed on the console, all of the print statements are mushed onto one line.

That is all for this tutorial! I will release lesson 2 soon and will link it on here whenever I post it! If you found this helpful and if you have any questions, let me know in the comments! I am open to any constructive feedback!

Link to lesson 2: not available yet!

Thank you for following this tutorial!

You are viewing a single comment. View All
techde

Wow awesome tutorial! Very nice use of markdown, and concepts are great, I might even start
coding in java with the help of this tut, very nice!

triple-catch

@techde
Thanks a lot! This took me a while to make :)

techde

@26arajesh Makes sense lots of work went into this clearly!

triple-catch

@techde
Yup! Thanks for the support. BTW, if you have any feedback, feel free to let me know!

techde

@26arajesh I have no experience in java so this looks great to me, if your looking for good feedback ask someone like @Coder100

triple-catch

@techde
Ok, good to know! Thanks for telling me!

techde