Saturday 17 March 2018

 Non - Primitive Datatypes



Wrapper Class 

👉 Program 1

class wrap
{
public static void main(String wrp[])
{
//primitive declaration
int p = 100;
System.out.println("primitive datatype = "  +p);

//non-primitive declaration
Integer h = new Integer(100);
System.out.println("non-primitive datatype = "  +h
);

Double d = new Double(2.1756);
System.out.println("non-primitive datatype = "  +d);

Character c = new Character('K');
System.out.println("non-primitive datatype = "  +c);

}


}

Output 


Sunday 11 March 2018



Variables and Datatypes


Write a program to print the values of a variables declared 
    using primitive datatypes:
üboolean
übyte
üshort
üint
ülong
üchar
üfloat
üdouble


Sol.   
 class datatype
{
public static void main(String data[])
{
//primitive datatypes
boolean a = false;
System.out.println("boolean is"+a+"by default");
//here + means concatenation

//byte datatype
byte b = 2;
System.out.println("byte is" +b);

//short datatype
short s = 20;
System.out.println("short is" +s);

//int datatype
int i = 200;
System.out.println("integer is" +i);

//long datatype
long l = 2000;
System.out.println("long is" +l);

//char datatype
char ch = 'A';
//char always declared in single quotes
System.out.println("char is" +ch);

//float datatype
float f = 2000000000f;
//0f means representing float numbers
System.out.println("float is" +f);

//double datatype
double d= 2000000000d;
//0d means representing double numbers
System.out.println("double is" +d);

}
}

Output:



Thursday 8 February 2018

JAVA PROGRAMS

👉 Program below shows the basic difference between Post/Pre increment and decrement :

class unoperator
{
public static void main(String args[])
{
int a = 20;
System.out.println(a++);
System.out.println(a--);
System.out.println(++a);
System.out.println(--a);
}
}

OUTPUT 



Explanation:

The number which we have : 20
now...
                  
                                    (a++) time                                         (a--) time
21 only  in a memory not displaying the output 21 →→→ Now we have 21 that is 

updated value in a memory so it will print 21 and →→ in a memory decrements the number from 21 

                               (++a) time
to 20 →→→Now we have 20 in a memory so it will increment the value and then print the

 incremented value →→from 20 after increment it will print 21 and store this number in a memory  

                                        (--a) time
→→→Now we have 21 in a memory so it will decrement the value and then print the decremented

 value →→from 21 after decrement it will print 20 and store this number in a memory .