Loading...
Wednesday, August 29, 2018

Java 10 local variable type inference feature.


Java10DataTypes.java

package com.java9r;

import java.util.Date;

public class Java10DataTypes {

public static void main(String[] args) {

var n= "java9r";// String declaring

var a ='J'; // char declaring character

var i = 90; // int - Integer data type is generally used for numeric values

var b = 0b11001000; // byte - use byte and short if memory is a constraint
var b2 = (byte) 320; //

// byte b1 = 789654258; // this will give error as number is larger than byte range

var s = 58; // short

var s2 = (short)58; // short

// short s1 = 789654258; this will give error as number is larger than short range

var d = 4.789654258; // double - by default fraction value is double in java

var f = 4.7896354f; // float - for float use 'f' as suffix

var l = 3200L; //long for long use 'l' as suffix

var bool=true; // declaring boolean

var date=new Date(); // declaring date

System.out.println("String : " + n);
System.out.println("char : " + a);
System.out.println("integer : " + i);
System.out.println("byte : " + b);
System.out.println("byte 2 : " + b2);
System.out.println("short : " + s);
System.out.println("short 2 : " + s2);
System.out.println("float : " + f);
System.out.println("double : " + d);
System.out.println("long : " + l);
System.out.println("bool : " + bool);
System.out.println("date : " + date);

}

}


Output


String : java9r
char : J
integer : 90
byte : 200
byte 2 : 64
short : 58
short 2 : 58
float : 4.789635
double : 4.789654258
long : 3200
boolean : true
date : Wed Aug 29 11:33:26 PDT 2018

0 comments:

Post a Comment

 
TOP