Tuesday, 20 May 2014

Java Operator Questions


What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int i=5,j;
        j=i++ + ++i;
        System.out.println("i="+i);
        System.out.println("j="+j);
    }
}


What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int i=5,j;
        j=i++ + ++i;
        System.out.println("i="+i);
        System.out.println("j="+j);
    }
}

What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int i=5,j;
        j=i + i++ + ++i;
        System.out.println("i="+i);
        System.out.println("j="+j);
    }
}

What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int i=5,j;
        j=i++ + i + ++i;
        System.out.println("i="+i);
        System.out.println("j="+j);
    }
}

What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int i=5,j;
        j=i++ + ++i + i;
        System.out.println("i="+i);
        System.out.println("j="+j);
    }
}

What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        double d=10;
        d=d<<2;
        System.out.println(d);
    }
}

What is the output of the following program?
lass Operators1
{
    public static void main(String[] args)
    {
        byte a=10;
        System.out.println(~a);

    }
}
What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        byte a=-20;
        System.out.println(~a);

    }
}


What is the output of the following program?
class BitWiseOps
{
    public static void main(String[] args)
    {
        int a=3, b=6;
        System.out.println((a|b) +" "+ (a&b) +" "+ (a^b));
    }
}
What is the output of the following program?
lass Operators1
{
    public static void main(String[] args)
    {
        int a=3, b=6;
    System.out.println((~a&b)|(a&~b));     
    }
}
What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int a=10, b=0;
        if( a > 10 && a/b == 10)
            System.out.println("Inside the If Condition!");
        System.out.println("Outside the If Condition!");
    }
}


What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int a=10, b=0;
        if( a == 10 && a/b == 10)
            System.out.println("Inside the If Condition!");
        System.out.println("Outside the If Condition!");
    }
}





What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int a=10, b=0;
        if( a <= 10 || a/b == 10)
            System.out.println("Inside the If Condition!");
        System.out.println("Outside the If Condition!");
    }
}
What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int a=10, b=0;
        if( a < 10 || a/b == 10)
            System.out.println("Inside the If Condition!");s
        System.out.println("Outside the If Condition!");
    }
}

Java Interview Operator Questions



What is the output of the following program?
class Operators1
{
    public static void main(String[] args)  
  {
        int i=0;
        System.out.println(i++);
        System.out.println(i);
        System.out.println(++i);
    }
}

A.
0 0 1

B.
0 1 2

C.
1 1 1

D.
1 1 2

E.
Compilation Error


What is the output of the following program?
class Operators2
{
    public static void main(String[] args)
    {
        int i=0;
        System.out.println(i--);
        System.out.println(i);
        System.out.println(--i);
    }
}

A.
0 0 -1

B.
0 -1 -2

C.
-1 -1 -2

D.
-1 -1 -1

E.
Compilation Error



What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int i=0;
        System.out.println("i--="+i--+" , --i="+ --i);
    }
}

A.
i-- = 0, --i=-2

B.
i-- = -1, --i= -1

C.
i-- = -1, --i =-2

D.
None of the Above


What is the output of the following program?
class ModulusOperators1
{
    public static void main(String[] args)
    {
        float f=7.5f;
        System.out.println("7.5 % 2 ="+ f%2);
    }
}

A.
1

B.
Compilation Error: Modulus operator can not be applied on Floating Point Numbers

C.
1.5

D.
None of the Above



What is the output of the following program?
class ModulusOperators1
{
    public static void main(String[] args)
    {
        System.out.println("-8%3="+ -8%3);
        System.out.println("10%-3="+ 10%-3);
        System.out.println("-7%-3="+ -7%-3);
    }
}

A.
2 -1 -1

B.
-2 -1 1

C.
-2 1 -1

D.
-2 1 1
















Access attributes in component

NOTE: To access an attribute in a  component , use expressions as  {! v.<Attribute Name>} . ----------------------------------------...