Questions and Answers.

Size: px
Start display at page:

Download "Questions and Answers."

Transcription

1 Q.1) What is the output of this program? classmainclass char a = 'A'; a++; System.out.print((int)a); A. 66 B. 67 C. 65 D. 64 ANSWER : 66 ASCII value of 'A' is 65, on using ++ operator character value increments by one. output: $ javac mainclass.java $ javamainclass 66 Q.2) What will be the output of the program? public class CommandArgs public static void main(string [] args) String s1 = args[1]; String s2 = args[2]; String s3 = args[3]; String s4 = args[4]; System.out.print(" args[2] = " + s2); and the command-line invocation is >javacommandargs A. args[2] = 2 B. args[2] = 3 C. args[2] = null D. An exception is thrown at runtime. ANSWER : An exception is thrown at runtime. An exception is thrown because in the code String s4 = args[4];, the array index (the fifth element) is out of bounds. The exception thrown is the cleverly named ArrayIndexOutOfBoundsException. Q.3) Which three are valid declarations of a float? float f1 = -343; float f2 = 3.14; float f3 = 0x12345; float f4 = 42e7; float f5 = D; float f6 = 2.81F; A. 1, 2, 4 B. 2, 3, 5 Page 1

2 C. 1, 3, 6 D. 2, 4, 6 ANSWER : 1, 3, 6 (1) and (3) are integer literals (32 bits), and integers can be legally assigned to floats (also 32 bits). (6) is correct because (F) is appended to the literal, declaring it as a float rather than a double (the default for floating point literals). (2), (4),and (5) are all doubles. Q.4) What will be the output of the program? public class CommandArgsTwo public static void main(string [] argh) int x; x = argh.length; for (int y = 1; y <= x; y++) System.out.print(" " + argh[y]); and the command-line invocation is >javacommandargstwo A B C D. An exception is thrown at runtime ANSWER : An exception is thrown at runtime An exception is thrown because at some point in (System.out.print(" " + argh[y]);), the value of x will be equal to y, resulting in an attempt to access an index out of bounds for the array. Remember that you can access only as far as length - 1, so loop logical tests should use x <somearray.length as opposed to x < = somearray.length. Q.5) What is the output of this program? class increment int g = 3; System.out.print(++g * 8); A. 25 B. 24 C. 32 D. 33 ANSWER : 32 Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32. output: $ javac increment.java $ java increment 32 Page 2

3 Q.6) public class F0091 public void main( String[] args ) System.out.println( "Hello" + args[0] ); What will be the output of the program, if this code is executed with the command line: >java F0091 world A. Hello B. Hello Foo91 C. Hello world D. The code does not run. ANSWER : The code does not run. D is correct. A runtime error will occur owning to the main method of the code fragment not being declared static: Exception in thread "main" java.lang.nosuchmethoderror: main The Java Language Specification clearly states: "The main method must be declared public, static, and void. It must accept a single argument that is an array of strings." Q.7) What is the output of this program? class variable_scope int x; x = 5; int y = 6; System.out.print(x + " " + y); System.out.println(x + " " + y); A B C. Runtime error D. Compilation error ANSWER : Compilation error Second print statement doesn't have access to y, scope y was limited to the block defined after initialization of x. output: $ javac variable_scope.java Exception in thread main java.lang.error: Unresolved compilation problem: y cannot be resolved to a variable Q.8) Which of these coding types is used for data type characters in Java? A. ASCII B. ISO-LATIN-1 C. UNICODE D. None of the mentioned ANSWER : UNICODE Page 3

4 Explanation: Unicode defines fully international character set that can represent all the characters found in all human languages. Its range is from 0 to Q.9) Which is a valid keyword in java? A. interface B. string C. Float D. unsigned ANSWER : interface interface is a valid keyword. B is wrong because although "String" is a class type in Java, "string" is not a keyword. C is wrong because "Float" is a class type. The keyword for the Java primitive is float. D is wrong because "unsigned" is a keyword in C/C++ but not in Java.a Q.10) What is the output of this program? class area double r, pi, a; r = 9.8; p1 = 3.14; a = pi * r * r; System.out.println(a); A B. 301 C D ANSWER : output: $ javac area.java $ java area Q.11) What is the output of this program? classdynamic_initialization double a, b; a = 3.0; b = 4.0; double c = Math.sqrt(a * a + b * b); System.out.println(c); A. 5.0 B C. 7.0 D. Compilation Error Page 4

5 ANSWER : 5.0 Variable c has been dynamically initialized to square root of a * a + b * b, during run time. output: $ javac dynamic_initialization.java $ javadynamic_initialization 5.0 Q.12) Which of these can not be used for a variable name in Java? A. identifier B. keyword C. both a < b D. None of the mentioned ANSWER : keyword Keywords are specially reserved words which can not be used for naming a user defined variable, example : class, int, for etc Q.13) Which is the valid declarations within an interface definition? A. public double methoda(); B. public final double methoda(); C. static void methoda(double d1); D. protected void methoda(double d1); ANSWER : public double methoda(); A is correct. A public access modifier is acceptable. The method prototypes in an interface are all abstract by virtue of their declaration, and should not be declared abstract. B is wrong. The final modifier means that this method cannot be constructed in a subclass. A final method cannot be abstract. C is wrong. static is concerned with the class and not an instance. D is wrong. protected is not permitted when declaring a method of an interface. See information below. Member declarations in an interface disallow the use of some declaration modifiers; you cannot use transient, volatile, or synchronized in a member declaration in an interface. Also, you may not use the private and protected specifiers when declaring members of an interface. Q.14) What is the numerical range of a char in Java? A to 127 B. 0 to 256 C. 0 to D. 0 to ANSWER : 0 to Char occupies 16-bit in memory, so it supports 2^16 i:e from 0 to Q.15) Which of these is data type long literal? A. 0x99fffL B. ABCDEFG C. 0x99fffa D Page 5

6 ANSWER : 0x99fffL Data type long literals are appended by an upper or lowercase L. 0x99fffL is hexadecimal long literal. Q.16) What is the range of data type byte in Java? A to 127 B to C to D. None of the above ANSWER : -128 to 127 Byte occupies 8 bits in memory. Its range is from -128 to 127. Q.17) What will be the output of the program? public class TestDogs public static void main(string [] args) Dog [][] thedogs = new Dog[3][]; System.out.println(theDogs[2][0].toString()); class Dog A. null B. thedogs C. Compilation fails D. An exception is thrown at runtime ANSWER : An exception is thrown at runtime The second dimension of the array referenced by thedogs has not been initialized. Attempting to access an uninitialized object element (System.out.println(theDogs[2][0].toString());) raises a NullPointerException. Q.18) What is the range of data type short in Java? A to 127 B to C to D. None of the mentioned ANSWER : to Short occupies 32 bits in memory. Its range is from to Q.19) In the given program, how many lines of output will be produced? public class Test public static void main(string [] args) int [] [] [] x = new int [3] [] []; int i, j; x[0] = new int[4][]; x[1] = new int[2][]; x[2] = new int[5][]; Page 6

7 for (i = 0; i <x.length; i++) for (j = 0; j < x[i].length; j++) x[i][j] = new int [i + j + 1]; System.out.println("size = " + x[i][j].length); A. 7 B. 9 C. 11 D. 13 ANSWER : 11 The loops use the array sizes (length). It produces 11 lines of output as given below. D:Java>javac Test.java D:Java>java Test size = 1 size = 2 size = 3 size = 4 size = 2 size = 3 size = 3 size = 4 size = 5 size = 6 size = 7 Therefore, 11 is the answer. Q.20) What will be the output of the program? public class Test public static void main(string [] args) signedint x = 10; for (int y=0; y<5; y++, x--) System.out.print(x + ", "); A. 10, 9, 8, 7, 6, B. 9, 8, 7, 6, 5, C. Compilation fails. D. An exception is thrown at runtime. ANSWER : Compilation fails. The word "signed" is not a valid modifier keyword in the Java language. All number primitives in Java are signed. Hence the Compilation will fails. Q.21) What is the output of this program? class main_arguments public static void main(string [] args) Page 7

8 String [][] argument = new String[2][2]; int x; argument[0] = args; x = argument[0].length; for (int y = 0; y < x; y++) System.out.print(" " + argument[0][y]); A. 1 1 B. 1 0 C D ANSWER : In argument[0] = args;, the reference variable arg[0], which was referring to an array with two elements, is reassigned to an array (args) with three elements. Output: $ javac main_arguments.java $ javamain_arguments Q.22) Which of these literals can be contained in a data type float variable? A. 1.7e-308 B. 3.4e-038 C. 1.7e+308 D. 3.4e-050 ANSWER : 3.4e-038 Range of data type float is 3.4e-038 to 3.4e+308. Q.23) Which of the following are legal lines of Java code? 1. int w = (int)888.8; 2. byte x = (byte)100l; 3. long y = (byte)100; 4. byte z = (byte)100l; A. 1 and 2 B. 2 and 3 C. 3 and 4 D. All statements are correct. ANSWER : All statements are correct. Statements (1), (2), (3), and (4) are correct. (1) is correct because when a floating-point number (a double in this case) is cast to an int, it simply loses the digits after the decimal.(2) and (4) are correct because a long can be cast into a byte. If the long is over 127, it loses its most significant (leftmost) bits.(3) actually works, even though a cast is not necessary, because a long can store a byte. Q.24) What is the output of this program? class evaluate int a[] = 1,2,3,4,5; Page 8

9 int d[] = a; int sum = 0; for (int j = 0; j < 3; ++j) sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]); System.out.println(sum); A. 38 B. 39 C. 40 D. 41 ANSWER : 40 output: $ javac evaluate.java $ java evaluate 40 Q.25) What is the output of this program? Class asciicodes char var1 = 'A'; char var2 = 'a'; System.out.println((int)var1 + " " + (int)var2); A. 162 B C D ANSWER : ASCII code for 'A' is 65 and for 'a' is 97. output: $ javac asciicodes.java $ javaasciicodes Q.26) What is the output of this program? class mainclass boolean var1 = true; boolean var2 = false; if (var1) System.out.println(var1); else System.out.println(var2); A. 0 B. 1 Page 9

10 C. true D. false ANSWER : true output: $ javac mainclass.java $ javamainclass true Q.27) If an expression contains double, int, float, long, then whole expression will promoted into which of these data types? A. long B. int C. double D. float ANSWER : double If any operand is double the result of expression is double. Q.28) An expression involving byte, int, and literal numbers is promoted to which of these? A. int B. long C. byte D. float ANSWER : int An expression involving bytes, ints, shorts, literal numbers, the entire expression is promoted to int before any calculation is done. Q.29) What is the output of this program? class conversion double a = ; int b = 300; byte c = (byte) a; byte d = (byte) b; System.out.println(c + " " + d); A B C D ANSWER : Type casting a larger variable into a smaller variable results in modulo of larger variable by range of smaller variable. b contains 300 which is larger than byte's range i:e -128 to 127 hence d contains 300 modulo 256 i:e 44. output: $ javac conversion.java Page 10

11 $ java conversion Q.30) Which of these is returned by operators &,? A. Integer B. Boolean C. Character D. Float ANSWER : Integer Here & is a BITWISE AND it returns integer value. Q.31) Which of these values can a boolean variable contain? A. True & False B. 0 & 1 C. Any integer value. D. Both a & b ANSWER : True & False Boolean variable can contain only one of two possible values, true and false. Q.32) What will be the output of the program? public class CommandArgsThree public static void main(string [] args) String [][] argcopy = new String[2][2]; int x; argcopy[0] = args; x = argcopy[0].length; for (int y = 0; y < x; y++) System.out.print(" " + argcopy[0][y]); and the command-line invocation is >javacommandargsthree A. 0 0 B. 1 2 C D ANSWER : In argcopy[0] = args;, the reference variable argcopy[0], which was referring to an array with two elements, is reassigned to an array (args) with three elements. Q.33) What is the output of this program? class conversion double a = ; int b = 300; byte c = (byte) a; Page 11

12 byte d = (byte) b; System.out.println(c + " " + d); A B C D ANSWER : Type casting a larger variable into a smaller variable results in modulo of larger variable by range of smaller variable. b contains 300 which is larger than byte's range i:e -128 to 127 hence d contains 300 modulo 256 i:e 44. output: $ javac conversion.java $ java conversion Q.34) What is the output of this program? class array_output int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) array_variable[i] = i/2; arry_variable[i]++; System.out.print(array_variable[i] + " "); i++; A B C D ANSWER : When an array is declared using new operator then all of its elements are initialized to 0 automatically. for loop body is executed 5 times as whenever controls comes in the loop i value is incremented twice, first by i++ in body of loop then by ++i in increment condition of for loop. output: $ javac array_output.java $ javaarray_output Q.35) Which one is a valid declaration of a boolean? A. boolean b1 = 1; B. boolean b2 = false; C. boolean b3 = false; D. boolean b4 = true; ANSWER : boolean b3 = false; Page 12

13 Boolean can only be assigned true or false literals. Q.36) What is the output of this program? classarray_output chararray_variable [] = new char[10]; for (int i = 0; i < 10; ++i) array_variable[i] = "i"; System.out.print(array_variable[i] + "" ); i++; A. iiiii B C. i j k l m D. None of the mentioned ANSWER : iiiii $ javac array_output.java $ javaarray_output iiiii Q.37) public interface Foo int k = 4; /* Line 3 */ Which three piece of codes are equivalent to line 3? finalint k = 4; publicint k = 4; staticint k = 4; abstractint k = 4; volatileint k = 4; protectedint k = 4; A. 1, 2 and 3 B. 2, 3 and 4 C. 3, 4 and 5 D. 4, 5 and 6 ANSWER : 1, 2 and 3 (1), (2) and (3) are correct. Interfaces can have constants, which are always implicitly public, static, and final. Interface constant declarations of public, static, and final are al in any combination. Q.38) What is the output of this program? class booloperators boolean var1 = true; boolean var2 = false; System.out.println((var2 & var2)); Page 13

14 A. 0 B. 1 C. true D. false ANSWER : false boolean '&' operator always returns true or false. var1 is defined true and var2 is defined false hence their '&' operator result is false. output: $ javac booloperators.java $ javabooloperators False Q.39) What is the output of this program? class A final public int calculate(int a, int b) return 1; class B extends A publicint calculate(int a, int b) return 2; public class output B object = new B(); System.out.print("b is " + b.calculate(0, 1)); A. b is : 2 B. b is : 1 C. Compilation Error. D. An exception is thrown at runtime. ANSWER : Compilation Error. The code does not compile because the method calculate() in class A is final and so cannot be overridden by method of class b. Q.40) What is the output of this program? class c public void main( String[] args ) System.out.println( "Hello" + args[0] ); A. Hello c B. Hello C. Hello world D. Runtime Error. ANSWER : Runtime Error. A runtime error will occur owning to the main method of the code fragment not being declared static. Output: $ javac c.java Exception in thread ~Ac^a'notA"main~Ac^a'not^A Page 14

15 Q.41) Which of these occupy first 0 to 127 in Unicode character set used for characters in Java? A. ASCII B. ISO-LATIN-1 C. None of the mentioned D. Both a & b ANSWER : Both a & b First 0 to 127 character set in Unicode are same as those of ISO-LAIN-1 and ASCII. Q.42) Which will legally declare, construct, and initialize an array? A. int [] mylist = "1", "2", "3"; B. int [] mylist = (5, 8, 2); C. intmylist [] [] = 4,9,7,0; D. intmylist [] = 4, 3, 7; ANSWER : intmylist [] = 4, 3, 7; The only legal array declaration and assignment statement is D A is wrong because it initializes an int array with String literals. B is wrong because it use something other than curly braces for the initialization. C is wrong because it provides initial values for only one dimension, although the declared array is a two-dimensional array. Q.43) What will be the output of the program? public class X public static void main(string [] args) String names [] = new String[5]; for (int x=0; x <args.length; x++) names[x] = args[x]; System.out.println(names[2]); and the command line invocation is >java X a b A. names B. null C. Compilation fails D. An exception is thrown at runtime ANSWER : null The names array is initialized with five null elements. Then elements 0 and 1 are assigned the String values "a" and "b" respectively (the command-line arguments passed to main). Elements of names array 2, 3, and 4 remain unassigned, so they have a value of null. Q.44) What is the numerical range of a char? A to 127 B. -(215) to (215) - 1 C. 0 to D. 0 to Page 15

16 ANSWER : 0 to A char is really a 16-bit integer behind the scenes, so it supports 216 (from 0 to 65535) values. Q.45) import java.awt.*; class Ticker extends Component public static void main (String [] args) Ticker t = new Ticker(); /* Missing Statements? */ which two of the following statements, inserted independently, could legally be inserted into missing section of this code? boolean test = (Component instanceof t); boolean test = (t instanceof Ticker); boolean test = t.instanceof(ticker); boolean test = (t instanceof Component); A. 1 and 4 B. 2 and 3 C. 1 and 3 D. 2 and 4 ANSWER : 2 and 4 (2) is correct because class type Ticker is part of the class hierarchy of t; therefore it is a legal use of the instanceof operator. (4) is also correct because Component is part of the hierarchy of t, because Ticker extends Component. (1) is incorrect because the syntax is wrong. A variable (or null) always appears before the instanceof operator, and a type appears after it. (3) is incorrect because the statement is used as a method (t.instanceof(ticker);), which is illegal. Q.46) Which two statements are equivalent? 1. 3/2 2. 3<2 3. 3*4 4. 3<<2 A. 1 and 2 B. 2 and 3 C. 3 and 4 D. 1 and 4 ANSWER : 3 and 4 (1) is wrong. 3/2 = 1 (integer arithmetic). (2) is wrong. 3 < 2 = false. (3) is correct. 3 * 4 = 12. (4) is correct. 3 <<2= 12. In binary 3 is 11, now shift the bits two places to the left and we get 1100 which is 12 in binary (3*2*2). Q.47) What will be the output of the program? class Test public static void main(string [] args) Page 16

17 int x=20; String sup = (x < 15)? "small" : (x < 22)? "tiny" : "huge"; System.out.println(sup); A. small B. tiny C. huge D. Compilation fails ANSWER : tiny This is an example of a nested ternary operator. The second evaluation (x < 22) is true, so the "tiny" value is assigned to sup. Q.48) Which of these is returned by greater than, <, and equal to, ==, operator? A. Integers B. Floating - point numbers C. Boolean D. None of the mentioned ANSWER : Boolean All relational operators return a boolean value i:e true and false. Q.49) What is the output of this program? class operators int x = 8; System.out.println(++x * 3 + " " + x); A B C D ANSWER : 27 9 Operator ++ has higher precedence than multiplication operator, *, x is incremented to 9 than multiplied with 3 giving 27. output: $ javac operators.java $ java operators 27 9 Q.50) What will be the output of the program class PassA public static void main(string [] args) PassA p = new PassA(); p.start(); Page 17

18 void start() long [] a1 = 3,4,5; long [] a2 = fix(a1); System.out.print(a1[0] + a1[1] + a1[2] + " "); System.out.println(a2[0] + a2[1] + a2[2]); long [] fix(long [] a3) a3[1] = 7; return a3; A B C D ANSWER : Output: The reference variables a1 and a3 refer to the same long array object. When the [1] element is updated in the fix() method, it is updating the array referred to by a1. The reference variable a2 refers to the same array object. So Output: " "3+7+5 Output: Because Numeric values will be added Q.51) What will be the output of the program? class Test public static void main(string [] args) int x= 0; int y= 0; for (int z = 0; z < 5; z++) if (( ++x > 2 ) && (++y > 2)) x++; System.out.println(x + " " + y); A. 5 2 B. 5 3 C. 6 3 D. 6 4 ANSWER : 6 3 In the first two iterations x is incremented once and y is not because of the short circuit && operator. In the third and forth iterations x and y are each incremented, and in the fifth iteration x is doubly incremented and y is incremented. Q.52) What is the output of relational operators? Page 18

19 A. Integer B. Boolean C. Characters D. Double ANSWER : Boolean Q.53) What is the output of this program? class Relational_operator int var1 = 5; int var2 = 6; System.out.print(var1 > var2); A. 1 B. 0 C. true D. false ANSWER : false Operator > returns a boolean value. 5 is not greater than 6 therefore false is returned. output: $ javac Relational_operator.java $ java Relational_operator false Q.54) Which of these operators can skip evaluating right hand operand? A.! B. C. & D. && ANSWER : && Operator short circuit and, &&, and short circuit or,, skip evaluating right hand operand when output can be determined by left operand alone. Q.55) What is the output of this program? class Output int a = 1; int b = 2; int c = 3; a = 4; b >>= 1; c <<= 1; a ^= c; System.out.println(a + " " + b " " + c); Page 19

20 A B C D ANSWER : output: $ javac Output.java $ java Output Q.56) Which of the following are legal lines of Java code for increasing value of variable x by 1? 1. x++; 2. x = x + 1; 3. x += 1; 4. x =+ 1; A. 1, 2 & 3 B. 1 & 4 C. 1, 2 & 4 D. 3 & 2 ANSWER : 1, 2 & 3 Operator ++ increases value of variable by 1. x = x + 1 can also be written in shorthand form as x += 1. Q.57) What will be the output of the program? class SC2 public static void main(string [] args) SC2 s = new SC2(); s.start(); void start() int a = 3; int b = 4; System.out.print(" " " "); System.out.print(a + b); System.out.print(" " + a + b + " "); System.out.print(foo() + a + b + " "); System.out.println(a + b + foo()); String foo() return "foo"; A foo 7 7foo B foo34 34foo C foo34 34foo D foo34 7foo ANSWER : foo34 7foo Page 20

21 Because all of these expressions use the + operator, there is no precedence to worry about and all of the expressions will be evaluated from left to right. If either operand being evaluated is a String, the + operator will concatenate the two operands; if both operands are numeric, the + operator will add the two operands. Q.58) What is the output of this program? class Output int x, y = 1; x = 10; if (x!= 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); A. 1 B. 2 C. Runtime error owing to division by zero in if condition. D. Unpredictable behavior of program. ANSWER : 2 Operator short circuit and, &&, skips evaluating right hand operand if left hand operand is false thus division by zero in if condition does not give an error. output: $ javac Output.java $ java Output 2 Q.59) What will be the output of the program? class Bitwise public static void main(string [] args) int x = 11 & 9; int y = x ^ 3; System.out.println( y 12 ); A. 0 B. 7 C. 8 D. 14 ANSWER : 14 The & operator produces a 1 bit when both bits are 1. The result of the & operation is 9. The ^ operator produces a 1 bit when exactly one bit is 1; the result of this operation is 10. The operator produces a 1 bit when at least one bit is 1; the result of this operation is 14. Q.60) What is the output of this program? class increment Page 21

22 A. 25 B. 24 C. 32 D. 33 int g = 3; System.out.print(++g * 8); ANSWER : 32 Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32. output: $ javac increment.java $ java increment 32 Q.61) What will be the output of the program? class Two byte x; class PassO public static void main(string [] args) PassO p = new PassO(); p.start(); void start() Two t = new Two(); System.out.print(t.x + " "); Two t2 = fix(t); System.out.println(t.x + " " + t2.x); Two fix(two tt) tt.x = 42; return tt; A. null null 42 B C D ANSWER : In the fix() method, the reference variable tt refers to the same object (class Two) as the t reference variable. Updating tt.x in the fix() method updates t.x (they are one in the same object). Remember also that the instance variable x in the Two class is initialized to 0. Q.62) What is the output of this program? Page 22

23 class bitwise_operator int var1 = 42; int var2 = ~var1; System.out.print(var1 + " " + var2); A B C D ANSWER : Unary not operator, ~, inverts all of the bits of its operand. 42 in binary is in using ~ operator on var1 and assigning it to var2 we get inverted value of 42 i:e which is -43 in decimal. output: $ javac bitwise_operator.java $ java bitwise_operator Q.63) Which two statements are equivalent? 16*4 16>>2 16/2^2 16>>>2 A. 1 and 2 B. 2 and 4 C. 3 and 4 D. 1 and 3 ANSWER : 2 and 4 (2) is correct. 16 >> 2 = 4 (4) is correct. 16 >>> 2 = 4 (1) is wrong. 16 * 4 = 64 (3) is wrong. 16/2 ^ 2 = 10 Q.64) What is the output of this program? class increment double var1 = 1 + 5; double var2 = var1 / 4; int var3 = 1 + 5; int var4 = var3 / 4; System.out.print(var2 + " " + var4); A. 1 1 B. 0 1 C D Page 23

24 ANSWER : output: $ javac increment.java $ java increment Q.65) What is the output of this program? class Output int x, y; x = 10; x++; --x; y = x++; System.out.println(x + " " + y); A B C D ANSWER : x is initialized to 10 then increased by 1 by ++ operator making it 11. x is again decreased by operator making it 10, next x is incremented by post increment and intialized to y, here the value of x obtained before increment operator is executed, so value of y is 10 and value of x is 11. output: $ javac Output.java $ java Output Q.66) What is the output of this program? class bool_operator boolean a = true; boolean b =!true; boolean c = a b; boolean d = a & b; boolean e = d? b : c; System.out.println(d + " " + e); A. false false B. true ture C. true false D. false true ANSWER : false true Operator returns true if any one operand is true, thus 'c = true false' is true. Operator & returns a true if both of the operand is true thus d is false. Ternary operator?: assigns left of ':' if condition is true and right hand of ':' if condition is false. d is false thus e = d? Page 24

25 b : c, assigns c to e, e contains true. output: $ javac bool_operator.java $ java bool_operator false true Q.67) Which of these statements are incorrect A. Equal to operator has least precedence. B. Brackets () have highest precedence. C. Division operator, /, has higher precedence than multiplication operator. D. Addition operator, +, and subtraction operator have equal precedence. ANSWER : Division operator, /, has higher precedence than multiplication operator. Division operator, /, has equal precedence as of multiplication operator. In expression involving multiplication and division evaluation of expression will begin from right side when no brackets are used. Q.68) Which of these statements are incorrect? A. The left shift operator, <<, shifts all of the bite in a value to the left specified number of times. B. The right shift operator, >>, shifts all of the bite in a value to the right specified number of times. C. The left shift operator can be used as an alternative to multiplying by 2. D. The right shift operator automatically fills the higher order bits with 0. ANSWER : The right shift operator automatically fills the higher order bits with 0. The right shift operator automatically fills the higher order bit with its previous contents each time a shift occurs. This also preserves the sign of the value. Q.69) What will be the output of the program? class SSBool public static void main(string [] args) boolean b1 = true; boolean b2 = false; boolean b3 = true; if ( b1 & b2 b2 & b3 b2 ) /* Line 8 */ System.out.print("ok "); if ( b1 & b2 b2 & b3 b2 b1 ) /*Line 10*/ System.out.println("dokey"); A. ok B. dokey C. ok dokey D. No output is produced ANSWER : dokey The & operator has a higher precedence than the operator so that on line 8 b1 and b2 are evaluated together as are b2 & b3. The final b1 in line 10 is what causes that if test to be true. Hence it prints "dokey". Page 25

26 Q.70) What is the output of this program? class Output int x, y = 1; x = 10; if (x!= 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); A. 1 B. 2 C. Runtime error owing to division by zero in if condition. D. Unpredictable behavior of program. ANSWER : 2 Operator short circuit and, &&, skips evaluating right hand operand if left hand operand is false thus division by zero in if condition does not give an error. output: $ javac Output.java $ java Output 2 Q.71) Which of these have highest precedence? A. () B. ++ C. * D. >> ANSWER : () Order of precedence is (highest to lowest) a -> b -> c -> d. Q.72) What is the output of this program? class leftshift_operator byte x = 64; int i; byte y; i = x << 2; y = (byte) (x << 2) System.out.print(i + " " + y); A B C D ANSWER : output: $ javac leftshift_operator.java Page 26

27 $ java leftshift_operator Q.73) What will be the output of the program? class BitShift public static void main(string [] args) int x = 0x ; System.out.print(x + " and "); x = x >>> 31; System.out.println(x); A and 1 B. 0x and 0x C and -1 D. 1 and ANSWER : and 1 A is correct. The >>> operator moves all bits to the right, zero filling the left bits. The bit transformation looks like this: Before: After: C is incorrect because the >>> operator zero fills the left bits, which in this case changes the sign of x, as shown. B is incorrect because the output method print() always displays integers in base 10. D is incorrect because this is the reverse order of the two output numbers. Q.74) What will be the output of the program? class Test public static void main(string [] args) int x= 0; int y= 0; for (int z = 0; z < 5; z++) if (( ++x > 2 ) (++y > 2)) x++; System.out.println(x + " " + y); A. 5 3 B. 8 2 C. 8 3 D. 8 5 ANSWER : 8 2 The first two iterations of the for loop both x and y are incremented. On the third iteration x is incremented, and for the first time becomes greater than 2. The short circuit or operator keeps y from ever being incremented again and x is incremented twice on each of the last three iterations. Page 27

28 Q.75) import java.awt.button; class CompareReference public static void main(string [] args) float f = 42.0f; float [] f1 = new float[2]; float [] f2 = new float[2]; float [] f3 = f1; long x = 42; f1[0] = 42.0f; which three statements are true? 1. f1 == f2 2. f1 == f3 3. f2 == f1[1] 4. x == f1[0] 5. f == f1[0] A. 1, 2 and 3 B. 2, 4 and 5 C. 3, 4 and 5 D. 1, 4 and 5 ANSWER : 2, 4 and 5 (2) is correct because the reference variables f1 and f3 refer to the same array object. (4) is correct because it is legal to compare integer and floating-point types (5) is correct because it is legal to compare a variable with an array element. (3) is incorrect because f2 is an array object and f1[1] is an array element. Q.76) Modulus operator, %, can be applied to which of these? A. Integers B. Floating point numbers C. Both Integers and floating point numbers. D. None of the mentioned ANSWER : Integers Modulus operator can be applied to both integers and floating point numbers. Q.77) Which two are equal? 32/4 (8 >> 2) << 4 2^5 128 >>> 2 2 >> 5 A. 1 and 2 B. 2 and 4 C. 1 and 3 D. 2 and 3 ANSWER : 2 and 4 (2) and (4) are correct. (2) and (4) both evaluate to 32. (2) is shifting bits right then left using the signed bit shifters >> and <<. (4) is shifting bits using the unsigned operator >>>, but since the beginning number is positive the sign is maintained. Page 28

29 (1) evaluates to 8, (3) looks like 2 to the 5th power, but ^ is the Exclusive OR operator so (3) evaluates to 7. (5) evaluates to 0 (2 >> 5 is not 2 to the 5th). Q.78) What is the output of this program? class ternary_operator int x = 3; int y = ~ x; int z; z = x > y? x : y; System.out.print(z); A. 0 B. 1 C. 3 D. -4 ANSWER : 3 output: $ javac ternary_operator.java $ java ternary_operator 4 Q.79) What is the output of this program? class Modulus double a = 25.64; int b = 25; a = a % 10; b = b % 10; System.out.println(a + " " + b); A B C. 5 5 D ANSWER : Modulus operator returns the remainder of a division operation on the operand. a = a % 10 returns % 10 i:e Similarly b = b % 10 returns 5. output: $ javac Modulus.java $ java Modulus Q.80) Which of these lines of code will give better performance? 1. a 4 + c >> b & 7; 2. (a ((( 4 * c ) >> b ) & 7 )) A. 1 will give better performance as it has no parentheses. Page 29

30 B. 2 will give better performance as it has parentheses. C. Both 1 & 2 will give equal performance. D. Dependent on the computer system. ANSWER : Both 1 & 2 will give equal performance. Parentheses do not degrade the performance of the program. Adding parentheses to reduce ambiguity does not negatively affect your system. Q.81) Which of these is not a bitwise operator? A. & B. &= C. = D. <= ANSWER : <= <= is a relational operator. Q.82) What is the output of this program? class operators int var1 = 5; int var2 = 6; int var3; var3 = ++ var2 * var1 / var2 + var2; System.out.print(var2); A. 10 B. 11 C. 12 D. 56 ANSWER : 12 Operator ++ has the highest precedence than /, * and +. var2 is incremented to 7 and then used in expression, var3 = 7 * 5 / 7 + 7, gives 12. output: $ javac operators.java $ java operators 12 Q.83) What will be the output of the program? class Test public static void main(string [] args) Test p = new Test(); p.start(); void start() boolean b1 = false; boolean b2 = fix(b1); System.out.println(b1 + " " + b2); Page 30

31 boolean fix(boolean b1) b1 = true; return b1; A. true true B. false true C. true false D. false false ANSWER : false true The boolean b1 in the fix() method is a different boolean than the b1 in the start() method. The b1 in the start() method is not updated by the fix() method. Q.84) Which of the following are legal lines of code? int w = (int)888.8; byte x = (byte)1000l; long y = (byte)100; byte z = (byte)100l; A. 1 and 2 B. 2 and 3 C. 3 and 4 D. All statements are correct. ANSWER : All statements are correct. Statements (1), (2), (3), and (4) are correct. (1) is correct because when a floating-point number (a double in this case) is cast to an int, it simply loses the digits after the decimal. (2) and (4) are correct because a long can be cast into a byte. If the long is over 127, it loses its most significant (leftmost) bits. (3) actually works, even though a cast is not necessary, because a long can store a byte. Q.85) What is the value stored in x in following lines of code? int x, y, z; x = 0; y = 1; x = y = z = 8; A. 0 B. 1 C. 9 D. 8 ANSWER : 8 Q.86) What is the output of this program? class Output int a = 1; int b = 2; Page 31

32 A B C D int c; int d; c = ++b; d = a++; c++; b++; ++a; System.out.println(a + " " + b " " + c); ANSWER : output: $ javac Output.java $ java Output Q.87) What is the output of this program? class Output boolean a = true; boolean b = false; boolean c = a ^ b; System.out.println(!b); A. 0 B. 1 C. false D. true ANSWER : false output: $ javac Output.java $ java Output False Q.88) On applying Left shift operator, <<, on an integer bits are lost one they are shifted past which position bit? A. 1 B. 32 C. 33 D. 31 ANSWER : 31 The left shift operator shifts all of the bite in a value to the left specified number of times. For each shift left, the high order bit is shifted out and lost, zero is brought in from right. When a left shift is applied to an integer operand, bits are lost once they are shifted past the bit position 31. Page 32

33 Q.89) What is the output of this program? class bitwise_operator int a = 3; int b = 6; int c = a b; int d = a & b; System.out.println(c + " " + d); A. 7 2 B. 7 7 C. 7 5 D. 5 2 ANSWER : 5 2 And operator produces 1 bit if both operand are 1. Or operator produces 1 bit if any bit of the two operands in 1. output: $ javac bitwise_operator.java $ java bitwise_operator 7 2 Q.90) What is the operand of arithmetic operators? A. Numeric B. Boolean C. Characters D. Both a & c ANSWER : Both a & c The operand of arithmetic operators can be any of numeric or character type, But not boolean. Q.91) What is the output of this program? class ternary_operator int x = 3; int y = ~ x; int z; z = x > y? x : y; System.out.print(z); A. 0 B. 1 C. 3 D. -4 ANSWER : 3 output: $ javac ternary_operator.java $ java ternary_operator Page 33

34 4 Q.92) Which of the following operators can operate on a boolean variable? 1. && 2. == 3.?: 4. += A. 3 & 2 B. 1 & 4 C. 1, 2 & 4 D. 1, 2 & 3 ANSWER : 1, 2 & 3 Operator Short circuit AND, &&, equal to, ==, ternary if-then-else,?:, are boolean logical operators. += is an arithmetic operator it can operate only on numeric values. Q.93) What will be the output of the program? class Equals public static void main(string [] args) int x = 100; double y = 100.1; boolean b = (x = y); /* Line 7 */ System.out.println(b); A. true B. false C. Compilation fails D. An exception is thrown at runtime ANSWER : Compilation fails The code will not compile because in line 7, the line will work only if we use (x==y) in the line. The == operator compares values to produce a boolean, whereas the = operator assigns a value to variables. A, B, and D are incorrect because the code does not get as far as compiling. If we corrected this code, the output would be false. Q.94) Which operator is used to invert all the digits in binary representation of a number? A. ~ B. <<< C. >>> D. ^ ANSWER : ~ Unary not operator, ~, inverts all of the bits of its operand in binary representation. Q.95) What will be the output of the program? class BoolArray boolean [] b = new boolean[3]; Page 34

35 int count = 0; void set(boolean [] x, int i) x[i] = true; ++count; public static void main(string [] args) BoolArray ba = new BoolArray(); ba.set(ba.b, 0); ba.set(ba.b, 2); ba.test(); void test() if ( b[0] && b[1] b[2] ) count++; if ( b[1] && b[(++count - 2)] ) count += 7; System.out.println("count = " + count); A. count = 0 B. count = 2 C. count = 3 D. count = 4 ANSWER : count = 3 The reference variables b and x both refer to the same boolean array. count is incremented for each call to the set() method, and once again when the first if test is true. Because of the && short circuit operator, count is not incremented during the second if test. Q.96) Which right shift operator preserves the sign of the value? A. << B. >> C. <<= D. >>= ANSWER : >> Q.97) What is the output of this program? class rightshift_operator int x; x = 10; x = x >> 1; System.out.println(x); A. 10 Page 35

36 B. 5 C. 2 D. 20 ANSWER : 5 Right shift operator, >>, devides the value by 2. output: $ javac rightshift_operator.java $ java rightshift_operator 5 Q.98) What should be expression1 evaluate to in using ternary operator as in this line? expression1? expression2 : expression3 A. Integer B. Floating ~Ac^a'not^aEURoe point numbers C. Boolean D. None of the mentioned ANSWER : Boolean The controlling condition of ternary operator must evaluate to boolean. Q.99) public class Test What is the prototype of the default constructor? A. Test( ) B. Test(void) C. public Test( ) D. public Test(void) ANSWER : public Test( ) A and B are wrong because they use the default access modifier and the access modifier for the class is public (remember, the default constructor has the same access modifier as the class). D is wrong. The void makes the compiler think that this is a method specification - in fact if it were a method specification the compiler would spit it out. Q.100) public class Outer public void someoutermethod() //Line 5 public class Inner public static void main(string[] argv) Outer ot = new Outer(); //Line 10 Which of the following code fragments inserted, will allow to compile? A. new Inner(); //At line 5 B. new Inner(); //At line 10 Page 36

37 C. new ot.inner(); //At line 10 D. new Outer.Inner(); //At line 10 ANSWER : new Inner(); //At line 5 A compiles without problem. B gives error - non-static variable cannot be referenced from a static context. C package ot does not exist. D gives error - non-static variable cannot be referenced from a static context. Q.101) Which of these keywords cannot be used for a class which has been declared final? A. abstract B. extends C. Both a & b D. None of the mentioned ANSWER : abstract A abstract class is incomplete by itself and relies upon its subclasses to provide complete implementation. If we declare a class final then no class can inherit that class, an abstract class needs its subclasses hence both final and abstract cannot be used for a same class. Q.102) Which of these is used as default for a member of a class if no access specifier is used for it? A. private B. public C. public, within its own package D. protected ANSWER : private When we pass an argument by call-by-value a copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have no effect on original argument, they remain the same. Q.103) What will be the output of the program? public class ArrayTest public static void main(string[ ] args) float f1[ ], f2[ ]; f1 = new float[10]; f2 = f1; System.out.println("f2[0] = " + f2[0]); A. It prints f2[0] = 0.0 B. It prints f2[0] = NaN C. An error at f2 = f1; causes compile to fail. D. It prints the garbage value. ANSWER : It prints f2[0] = 0.0 A is correct. When you create an array (f1 = new float[10];) the elements are initialises to the default values for the primitive data type (float in this case - 0.0), so f1 will contain Page 37

38 10 elements each with a value of 0.0. f2 has been declared but has not been initialised, it has the ability to reference or point to an array but as yet does not point to any array. f2 = f1; copies the reference (pointer/memory address) of f1 into f2 so now f2 points at the array pointed to by f1. This means that the values returned by f2 are the values returned by f1. Changes to f1 are also changes to f2 because both f1 and f2 point to the same array. Q.104) What will be the output of the program? class Super public Integer getlength() return new Integer(4); public class Sub extends Super public Long getlength() return new Long(5); public static void main(string[] args) Super sooper = new Super(); Sub sub = new Sub(); System.out.println( sooper.getlength().tostring() + "," + sub.getlength().tostring() ); A. 4, 4 B. 4, 5 C. 5, 4 D. Compilation fails. ANSWER : Compilation fails. D is correct, compilation fails - The return type of getlength( ) in the super class is an object of reference type Integer and the return type in the sub class is an object of reference type Long. In other words, it is not an override because of the change in the return type and it is also not an overload because the argument list has not changed Q.105) Which of the following statements are incorrect? A. public members of class can be accessed by any code in the program. B. private members of class can only be accessed by other members of the class. C. private members of class can be inherited by a sub class, and become protected members in sub class. D. protected members of a class can be inherited by a sub class, and become private members of the sub class. ANSWER : private members of class can be inherited by a sub class, and become protected members in sub class. private members of a class cannot be inherited by a sub class. Q.106) What is the stored in the object obj in following lines of code? box obj; Page 38

39 A. Memory address of allocated memory of object. B. NULL C. Any arbitrary pointer D. Garbage ANSWER : NULL Memory is allocated to an object using new operator. box obj; just declares a reference to object, no memory is allocated to it hence it points to NULL. Q.107) You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective? A. public B. private C. protected D. transient ANSWER : protected Access modifiers dictate which classes, not which instances, may access features. Methods and variables are collectively known as members. Method and variable members are given access control in exactly the same way. private makes a member accessible only from within its own class protected makes a member accessible only to classes in the same package or subclass of the class default access is very similar to protected (make sure you spot the difference) default access makes a member accessible only to classes in the same package. public means that all other classes regardless of the package that they belong to, can access the member (assuming the class itself is visible) final makes it impossible to extend a class, when applied to a method it prevents a method from being overridden in a subclass, when applied to a variable it makes it impossible to reinitialise a variable once it has been initialised abstract declares a method that has not been implemented. transient indicates that a variable is not part of the persistent state of an object. volatile indicates that a thread must reconcile its working copy of the field with the master copy every time it accesses the variable. After examining the above it should be obvious that the access modifier that provides the most restrictions for methods to be accessed from the subclasses of the class from another package is C - protected. A is also a contender but C is more restrictive, B would be the answer if the constraint was the "same package" instead of "any package" in other words the subclasses clause in the question eliminates default. Q.108) What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package? A. public B. abstract C. protected D. default access ANSWER : default access default access is the "package oriented" access modifier. A and C are wrong because public and protected are less restrictive. B and D are wrong because abstract and synchronized are not access modifiers. Q.109) Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class? Page 39

40 A. final B. static C. private D. protected ANSWER : protected The private access modifier limits access to members of the same class. A, B, D, and E are wrong because protected are the wrong access modifiers, and final, static, and volatile are modifiers but not access modifiers. Q.110) Which of the following is a valid declaration of an object of class Box? A. Box obj = new Box(); B. Box obj = new Box; C. obj = new Box(); D. new Box obj; ANSWER : Box obj = new Box(); new is keyword used to allocate dynamic memory. Box obj = new Box(); This is syntax to create object in java. Q.111) Which of the following class level (nonlocal) variable declarations will not compile? A. protected int a; B. transient int b = 3; C. private synchronized int e; D. volatile int d; ANSWER : private synchronized int e; C will not compile; the synchronized modifier applies only to methods. A and B will compile because protected and transient are legal variable modifiers. D will compile because volatile is a proper variable modifier. Q.112) What is the output of this program? class main_class int x = 9; if (x == 9) int x = 8; System.out.println(x); A. 9 B. 8 C. Compilation error D. Runtime error ANSWER : Compilation error Two variables with the same name can't be created in a class. output: Page 40

41 $ javac main_class.java Exception in thread main java.lang.error: Unresolved compilation problem: Duplicate local variable x Q.113) /* Missing statements? */ public class NewTreeSet extends java.util.treeset public static void main(string [] args) java.util.treeset t = new java.util.treeset(); t.clear(); public void clear() TreeMap m = new TreeMap(); m.clear(); which two statements, added independently at beginning of the program, allow the code to compile? No statement is required import java.util.*; import.java.util.tree*; import java.util.treeset; import java.util.treemap; A. 1 only B. 2 and 5 C. 3 and 4 D. 3 and 5 ANSWER : 2 and 5 (2) and (5). TreeMap is the only class that must be imported. TreeSet does not need an import statement because it is described with a fully qualified name. (1) is incorrect because TreeMap must be imported. (3) is incorrect syntax for an import statement. (4) is incorrect because it will not import TreeMap, which is required. Q.114) Which of the following statements is correct? A. Public method is accessible to all other classes in the hierarchy B. Public method is accessible only to subclasses of its parent class C. Public method can only be called by object of its class. D. Public method can be accessed by calling object of the public class. ANSWER : Public method is accessible to all other classes in the hierarchy we can access public member of class anywhere in program. Q.115) Which of these operators is used to allocate memory for an object? A. malloc B. alloc C. new D. give ANSWER : new Operator new dynamically allocates memory for an object and returns a reference to it. Page 41

JAVA AS OBJECT ORIENTED PROGRAMMING LANGUAGE

JAVA AS OBJECT ORIENTED PROGRAMMING LANGUAGE Unit IV JAVA AS OBJECT ORIENTED PROGRAMMING LANGUAGE MULTIPLE CHOICE QUESTIONS 1. What is the range of data type short in Java? (a) -128 to 127 (b) -32768 to 32767 (c) -2147483648 to 2147483647 (d) None

More information

1.Which four options describe the correct default values for array elements of the types indicated?

1.Which four options describe the correct default values for array elements of the types indicated? 1.Which four options describe the correct default values for array elements of the types indicated? 1. int -> 0 2. String -> "null" 3. Dog -> null 4. char -> '\u0000' 5. float -> 0.0f 6. boolean -> true

More information

1. Short circuit AND (&&) = if first condition is false then the second is never evaluated

1. Short circuit AND (&&) = if first condition is false then the second is never evaluated 1. What are the 2 types of short circuit operators. 1. Short circuit AND (&&) = if first condition is false then the second is never evaluated because true and false gives you false only. 2. Short circuit

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

SECTION II: LANGUAGE BASICS

SECTION II: LANGUAGE BASICS Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Operators Questions

Operators Questions Operators Questions https://www.geeksforgeeks.org/java-operators-question-1/ https://www.indiabix.com/java-programming/operators-andassignments/ http://www.instanceofjava.com/2015/07/increment-decrementoperators-interview.html

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

3 Operators and Assignments

3 Operators and Assignments 3 Operators and Assignments CERTIFICATION OBJECTIVES Java Operators Logical Operators Passing Variables into Methods Q&A Two-Minute Drill Self Test 146 Chapter 3: Operators and Assignments If you ve got

More information

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

The Java language has a wide variety of modifiers, including the following:

The Java language has a wide variety of modifiers, including the following: PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

STRUCTURING OF PROGRAM

STRUCTURING OF PROGRAM Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the

More information

Points To Remember for SCJP

Points To Remember for SCJP Points To Remember for SCJP www.techfaq360.com The datatype in a switch statement must be convertible to int, i.e., only byte, short, char and int can be used in a switch statement, and the range of the

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Zheng-Liang Lu Java Programming 45 / 79

Zheng-Liang Lu Java Programming 45 / 79 1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

More information

Operators. Java Primer Operators-1 Scott MacKenzie = 2. (b) (a)

Operators. Java Primer Operators-1 Scott MacKenzie = 2. (b) (a) Operators Representing and storing primitive data types is, of course, essential for any computer language. But, so, too, is the ability to perform operations on data. Java supports a comprehensive set

More information

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail. OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>= Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic

More information

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA 1. JIT meaning a. java in time b. just in time c. join in time d. none of above CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA 2. After the compilation of the java source code, which file is created

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Exercises Software Development I. 05 Conversions and Promotions; Lifetime, Scope, Shadowing. November 5th, 2014

Exercises Software Development I. 05 Conversions and Promotions; Lifetime, Scope, Shadowing. November 5th, 2014 Exercises Software Development I 05 Conversions and Promotions; Lifetime, Scope, Shadowing November 5th, 2014 Software Development I Winter term 2014/2015 Priv.-Doz. Dipl.-Ing. Dr. Andreas Riener Institute

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Lecture Set 4: More About Methods and More About Operators

Lecture Set 4: More About Methods and More About Operators Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

More information

Declarations and Access Control SCJP tips

Declarations and Access Control  SCJP tips Declarations and Access Control www.techfaq360.com SCJP tips Write code that declares, constructs, and initializes arrays of any base type using any of the permitted forms both for declaration and for

More information

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false. CS101, Mock Boolean Conditions, If-Then Boolean Expressions and Conditions The physical order of a program is the order in which the statements are listed. The logical order of a program is the order in

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

The Sun s Java Certification and its Possible Role in the Joint Teaching Material The Sun s Java Certification and its Possible Role in the Joint Teaching Material Nataša Ibrajter Faculty of Science Department of Mathematics and Informatics Novi Sad 1 Contents Kinds of Sun Certified

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,

More information

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003 Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

public class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("The age is " + age); }

public class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println(The age is  + age); } Question No :1 What is the correct ordering for the import, class and package declarations when found in a Java class? 1. package, import, class 2. class, import, package 3. import, package, class 4. package,

More information

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below: QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the

More information

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

IC Language Specification

IC Language Specification CS 301 Spring 2016 IC Language Specification The IC Language For the implementation project, you will build a compiler for an object-oriented language called IC (for Irish Coffee 1 ), which is essentially

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

Answer1. Features of Java

Answer1. Features of Java Govt Engineering College Ajmer, Rajasthan Mid Term I (2017-18) Subject: PJ Class: 6 th Sem(IT) M.M:10 Time: 1 hr Q1) Explain the features of java and how java is different from C++. [2] Q2) Explain operators

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

More information

Java Programming Language. 0 A history

Java Programming Language. 0 A history Java Programming Language 0 A history How java works What you ll do in Java JVM API Java Features 0Platform Independence. 0Object Oriented. 0Compiler/Interpreter 0 Good Performance 0Robust. 0Security 0

More information

Lecture Set 4: More About Methods and More About Operators

Lecture Set 4: More About Methods and More About Operators Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

More information

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

More information

The Arithmetic Operators

The Arithmetic Operators The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

More information

The Decaf Language. 1 Lexical considerations

The Decaf Language. 1 Lexical considerations The Decaf Language In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

Operators. 3 Two-Minute Drill CERTIFICATION OBJECTIVES Q&A. Using Operators. Self Test

Operators. 3 Two-Minute Drill CERTIFICATION OBJECTIVES Q&A. Using Operators. Self Test 4 Operators CERTIFICATION OBJECTIVES l Using Operators 3 Two-Minute Drill Q&A Self Test 276 Chapter 4: Operators If you've got variables, you're going to modify them. You'll increment them, add them together,

More information

VARIABLES AND TYPES CITS1001

VARIABLES AND TYPES CITS1001 VARIABLES AND TYPES CITS1001 Scope of this lecture Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Primitive types Every piece of data

More information

Primitive Data, Variables, and Expressions; Simple Conditional Execution

Primitive Data, Variables, and Expressions; Simple Conditional Execution Unit 2, Part 1 Primitive Data, Variables, and Expressions; Simple Conditional Execution Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Overview of the Programming Process Analysis/Specification

More information

Expressions & Flow Control

Expressions & Flow Control Objectives Distinguish between instance and local variables 4 Expressions & Flow Control Describe how instance variables are initialized Identify and correct a Possible reference before assignment compiler

More information

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

More information

Java Programming. Atul Prakash

Java Programming. Atul Prakash Java Programming Atul Prakash Java Language Fundamentals The language syntax is similar to C/ C++ If you know C/C++, you will have no trouble understanding Java s syntax If you don't, it will be easier

More information

Building Java Programs Chapter 2

Building Java Programs Chapter 2 Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. Data types type: A category or set of data values. Constrains the operations that can

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz) SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz) OPERATORS Operators are required to form expressions. Depending on the number of operands they take, they are called:

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

Array. Prepared By - Rifat Shahriyar

Array. Prepared By - Rifat Shahriyar Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types

More information

More Programming Constructs -- Introduction

More Programming Constructs -- Introduction More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Lara Technologies Special-Six Test

Lara Technologies Special-Six Test Flow control Part-1 Q: 01 Given: 10. public class Bar 11. static void foo( int... x ) 12. // insert code here 13. 14. Which two code fragments, inserted independently at line 12, will allow the class to

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

Language Fundamentals Summary

Language Fundamentals Summary Language Fundamentals Summary Claudia Niederée, Joachim W. Schmidt, Michael Skusa Software Systems Institute Object-oriented Analysis and Design 1999/2000 c.niederee@tu-harburg.de http://www.sts.tu-harburg.de

More information

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Language Features. 1. The primitive types int, double, and boolean are part of the AP Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

More information

Variables and literals

Variables and literals Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of

More information

The Decaf language 1

The Decaf language 1 The Decaf language 1 In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance

More information

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8 Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

Building Java Programs Chapter 2. bug. Primitive Data and Definite Loops. Copyright (c) Pearson All rights reserved. Software Flaw.

Building Java Programs Chapter 2. bug. Primitive Data and Definite Loops. Copyright (c) Pearson All rights reserved. Software Flaw. Building Java Programs Chapter 2 bug Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. 2 An Insect Software Flaw 3 4 Bug, Kentucky Bug Eyed 5 Cheesy Movie 6 Punch Buggy

More information

Building Java Programs Chapter 2

Building Java Programs Chapter 2 Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. bug 2 An Insect 3 Software Flaw 4 Bug, Kentucky 5 Bug Eyed 6 Cheesy Movie 7 Punch Buggy

More information

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every

More information