JAVA OFFICIAL, Java CH 3, java ch 4, Java CH 2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

In UML diagrams, what symbol indicates that a member is public?

+

GM_02_15. Which of the following is valid?

. float w; w = 1.0f;

When saving a Java source file, save it with an extension of:

.java

x = 10; x = x+1; System.out.println(x);

11

Which of the following are not valid Java identifiers

2015Taxes

How many accessibility modifiers are there in Java

3

x=10; x=x+1; (x+x+x)

33

GM_02_21. What will be the value of z as a result of executing the following code? int x = 5, y=28; float z; z = (float) (y/z);

5.0

How many bits are in a byte?

8

A Java program must have at least one of these:

Class definitionp

Which one of the following would contain the translated Java byte code for a program named Demo?

Demo.class

Spring_2015_ch02_q03. The following four lines of code System.out.print("Hell"); System.out.print("o"); System.out.print("world"); System.out.println("!!"); would:

Helloworld!!

Which of the following are false

Java has four floating-point data types

GM_02_44. Which of the following is a valid Java statement?

String str = "John Doe";

What would be displayed as a result of the following code? int x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house");

There are 5785 hens in the hen house.

To display the output on the next line, you can use the println method or use this escape sequence in the print method.

\n

A computer program is

a set of instructions that enable the computer to solve a problem or perform a task. Correct

RAM is usually

a volatile type of memory, used only for temporary storage. Correct

Which of the following is false:

a. 3.0E4 is a whole number (i.e. no fractional part) Correct

Which of the following are false

a. An integer literal is a variable than can only hold whole numbers such as 5, 10, 23, 89, etc Correct

GM_02_13. In Java, it is standard practice to capitalize the first letter of:

a. Class names. Correct

GM_02_50. Which one of the following methods would you use to convert a string to a double?

a. Double.ParseDouble Correct

When the + operator is used with strings, it is known as the:

a. String concatenation operator. Correct

Blank lines and spaces

a. are inserted by the programmer in order to make the program easier to read

Which ones of the following are not valid names for a Java class:

a. my class Correct

A constructor is a method that

a. performs initialization or setup operations. Correct

When you type the command: java Simple

a. the file Simple.class must exist in the current working directory Correct

Given the following variable declaration: int x; Which of the following is true

a. you can only assign a value of any type compatible with int to x Correct

"Attributes" is another word for the data stored in an object

always

The operations that a method can perform are called "methods"

always

If person is a variable declared to be be of type String, then the value it holds will be:

an address in memory

What is the following statement an example of? improt java.util.Scanner;

an explicit import statement

What does the following code print? System.out.print("anna's \name is \none?"); Select one:

anna's ame is one?

Because Java byte code is the same on all computers, compiled Java programs

are highly portable. Correct

GM_02_11. Which of the following is not a rule that must be followed when naming identifiers?

b. Identifiers can contain spaces. Correct

Which of the following does not describe a valid comment in Java?

b. Multi-line comments, start with */ and end with /* Correct

If the following Java statements are executed, what will be displayed? System.out.println("The top three winners are\n"); System.out.print("Jody, the Giant\n"); System.out.print("Buffy, the Barbarian"); System.out.println("Adelle, the Alligator");

b. The top three winners are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator

The file Simple.class is:

b. a file that contains the Java executable code

A java program

b. must have at least one class definition Correct

GM_02_48. Which Scanner class method reads an int?

b. nextInt() Correct

GM_02_17. Character literals are enclosed in ________; string literals are enclosed in ________.

b. single quotes; double quotes Correct

The result of typing javac Simple.java in a directory that contains a file called Simple.java (and assuming you have instaled Java correctly in that machine) is that:

b. the compiler will try to translate the contents of the file Simple.java into Java machine code

When an application is executed

c. the method called main is executed Correct

The term ________ typically refers to the device that displays console output.

d. Standard output device Correct

GM_02_23. In the following Java statement what value is stored in the variable name? String name = "John Doe";

d. The memory address where "John Doe" is located

When you write a comment in a Java program using //

d. all the characters between // and the end of that line are ignored by the compiler

GM_02_36. Given the declaration double r;, which of the following statements is invalid?

d. r = 2.9X106; Correct

. In he following example: public class Simple { public static void main(String[] args){ int x; x = 120; x = 5; System.out.println(x); } }

d. the word Simple is the the name of the class

What would the following code print System.out.print("this is \\\"easy\"");

d. this is \"easy" Correct

Which of the following is not a variable declaration

e. speed = 20; Correct

which of the following are true

every Java application must have one, and only one, method named main

A literal is a named storage location in the computer's memory.

false

A variable is a value that is written into the code of a program.

false

All lines in a Java program must end with semicolon

false

GT_02_01. A Java program will not compile unless it contains the correct line numbers.

false

GT_02_03. Java is a case-insensitive language.

false

GT_02_09. Class names and key words are examples of variables.

false

Many classes can be created from a single object

false

Primitive data types, such as int, are capable of storing data and also have methods associated to them (e.g. transform Strings into integers).

false

Reference variables are used to store primitive data type values

false

The method length() is a method of int that returns an integer value that is equal to the length of the string

false

When you write a program in an object-oriented programming language you need to write the objects the program is made of.

false

in Java key words are words or names that are defined by the programmer

false

public class Payroll { public static void main(String[] args) { int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println("Your gross pay is $" + grossPay); } } the following are keywords: String, double, int, System

false

the code written by the programmer is stored in a file that has .class file extension.

false

the following: System.out.println( message); is not a correct java statament

false

variable names can be key words

false

GOF5eMC_CH03_q17. It is common practice in object-oriented programming to make all of a class's

fields private

You use this key word to import a class.

import

You should not define a class field that is dependent upon the values of other class fields

in order to avoid having stale data.

Another term for an object of a class is a(n) Select one:

instance

When an object is created, the attributes associated with the object are called

instance fields

If the following line of code is executed: int stringLength = cityName.length(); then Select one:

it is impossible to tell what the value of stringLength will be from this single line of code

Before a variable can be used:

it must be declared

variable names can be key words

java ReadIt

Suppose you are at an operating system command line, and you are going to use the following command to compile a program: javac MyClass.java Before entering the command, you must

make sure you are in the same directory or folder where the MyClass.java file is located. Correct

A program must

may or may not have comments

GM_02_42. This is a variable whose content is read only and cannot be changed during the program's execution.

named constant

Objects and Classes are different words for the same thing

never

Which of he following are true

no primitive type is a class

If you define a class as being "private" it means that:

none of these options is correct

A group of related classes is called a(n)

package

This is a set of programming language statements that, together, perform a specific task.

procedure

Software refers to

programs

Byte code instructions are

read and interpreted by the JVM. Correct

An object in an object-oriented programming language such as Java is able to:

store information in fields and perform operations called methods

Variables are

symbolic names made up by the programmer that represents locations in the computer's RAM.

If a .java file has a public class, then the following is true:

the class must have the same name as the file. Correct

The body of the class is

the code that defines the class

Consider the following code: String str = "Charleston"; after executing this line of code:

the variable str does not hold the value "Charleston"

What happens if the following code is executed: int x; x = 100; int xLength = x.length();

this code will not compile

A compiler is a program that translates source code into an executable form.

true

GT_02_07. A variable's scope is the part of the program that has access to the variable.

true

GT_02_11. If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.

true

In java a String can store data and perform operations on that data

true

The Java compiler translates a Java source file into a file that ends with the .class file extension.

true

a variable is a name that represents a location in memory

true

in the following program: public class Payroll { public static void main(String[] args) { int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println("Your gross pay is $" + grossPay); } } the following are key words: public, static, class, void

true

programmer defined names are also called identifiers

true

programmer defined names cannot be also key words

true

the following Java statement is used to assign (or store) the value 40 in a variable called hours: int hours = 40;

true

Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by

using the private access specifier on the class fields.

x=10 x=x+1 ("value: " +x+x+x);

value: 111111

GM_02_34. The primitive data types only allow a(n) ________ to hold a single value.

variable

The output of a Java program is:

what the program writes on the screen when it runs

Key words are

words that have a special meaning in the programming language. Correct

Which of the following is not involved in finding the classes when developing an object-oriented application?

write the code


Ensembles d'études connexes

Pharmacology: Chapter 49 Key terms, Notes, PrepU

View Set

Unit 3 Multiple Choice Question (Hopefully) Full Set

View Set

Solving Equations using Properties of Logarithms

View Set

chapter 19-36 auto technology study guide

View Set

SDSU Econ 102 Exam 3 + Final Cullivan

View Set

cultural final exam back of book questions

View Set

Managerial Accounting: Chapter 6

View Set