java tutorial

java tutorial

Java Data Types

Data Types

In view of the data type of a variable, the working OS distributes memory and chooses what can be put away in the saved memory. In this manner, by allocating distinctive information to variables, you can store numbers, decimals, or characters in these.

Types of data types:

• Primitive Data Type: byte,short,int,char,float,double,boolean

• Reference Data Type: These are created after using defined constructors of the classes to access objects. These variables are declared as a specific type that cannot be changed

Typecasting in java

JAVA typecasting converts one type to another whether it is any class or interface. Both primitive and reference type can be typecasted in JAVA. e.g.,

Base a= new Derived(); //reference variable of Base class points object of Derived class
	Derived b = a; //compile time error, requires casting
	Derived b = (Derived) a; // type casting Base to Derived

Arrays in java

The array is a data structure which stores sequential data elements on a fixed size. To use arrays in programs, a variable to reference must be declared. e.g.,
double[] mynewArray= new double[10];//to declare an array

public class TestArray {

   public static void main(String[] args) {
      double[] mynewArray = {1.9, 2.9, 3.4, 3.5};

      // Print all the array elements
      for (int i = 0; i  largest) largest = mynewArray[i];
      System.out.println("Max is " + largest);  


Leave a Reply

Your email address will not be published. Required fields are marked *