Data Types in Java

Submitted by: 
Visitors have accessed this post 146 times.

This tutorial will teach you how to understand what are the variables in java. A data type refers to the type of data that can be stored in a variable, means that a variable needs a data type to save space in the memory for allocation.

So, now let's start this tutorial!

1. Open JCreator or NetBeans and make a java program with a file name of

2. Now, we will initialize variables with their own data types in java.

An int data type contains a whole number. It is 32-bit signed two's complement integer,

  1. int shirtID = 0;

A String data type contains text and numbers.

  1. String description = "-description required-";

A char data type contains only a single character.

  1. char colorCode = 'U';

A double data type contains a decimal value of numbers.

  1. double price = 12.01;

A boolean data type returns only a True or False value.

  1. boolean good = true;

A byte data type contains a small value of integer. It is four times smaller than an int and is used to save space in large arrays.

  1. byte num = 24;

3. To display the declared variables in their different data types, have this code below:

  1. System.out.println("Shirt ID: " + shirtID);
  2. System.out.println("Shirt description:" + description);
  3. System.out.println("Color Code: " + colorCode);
  4. System.out.println("Shirt price: " + price);
  5. System.out.println("Good? " + good);
  6. System.out.println("Number of bytes: " + num);


Here's the full code of this tutorial:

  1. public class variables {
  3. public static void main (String args[]) {
  5. int shirtID = 0;
  6. String description = "-description required-";
  7. char colorCode = 'U';
  8. double price = 12.01;
  9. boolean good = true;
  10. byte num = 24;
  12. System.out.println("Shirt ID: " + shirtID);
  13. System.out.println("Shirt description:" + description);
  14. System.out.println("Color Code: " + colorCode);
  15. System.out.println("Shirt price: " + price);
  16. System.out.println("Good? " + good);
  17. System.out.println("Number of bytes: " + num);
  18. }
  21. }

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook:

Visit and like my page on Facebook at:

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.