Java code
This program generates the following output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Demonstrate a two-dimensional array. class TwoDArray { public static void main(String args[]) { int twoD[][]= new int[4][5]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<5; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } } }
Operator Result ~ Bitwise unar y NOT & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR >> Shift right >>> Shift right zero fill << Shift left &= Bitwise AND assignment |= Bitwise OR assignment ^= Bitwise exclusive OR assignment >>= Shift right assignment >>>= Shift right zero fill assignment <<= Shift left assignment
The Bitwise Operators Java defines several bitwise operators that can be applied to the integer types, long, int, short, char, and byte. These operators act upon the individual bits of their operands. They are summarized in the following table:
True
All Java objects reside on the heap; there are no objects stored on the stack. Storing objects on the heap does not cause potential memory leakage problems because of garbage collection. (True/False)
int a; // defines an integer int[] b; // defines a reference to array of ints Vector v; // reference to a Vector object
Declarations A Java variable may refer to an object, an array, or an item of primitive type. Variables are defined using the following simple syntax: TypeName variableName;
True
Java int types may not be used as boolean types and are always signed (True/False)
Primitive Types Primitive Type Description boolean true/false byte 8 bits char 16 bits (UNICODE) short 16 bits int 32 bits long 64 bits float 32 bits IEEE 754-1985 double 64 bits IEEE 754-1985
Primitive Types The Java language has the following primitive types:
class FreshJuice { enum FreshJuiceSize{ SMALL, MEDIUM, LARGE } FreshJuiceSize size; } public class FreshJuiceTest { public static void main(String args[]){ FreshJuice juice = new FreshJuice(); juice.size = FreshJuice.FreshJuiceSize.MEDIUM ; System.out.println("Size: " + juice.size); } }
Sample Java code which will produce : Size:MEDIUM