Data Types in Java

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 variables.java. 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);
Output: output Here's the full code of this tutorial:
  1. public class variables {
  2.  
  3.    public static void main (String args[]) {
  4.        
  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;
  11.        
  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.    }
  19.      
  20.    
  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: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment