Enterprise Solutions Using J2EE

15
Enterprise solutions using J2EE SSS [1 ] Which of the following statements are correct? I. The long data type is the most versatile and efficient type. II. Data type determines behavior and not size. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect. The int type is the most versatile and efficient type, and it should be used most of the time when you want to create a number for counting or indexing arrays or doing integer math. It may seem that using short or byte will save space, but there is no guarantee that Java won't promote those types to int internally anyway. Remember, type determines behavior, not size. (The only exception is arrays, where byte is guaranteed to use only one byte per array element, short will use two bytes, and int will use four.) [1 ] Which of the following statements are correct? I. The long data type is the most versatile and efficient type. II. Data type determines behavior and not size. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect. [3 ] Which of the following statements are correct? I. In Java, a byte is a signed 8- bit type entity. II. The smallest integer data type is short. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect. The smallest integer type is byte. This is a signed 8-bit type that has a range from –128

Transcript of Enterprise Solutions Using J2EE

Page 1: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSS[1] Which of the following statements are correct? I. The long data type is the most

versatile and efficient type. II. Data type determines behavior and not size.

 Choice aOnly I is correct.

 Choice bOnly II is correct.

 Choice cBoth I and II are correct.

 Choice dBoth I and II are incorrect.

The int type is the most versatile and efficient type, and it should be used most of the time when you want to create a number for counting or indexing arrays or doing integer math. It may seem that using short or byte will save space, but there is no guarantee that Java won't promote those types to int internally anyway. Remember, type determines behavior, not size. (The only exception is arrays, where byte is guaranteed to use only one byte per array element, short will use two bytes, and int will use four.)

[1] Which of the following statements are correct? I. The long data type is the most versatile and efficient type. II. Data type determines behavior and not size.

 Choice aOnly I is correct.

 Choice bOnly II is correct.

 Choice cBoth I and II are correct.

 Choice dBoth I and II are incorrect.

[3] Which of the following statements are correct? I. In Java, a byte is a signed 8-bit type entity. II. The smallest integer data type is short.     

 Choice aOnly I is correct.

 Choice bOnly II is correct.

 Choice cBoth I and II are correct.

 Choice dBoth I and II are incorrect.

The smallest integer type is byte. This is a signed 8-bit type that has a range from –128 to 127. Variables of type byte are especially useful when you're working with a stream of data from a network or file. They are also useful when you're working with raw binary data that may not be directly compatible with Java's other built-in types. Byte variables are declared by use of the byte keyword. For example, the following declares two byte variables called b and c:

[4] Which of the following statements are correct? I. In Java octal values are denoted by a leading zero. II. In Java, the value 09 produces an error.

Page 2: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSS

 Choice aOnly I is correct.

 Choice bOnly II is correct

 Choice cBoth I and II are correct.

 Choice dBoth I and II are incorrect.

In Java octal values are denoted by a leading zero. Thus, 09 will produce an error from the compiler, since 9 is outside of octal's 0 to 7 range.

[5] Which of the following statements are correct? I. Integer literals create an int value. II. In Java, when a literal value is assigned to a byte or short variable, an error is generated even if the literal value is within the range of the target type.

 Choice aOnly I is correct.Values of the integral types byte, short, int, and long can be created from int literals. Values of type long that exceed the range of int can be created from long literals. Integer literals can be expressed these number systems:

 Choice b Only II is correct. When assigning a literal value to a variable, the range of the variable's data type is checked against the value of the literal and assignment is allowed or compiler will produce an error.

 Choice cBoth I and II are correct.

 Choice dBoth I and II are incorrect.

[6] Which of the following statements are correct? I. We can operate on chars as if they are integers. II. Java has a simple data type boolean for logical values.

 Choice a

Only I is correct.

 Choice b

Only II is correct.

Java has eight primitive data types: four integer types for whole-valued ... logical values (boolean)

 Choice c

Both I and II are correct.

 Choice d

Both I and II are incorrect.

My be..

[7] Which of the following statements are correct? I. boolean data type is returned by all relational operators. II. When a boolean value is output by println( ), 1 or 0 gets displayed.

Page 3: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSS Choice a

Only I is correct.

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.

 Choice d

Both I and II are incorrect.

[8] Which of the following statements are correct? I. Floating-point numbers are used when evaluating expressions that require fractional precision. II. Java implements the standard set of floating-point types and operators.

 Choice a

Only I is correct.

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.

Floating-point numbers, also known as real numbers, are used when evaluating expressions that require fractional precision. For example, calculations such as square root, or transcendentals such as sine and cosine, result in a value whose precision requires a floating-point type. Java implements the standard (IEEE–754) set of floatingpoint types and operators. There are two kinds of floating-point types, float and double, which represent single- and double-precision numbers, respectively. Their width and ranges are shown here:

 Choice d

Both I and II are incorrect.

[9] Which of the following statements are correct? I. In Java an int is always 32 bits regardless of the particular platform. II. Java supports unsigned, positive-only integers.     

 Choice a

Only I is correct.

 Choice b

Only II is correct.

ava defines four integer types: byte, short, int, and long. All of these are signed, positive and negative values. Java does not support unsigned, positive-only integers

 Choice c

Both I and II are correct.java's portability requirement, all data types have a strictly defined range. An int is always 32 bits, regardless of the particular platform

 Choice d

Both I and II are incorrect.

[10] Which of the following statements are correct? I. The type float specifies a single-precision value that uses 64 bits of storage. II. Java uses Unicode to represent characters.

Page 4: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSS Choice a

Only I is correct.

 Choice b

Only II is correct.

n the Java programming language char values represent Unicode characters. Unicode is a 16-bit character encoding that supports the world's major languages

he type float specifies a single-precision value that uses 32 bits of storage. Single precision is faster on some processors and takes half as much space as double precision, but will become imprecise when the values are either very large or very small. Variables of type float are useful when you need a fractional component, but don't require a large degree of precision. For example, float can be useful when representing dollars and cents.

 Choice c

Both I and II are correct.

 Choice d

Both I and II are incorrect.

[11] Which of the following statements are correct? I. In Java, variables of type int are commonly employed to control loops and to index arrays. II. Any time we have an integer expression involving bytes, shorts, ints and literal numbers, the entire expression is promoted to int before the calculation is done.

 Choice a

Only I is correct.

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.he most commonly used integer type is int. It is a signed 32-bit type that has a range from –2,147,483,648 to 2,147,483,647. In addition to other uses, variables of type int are commonly employed to control loops and to index arrays. Any time you have an integer expression involving bytes, shorts, ints, and literal numbers, the entire expression is promoted to int before the calculation is done.

 Choice d

Both I and II are incorrect.

[12] Which of the following statements are correct? I. The Java compiler checks all expressions and parameters to ensure that the types are compatible. II. In Java, we can assign a floating-point value to an integer.

 Choice a

Only I is correct.

he Java compiler checks all expressions and parameters to ensure that the types are compatible. Any type mismatches are errors that must be corrected before the compiler will finish compiling the class.

When we assign a floating-point value to an integer type, the

Page 5: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSSfractional part, if any, is dropped (not rounded) and the resulting integer value is assigned. It is up to us to ensure that the integer obtained is small enough to fit in the integer type. If not, the resulting value is unpredictable.

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.

 Choice d

Both I and II are incorrect.

[13] Which of the following statements are correct? I. In Java, char is 8-bit type. II. We have negative chars in Java.

 Choice a

Only I is correct.

n Java, the data type used to store characters is char. However, C/C++ programmers beware: char in Java is not the same as char in C or C++. In C/C++, char is an integer type that is 8 bits wide. This is not the case in Java. Instead, Java uses Unicode to represent characters. Unicode defines a fully international character set that can represent all of the characters found in all human languages

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.

 Choice d

Both I and II are incorrect.

[14] Which of the following statements are correct? I. Java manages the meaning of the high-order bit by adding an unsigned right shift operator. II. The Java run-time environment is free to use whatever size it wants, as long as the types behave as user declared them.

 Choice a

Only I is correct.

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.

Java manages the meaning of the high-order bit differently, by adding a special "unsigned right shift" operator. Thus, the need for an unsigned integer type was eliminated.The Java run-time environment is free to use whatever size it wants, as long as the types behave as you declared them. In fact, at least one implementation stores bytes and shorts as 32-bit (rather than 8- and 16-bit) values to improve performance, because that is the word size of most computers currently in use.

 Choice d

Both I and II are incorrect.

[15] Which of the following statements are correct? I. In Java, an integer

Page 6: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSSliteral cannot be assigned to a long variable. II. To specify a long literal, user needs to explicitly tell the compiler that the literal value is of type long by appending an upper or lowercase L to the literal.

 Choice a

Only I is correct.

 Choice b

Only II is correct.Values of the integral types byte, short, int, and long can be created from int literals. Values of type long that exceed the range of int can be created from long literals. Integer literals can be expressed these number systems:

However, to specify a long literal, you will need to explicitly tell the compiler that the literal value is of type long. You do this by appending an upper- or lowercase L to the literal. 

 Choice c

Both I and II are correct.

 Choice d

Both I and II are incorrect.

[16] Which of the following statements are correct? I. The relational operators determine the relationship that one operand has to the other. II. The relational operators determine equality and ordering.     

 Choice a

Only I is correct.

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.The relational operators determine the relationship that one operand has to the other. They determine the equality and ordering.

 Choice d

Both I and II are incorrect.

[17] Which of the following statements are correct? I. The outcome of a left shift on a byte or short value will be long. II. When a negative byte or short value is promoted to int, the high-order bits will be filled with 0’s.

 Choice a

Only I is correct.

 Choice b

Only II is correct.This means that the outcome of a left shift on a byte or short value will be an int, and the bits are not lost until they are past positionFurthermore, a negative byte or short value will be sign-extended when it is promoted to int. Thus, the high-order bits will be filled with 1's

 Choice c

Both I and II are correct.

Page 7: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSS Choice d

Both I and II are incorrect.

[18] Which of the following statements are correct? I. The bitwise operators act upon the individual bits of their operands. II. The bitwise operators manipulate the bits within an integer.     

 Choice a

Only I is correct.

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.Bitwise Operators act upon the individual bits of their operands.Since the Bitwise operators manipulate the bits within an integer, it is important to understand what effects such manipulations may have on a value.

 Choice d

Both I and II are incorrect.

[19] Which of the following statements are correct? I. To perform a left shift on a byte or short implies that we must not discard the high-order bytes of the int result. II. If a byte value is left-shifted that value will first be promoted to int and then shifted.

 Choice a

Only I is correct.

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.

to perform a left shift on a byte or short implies that you must discard the high order bytes of the int resultif you left-shift a byte value, that value will first be promoted to int and then shifted. This means that you must discard the top three bytes of the result if what you want is the result of a shifted byte value

 Choice d

Both I and II are incorrect.

[20] Which of the following statements are correct? I. When the division operator is applied to an integer type, there will be a fractional component attached to the result. II. In Java, modulus operator cannot be applied to floating-point types.

 Choice a

Only I is correct.when the division operator is applied to an integer type, there will be no fractional component attached to the result.

 Choice b

Only II is correct.When the modulo operator is applied to floating point types the result might well have a fractional part.the modulus operator, %, return the remainder of a division operation. It can be applied to floating-point types as well as integer types. The following program demonstrates.

Page 8: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSS Choice c

Both I and II are correct.

 Choice d

Both I and II are incorrect.

[21] Which of the following statements are correct? I. if statement is Java’s conditional branch statement. II. if statement is used to route program execution through two different paths.

 Choice a

Only I is correct.

 Choice b

Only II is correct.

 Choice c

Both I and II are correct.

 Choice d

Both I and II are incorrect.

[22] Which of the following selection statements are supported by Java? I. if II. switch III. Macro

 Choice a

Only I and II may be

 Choice b

Only I and III

 Choice c

Only II and III

 Choice d

I, II and III

 

[23]

What will be the output of the code snippet given below?

public class Main {public static void main ( String[ ] args ) {char ch = 296 ;    System.out.println ( ( int ) ch + " " + ch ) ;}}

 Choice a

40 character corresponding to it

 Choice b

296 character corresponding to 128

 Choice c

296 character corresponding to it output I s296?

 Choice d

40 character corresponding to 255

Page 9: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSS 

[24] What will be the output of the code snippet given below?

public class Main {public static void main ( String[ ] args ) {char ch1, ch2 ;ch1 = 88 ; ch2 = 'Y' ;System.out.println ( ch1 + " " + ch2 ) ;}}

 Choice a

X Y

 Choice b

88 Y

 Choice c

88 89

 Choice d

X 89

 [25] Which of the following statement is correct about the code snippet given

below?

public class Main {public static void main ( String[ ] args ) {int i = 400 * 400 / 400 ;if ( i == 400 )System.out.println ( "In if" ) ;elseSystem.out.println ( "In else" ) ;}}

 Choice a

The code reports an error.

 Choice b

The code causes an exception     

 Choice c

The code gives an output as In if.

 Choice d

The code gives an output as In else

[26] What will be the output of the code snippet given below?

public class Main {public static void main ( String[ ] args ) {int x ; x = 10 ;

Page 10: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSSif ( x == 10 ) { int y = 20 ; System.out.println ( x + " " + y ) ;x = y * 2 ;}System.out.println ( x ) ;}}

 Choice a

10 2010

 Choice b

10 2040

 Choice c

40 2040

 Choice d

20 2010

 

27]

What will be the output of the code snippet given below?

public class Main { public static void main ( String[ ] args ) {double pi, r, a ;r = 10.8 ;pi = 3.1416 ;a = pi * r * r ; System.out.println ( a ) ;}}

 Choice a

366.436224

 Choice b

366.44

 Choice c

366.43

 Choice d

366.430000

 

[28] What will be the output of the code snippet given below?

public class Main {public static void main ( String[ ] args ) 

Page 11: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSS{double a = 3.0, b = 4.0 ;double c = Math.sqrt ( a * a + b * b ) ;System.out.println ( c ) ;}}

 Choice a

5.00

 Choice b

5

 Choice c

5.0

 Choice d

5.000000

[29] What will be the output of the code snippet given below?

public class Main {public static void main ( String[ ] args ) {int x = 5, y = 6, z = 7, w = 8, p = x++ * y++ / z++ * ++w, q = x++ * ++y * ++z / p * w++, r = x-- * y-- * --z / --q ;System.out.println ( x + " " + y + " " + z + " " + w + " " + p + " " + q + " " + r ) ;}}

 Choice a

6 7 8 10 36 107 4

 Choice b

5 6 7 8 36 107 4

 Choice c

6 7 8 10 37 108 5

 Choice d

5 6 7 8 37 108 5

[30] Which of the following statement is correct about the code snippet given below?

public class Main {public static void main ( String[ ] args ) {double d = -10.0 / 0.0 ;if ( d == Double.NEGATIVE_INFINITY )System.out.println ( d ) ;}}

 Choice a

The code reports an error.

 Choi The code causes an exception

Page 12: Enterprise Solutions Using J2EE

Enterprise solutions using J2EE SSSce b

 Choice c

The code gives an output as 0.

 Choice d

The code gives an output as -Infinity