Friday 23 March 2018

JAVA PROGRAMMING

How to set path in java programming

Setep1:-- install java application in host machine
Step2:-- Open my computer and go C drive chose all program chose java bin copy
(ctrl+c) path
Step3:- my computer right click goto his properties select advance system seting ok.
Go envorment variables chose new paste selected path jdk/bin (ctrl+v)
%path%; C:\Program Files\Java\jdk1.6.0\bin;.
Step4:-- open command prompt (windows+r type (cmd))
Step5:-- dir java Step6:- open notpad type source code save (niraj.java)
Step7: compile (javac niraj.java) run program (java niraj)

Type casting conversion

It is a concept use in almost all language to assign the value of one type into another type. Java
also supports such future to convert / type cast one type of value into another type of value.

It convert data from one type to another type is also known as type casting conversion.
Two type of type casting in java.

(1) Implicit conversion
(2) Explicit conversion

(1) Implicit Conversion

Implicit conversion refers to an automatic conversion of one data type to another. It
occurs if both the data types are compatible with each other.
For example, you can assign a value of int type to a variable of long data type.
class implicitc
{
                   public static void main(String... args)
                 {
                         int n=100;
                         System.out.println(n);
                         long m=n;
                        System.out.println(m);
                       double p=m;
                       System.out.println(p);
                  }
}

(2) Explicit Conversion

Explicit conversion occurs when one data type cannot be implicitly converted to another
data type. In an explicit conversion, you must convert the data type to the compatible
type.
For example, the int type is large enough to store a byte value. Therefore, it does
not require any explicit conversion. However, assigning an int value to a byte type
would require explicit conversion as the range of the byte type is smaller as compared
to the int type
 You can use the following code to perform type casting of an int number, 259and
a double number, 350.55to byte type:
class TypeCast
{
              public static void main(String arr [])
             {
                   byte b;
                     int i = 259;
                    double d = 350.55;
                    b = (byte) i;
                    System.out.println("Value of int to byte conversion" + b);
                    b = (byte) d;
                        System.out.println("Value of double to byte conversion" + b);
                       i = (int) d;
                     System.out.println("Value of double to int conversion" + i);
                }
}

No comments:

Post a Comment