Monday 28 September 2015

Java Tutorial : Java Variable Type Conversion && Type Casting


Click here to watch in Youtube :
https://www.youtube.com/watch?v=5Qa40NrzajQ&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Variable Type Conversion && Type Casting 
Java Tutorial : Java Variable Type Conversion && Type Casting 
Java Tutorial : Java Variable Type Conversion && Type Casting 
Java Tutorial : Java Variable Type Conversion && Type Casting 

TypeConversionDemo.java
public class TypeConversionDemo
{

    public static void main(String[] args)
    {
        double doubleVariable;
        long longVariable;
        int intVariable = 10;

        /*
         * Variable of smaller capacity is be assigned to another variable of
         * bigger capacity.
         */
        longVariable = intVariable;
        doubleVariable = intVariable;

        System.out.println("longVariable : " + longVariable);
        System.out.println("doubleVariable : " + doubleVariable);

    }

}

Output
longVariable : 10
doubleVariable : 10.0
TypeCastDemo.java
public class TypeCastDemo
{

    public static void main(String[] args)
    {
        double doubleVariable = 2898.9999;
        long longVariable = 199;
        int intVariable;

        /*
         * Variable of larger capacity is be assigned to another variable of
         * smaller capacity.
         */
        intVariable = (int) longVariable;

        System.out.println("longVariable " + longVariable
                + " converted to intVariable : " + intVariable);

        intVariable = (int) doubleVariable;

        System.out.println("doubleVariable " + doubleVariable
                + " converted to intVariable : " + intVariable);

    }
}
Output
longVariable 199 converted to intVariable : 199
doubleVariable 2898.9999 converted to intVariable : 2898
To Download VariableDemoTypeConversionAndCastingApp Project Click the below link
https://sites.google.com/site/javaee4321/java/VariableDemoTypeConversionAndCastingApp.zip?attredirects=0&d=1

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • 1 comment: