Programming Final

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is y after the following statement is executed? x = 0; y = (x>0)? 10: -10;

-10

-24 % 5 is

-2

-15 % -4 is

-3

-15 % 4 is_____

-3

-24 % -5 is

-4

What is the result of 45/4?

11

Given the following method static void nPrint(String message, int n){ while(n>0){ System.out.print(message); n--; } } what is k after involving nPrint(" A message", k)? int k = 2; nPrint("A message", k);

2

A variable or a valu listed in a call to method is called_____

An argument

System analysis seeks to analyze the data flow and to identify the systems input and output. When you do analysis, it helps to identify what the output is first, and then figure out what input data you need in order to produce the output

Analysis

Which of the following statements is true

A java applet can be executed from a Web browser

_______provides an integrated development environment(IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface

Java IDE

__________consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.

Java JDK

Java compiler translates Java source code into_______

Java bytecode

________is a technical definition of the language that includes the syntax and semantics of the Java programming language

Java language specification

_________is a software that interprets Java bytecode

Java virtual machine

Suppose you define a Java class as follows: public class Test{ } In order to compile this program, the source code should be stored in a file named___________

Test.java

In java, the word true is

a Boolean literal

Every statement in java ends with________

a semicolon (;)

Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as __________, which stores elements in last-in-first-out fashion

a stack

_______is a simple but incomplete version of a method

a stub

Java______can run from a Web browser

applets

If you attempt to add an int, a byte, a long, and a double, the result will be a ____value

double

The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as______

encapsulation

To declare a constant MAX_LENGTH inside a method with value 99.98, you write____

final double MAX LENGTH =99.98

To declare a constant PI, you write______

final double PI= 3.14159;

Which of the following assignment statements is illegal?

float f = 34.0;

The speed of the CPU may be measured in______

gigahertz

Programming style is important, because_______

good programming style helps reduce programming errors

To declare an int variable number with initial value 2, you write_____

int number = 2

To declare an int variable x with initial value 200, you write____

int x = 200;

Given the following method static void nPrint(String message, int n){ while(n>0){ System.out.print(message); n--; } } What is the printout of the call nPrint('a',4)"?

invalid call

You use____to run a Java program

java

Which JDK command is correct to run a Java application in ByteCode.class?

java ByteCode

The JDK command to compile in the file Test.java is______

javac Test.java

The command to compile a class in the file Test.java is______

javac Test.java

Variables defined inside a method are called______

local variables

Which of these data types requires the most amount of memory

long

Computer can execute the code in__________

machine language

The signature of a method consists of________

method name and parameter list

Any assignment can be used as an assignment expression

true

If a method does not contain any parameters, you must invoke it with a pair of empty parentheses

true

Java is an object-oriented programming language.

true

Java was originally developed by a team led by James Gosling at Sun Microsystems

true

System.exit(0) can be used to terminate the program

true

The keywords in Java are all in lowercase

true

The public classname must be the same as the filename that contains the class

true

The result of an integer division is the integer part of the division; the fraction part is truncated

true

What is 1 + 1 + 1 + 1 + 1 ==5?

true

What is the value of the following expression? true || true && false

true

You can always assign a value of int type to a variable of long type without loss of information

true

You can always convert a switch statement to an equivalent if statement

true

You may have a return statement in a void method.

true

You must have a return statement in a non-void method

true

you may have a return statement in a void method

true

Suppose your method does not return any value, which of the following keywords can be used as a return type?

void

Given |x-2| <=4, which of the following is true?

x-2 <=4 && x-2 >=-4

Given |x-2| >=4, which of the following is true

x-2 >=4 || x-2<= -4

Analyze the following code int x = 0; int y = ((x<100) && (x >0))? 1: -1;

y becomes -1 after the code is executed

The expression (int)(76.0252175*100)/100 evaluates to

76

one byte has_______bits

8

The "less than or equal to" comparison operator in Java is

<=

The assignment operator in Java is____

=

Which of the following operators are right-associative

=

_________is the java assignment operator

=

The equal comparison operator in Java is

==

_______is the brain of the computer

A CPU

Which of the following are storage devices

all of the above

Which of the following expressions evaluates to true?

'a' > 'A'

Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative

((x<100) && (x>1)) || (x<0)

Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?

((x<100) && (x>1)) || (x<0)

Which of the following statements are the same? (A) x -= x+4 (B) x = x + 4 - x (C) x = x - (x +4)

(A) and (C) are the same

Which of the following is the best for generating random integer 0 or 1?

(int)(Math.random() + 0.5)

Which of the following lines is not a java comment?

**comment** --comments

The order of the precedence (from high to low) of the operators binary +, *, &&, ||, & is

*, +, &, &&, ||

The extension name of a Java bytecode file is______

.class

The extension name of java source code file is____

.java

-5 % 5 is

0

25 % 1 is______

0

5 % 1 is______

0

5 % 5 is

0

Suppose x = 0 and y = 0. What is x after evaluating the expression (y>0) && (1>x++)?

0

Suppose x is 1. What is x after x -=1?

0

What is (int)Math.random()?

0

5 % 4 is ______

1

What is 1 % 2?

1

Math.pow(4, 1/2) returns______

1.0

Suppose x =10 and y =10. What is x after evaluating the expression (y >10) && (x++>10)?

10

Supposed x=10 and y = 10. What is x after evaluating the expression (y>10) && (x-->10)?

10

Which of the following are the reserved words?

all of the above

Math.pow(4, 1.0/2) returns______

2.0

What is the value of (double) 5/2?

2.5

The expression 4 + 20/(3-1)*2 is evaluated to

24

Supposed x is 1. What is x after x + =2?

3

What is x after evaluating the following? x = (2>3) ? 2:3

3

Four bytes have_____bits

32

Which of the following expression results in a value 1?

37 % 6

24 % 5 is

4

Which of the following are not valid assignment statements>

55 = x

(Int)('a' + Math.random() * ('z'-'a' + 1)) returns a random number

Between(int)'a' and (int)'z'

Analyze the following code. I. public class Test { public static void main(String[] args){ System.out.println("Welcome to Java!"); } } II. public class Test { public static void main(String[] args) {System.out.println("Welcome to Java!");}}

Both I an II can compile and run and display Welcome to Java, but the code in II has a better style than I.

Which of the following statements is correct?

Every statement in a program must end with a semicolon

_________is the physical aspect of the computer that can be seen

Hardware

Which of the following code has the best style? I. public class Test{ public static void main(String[] args){ System.out.println("Welcome to Java!"); } } II. public class Test{ public static void main(String[] args){ System.out.println("Welcome to Java!"); } } III. public class Test{ public static void main(String[] args){ System.out.println("Welcome to Java!"); } } IV. public class Test{ public static void main(String[] args){ System.out.println("Welcome to Java!"); } }

IV

__________is an object-oriented programming language.

Java

_________is interpreted

Java

_______is Architecture-Neutral

Java

_________contains predefined classes and interfaces for developing Java programs.

Java API

What is k after the following block executes? { Int k = 2; NPrint("a message", k); } System.out.println(k);

K is not defined outside the block. So, the program has a compile error

Which of the following is a constant, according to Java naming conventions?

MAX_VALUE

pow is a method in the ____class

Math

The ______method returns a raised to the power b

Math.pow(a,b)

Java allows you to declare methods with the same name in a class. This is called_____

Method overriding

____is a device to connect a computer to a local area network (LAN)

NIC

Does the method call in the following method cause compile errors? public static void main(String[] args){ Math.pow(2,4); }

No

Does the return statement in the following method cause compile errors? public static void main(String[] args){ int max = 0 if(max! = 0) system.out.println(max); else return; }

No

__________is a program that runs on a computer to manage and control a computer's activities

Operating System

Variables defined in the method header are called_____

Parameter

Arguments to methods allows appear within_____

Parentheses

_________are instructions to the computer

Programs

____________is the code with natural language mixed with Java code

Pseudocode

_______are secondary storage

RAM

Java was developed by______

Sun Microsystems

The____method immediately terminates the program

System.exit(0);

Which of the following statements is correct to display Welcome to Java on the console?

System.out.println(Welcome to Java");

Analyze the following code. public class Test{ public static void main(String[] args){ System.out.println(max(1,2)); } Public static double max(int num1, double num2){ System.out.println("max(int,double) is invoked"); If(num1>num2) Return num1; Else Return num2; } Public static double max(double num1, int num2){ System.out.println("max(double, int) is invoked"); If (num1>num2) Return num1; Else Return num2; } }

The program cannot compile because you cannot have the print statement in a non-void method.

Analyze the following code: public class Test{ public static void main(String[] args){ System.out.println(xMethod(5, 500L)); } public static int xMethod(int n, long 1){ System.out.println("int, long"); return n; } public static long xMethod(long n, long 1){ System.out.println("long, long"); return n; } }

The program displays int, long followed by 5

Analyze the following code: class Test { public static void main(String[] args) { System.out.println(xmethod(5)); } public static int xmethod(int n, long t) { System.out.println(ʺintʺ); return n; } public static long xmethod(long n) { System.out.println(ʺlongʺ); return n; } }

The program displays long followed by 5

Analyze the following code. public class Test { public static void main(String[] args) { System.out.println(m(2)); } public static int m(int num) { return num; } public static void m(int num) { System.out.println(num); } }

The program has compile error because the two methods m have the same signature

_____is to implement one method in the structure chart at a time from the top to the bottom

Top-down approach

A call for the method with a void return type is always a statement itself, but a call for the method with a non-void return type can be treated as either a statement or an expression

True

A method can be declared with no parameters

True

Methods can be declared in any order in a class

True

The actual parameters of a method must match the formal parameters in type, order, and number

True

The modifiers and return value type do not contribute toward distinguishing one method from another, only the parameter list

True

You can define two methods in the same class with the same name and parameters list

True

Which of the following is not an advantage of using methods?

Using methods makes programs run faster

A______mehod does not return a value

Void

public class Test { public static void main(String[] args) { System.out.print(ʺThe grade is ʺ + getGrade(78.5)); System.out.print(ʺ\nThe grade is ʺ + getGrade(59.5)); } public static ________ getGrade(double score) { if (score >= 90.0) return ʹAʹ; else if (score >= 80.0) return ʹBʹ; else if (score >= 70.0) return ʹCʹ; else if (score >= 60.0) return ʹDʹ; else return ʹFʹ; }

Void

A return statement without any values can be used in______

Void method

________is an operating system

Windows XP

Are the following four statements equivalents? number += 1; number=number +1, number++; ++number;

Yes

If you forget to put a closing quotation mark on a string, what kind error will be raised?

a compilation error

__________translates high-level language program into machine language program

a compiler

a variable that is declared inside a method is called__________variable

a local

A variable defined inside a method is referred to as_________

a local variable

If a program compiles fine, but it produces incorrect result, then the program suffers______

a logic error

Why do computers use zeros and ones?

because digital devices have two stable states and it is natural to use one state for 0 and the other for 1

(char)('a' + Math.random()*('z' - 'a' + 1)) returns a random character

between 'a' and 'z'

(int)(Math.random()*(65535+1)) returns a random number_________

between 0 and 65535

A block is enclosed inside______

braces

Which of theses data types requires the least amount of memory

byte

The________loads Java bytecode to the memory

class loader

To improve readability and maintainability, you should declare_____instead of using literal values such as 3.14159

constants

A java interpreter is a program that translates Java source code into Java bytecode

false

A variable may be assigned by a value only once in the program

false

Each Java class must contain a main method

false

In a switch statement, the default case must appear last among all cases. Otherwise, it would result in a compilation error

false

Java source code can be executed on a Java Virtual Machine

false

The assignment operator = is left-associative

false

The break keyword must be used in a switch statement; otherwise, a syntax error occurs.

false

The compiler generates bytecode even if the program has syntax errors

false

The default case must be specified in a switch statement

false

The exclusive or (^) of true and true is true

false

The signature of a method consists of the method name, parameter list and return type

false

You can always assign a value of long type to a variable of int type without loss of precision

false

You can cast a Boolean value to an int, or an int to a Boolean

false

You can define a constant twice in a block

false

You can define a variable twice in a block

false

You can redeclare the variable if it is declared in the method signature

false

a method can be defined inside a method in Java

false

Which of the following code displays the area of a circle if the radius is positive?

if (radius >0) System.out.println(radius * radius * 3.14159);

Suppose isPrime is a boolean variable which of the following is the correct and best statement for testing if isPrime is true?

if(isPrime)

Suppose cond1 and cond2 are two Boolean expressions. When will this if condition be true? if (cond1 && cond2)....

in case cond1 is true and cond2 is true

When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as________

pass by value

All java applications must have a method_____

public static void main(String[] args)

The main method header is written as______

public static void main(String[] args)

_________is a formal process that seeks to understand the problem and document in detail what the software system needs to do

requirements specification

A java statement ends with a

semicolon

The compiler checks______

syntax errors

The conditional operator? : is a

ternary operator

The System.currentTimeMillis() returns______

the current time in milliseconds since midnight, January 1, 1979 GMT (the Unix time)

A java application must have a main method

true

A java program block starts with an open brace ({) and ends with a closing brace (})

true

A variable must be declared before it can be used

true

You should fill in the blank in the following code with __. public class Test { public static void main(String[] args) { System.out.print("The grade is "); printGrade(78.5); System.out.print("The grade is "); printGrade(59.5); } public static __________ printGrade(double score) { if (score >= 90.0) { System.out.println('A'); } else if(score>= 80.0){ System.out.println('B'); } else if(score>= 70.0){ System.out.println('c'); } else if(score>= 60.0){ System.out.println('D'); } else{ System.out.println('F'); } } }

void

Which of the following should be defined as a void method?

write a method that prints integers from 1 to 100

Assume x = 4, which of the following is true?

x ! = 5

Assume x = 4 and y = 5 which of the following is true

x !=4 ^ y ==5

Assume x = 4 and y = 5, which of the following is true

x < 5 || y < 5

To assign a double variable d to a float variable x, you write____

x = (float)d;

to assign a value 1 to variable x, you write___

x = 1

What is x after the following statements int x = 1; x * = x+1;

x is 2

What is x after the following statements? int x = 2; int y = 1; x *= y + 1;

x is 4


संबंधित स्टडी सेट्स

Map scales and generalization concepts

View Set

code of honor - chapters 9-16 - novel study

View Set

Interpersonal Communications - Chapter 12: Empathy and Assertive Behavior

View Set

Chapter 14 - Transportation in a Supply Chain

View Set