Programming Essentials (Ch 1-4)

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

What is 'data hiding'?

Data hiding refers to an object's ability to hide its data from code that is outside the object. Only the objects methods may then directly access and make changes to the object's data.

What does the following symbol mean? /

Division, this is a binary operator.

What does the following escape sequence and control character do? \"

Double quote, it causes a double quotation mark to be printed.

What is an 'instance'?

Each object that is created from a class is called an instance in the class.

What is 'encapsulation'?

Encapsulation refers to the combining of data and code into a single object.

What does this relational operator mean? ==

Equal to

What type of files contain machine language instructions?

Executable files, they can be executed directly by the computer's CPU.

This programming language is designed for programming complex mathematical algorithms.

FORTRAN (Formula Translator)

If one of an operator's operands is a double, and the other operand is int, Java will automatically convert the value of he double to an int, true or false?

False

Variable names may begin with a number, true or false?

False

What is the range that a 'float' data type holds?

Floating point numbers in the range of +/- 3.4 x 10^-38 to +/- 3.4 x 10^38 with 7 digits of accuracy

What is the range that a 'double' data type holds?

Floating-point numbers in the range of +/- 1.7 x 10^-308 to +/- 1.7 x 10^308 with 15 digits of accuracy

What does this relational operator mean? >

Greater than

What does this relational operator mean? >=

Greater than or equal to

What does the following escape sequence and control character do? \t

Horizontal tab, it causes the cursor to skip over to the next tab stop.

What will the following code segments print on the screen? System.out.print("I am the incredible"); System.out.print ("computing\nmachine"); System.out.print("\nand I will\namaze\n"); System.out.println("you. ");

I am the incrediblecomputing machine and I will amaze you.

What is in an IDE?

IDEs consist of a text editor, compiler, debugger, and other utilities integrated into a package with a single set of menus.

In format specifiers what is .precision?

If the value is a floating-point number, after the minimum field width, you can optionally specify the precision. This is the number of the decimal places the number should be rounded to.

What is a widening conversion?

In assignment statments where values of lower-ranked data types are stored in variables of higher-ranked data types, Java automatically converts the lower-ranked value to the higher-ranked type.

How is the System.out.printf method used?

In most cases you will use this method in the following manner: - The format string will contain one or more format specifiers. - After the format string, one or more additional arguments will appear. Each of the additional arguments will correspond to a format specifier that appears inside the format string.

What is a string literal?

In programming terms, this is a group of characters inside quotation marks. ie. "Hello!"

What is int?

Int stands for integer, variables declared as an int will only hold integer numbers.

What is IDE?

Integrated Development Environment

What is the update expression?

It executes at the end of each iteration. Typically, this is a statement that increments the loop's control variable.

If a flag variable is set to false, what happens?

It indicates the condition does not yet exist.

What is a 'class'?

It is a Java keyword, it must be written in lowercase letters. It indicates the beginning of a class definition.

What is 'public'?

It is a Java keyword, it must be written in lowercase letters. It is know as an access specifier and it controls where the class may be accessed from.

What is 'String'?

It is a class that is provided by the Java API for handling strings. The first step in using the String class is to declare a variable of the String class data type.

What is a while loop?

It is a loop that is executed when the boolean expression that is tested for is a true or false value and a statement or block of statements that is repeated as long as the expression is true. This loop will not run at all if the expression is false.

What is 'out' object?

It is a member of the system class, it provides methods for sending output to the screen.

What kind of decision structure is a swtich statement?

It is a multiple alternative decision structure.

What is 'system' class?

It is a part of the Java API, it has member objects and methods for performing system-level operations, such as sending output to the console.

What is a format specifier?

It is a placeholder for a value that will be inserted into the string when it is displayed.

What is a compiler?

It is a pogram that translates the source code into an executable form.

What is an identifier?

It is a programmer-defined name that represents some element of a program.

What is Unicode?

It is a set of numbers that are used as codes for representing characters.

What is a dialog box?

It is a small graphical window that displays a message to the user or requests input.

What is a running total?

It is a sum of numbers that accumulates with each iteration of a loop.

What is an assignment statement?

It is a variable declaration or variable that has been assigned an initial value. ie. value = 5;

What is a named constant?

It is a variable whose value is read only and cannot be changed during the programs execution.

When do you use a for loop?

It is ideal in situations where the exact number of iterations is known.

When do you use a do-while loop?

It is ideal in situations where you always want the loop to iterate at least once.

When do you use a while loop?

It is ideal in situations where you do not want the loop to iterate if the condition is false from the beginning, it is also ideal if you want to use a sentinel value to terminate the loop.

What is the initialization expression?

It is normally used to initialize a control variable to its starting value.

What is console output?

It is plain text.

What does the following symbol mean? =

It is the assignment operator, the value being assigned must be on the right side of this symbol.

What is narrowing conversion?

It is the conversion of a value to a lower-ranked type.

What is a standard output device?

It is the device that displays console outputs.

What is a data type?

It is the type of data that the variable can hold.

What is // used for?

It is used by programmers for making comments, the compiler will ignore everything after it.

What is a char data type?

It is used to store characters.

What is a cast operator?

It lets you manually convert a value, even if it means narrowing conversion will take place. Cast operators are unary operators that appear as a data type name enclosed in a set of parentheses, the operator precedes the value being converted.

What are semicolons used for?

It marks the end of a statement in Java although not all codes end with a semicolon.

If a flag variable is set to true, what happens?

It means the condition does exist.

Java is a strongly types language, which means?

It only allows you to store values of compatible data types in variables.

What is a variable declaration?

It tells the compiler the variables name and the type of data it will hold.

How does the while loop work?

It works like an if statement that executes over and over. As long as the expression in the parentheses is true, the conditionally executed statement or block will repeat.

What is compareTo?

It's a method to compare two strings, the string are compared character by character. This is also known as a lexicographical comparison.

How do you create a dialog box?

JOptionPane class is not automatically available to your java program. import javax.swing.JOptionPane To display the dialog box use this method: JOptionPan.showMessageDialog (null, "Hello World");

Byte code instructions are not executable so they must be run using a?

JVM (Java Virtual Machine)

Who created Java?

James Gosling

This object-oriented programming language was invented at Sun Microsystems and is now owned by Oracle. It may be used to develop stand-alone applications that operate on a single computer application that run over the Internet from a Web server, and applets that run in a Web browser.

Java

What is JDK?

Java Development Kit

What is Java EE?

Java Enterprise Edition, it provides tools for creating large business applications that employ servers and provide services over the Web.

What is Java ME?

Java Micro Edition, it provides a small, highly optimized runtime environment for consumer products such as cell phones, pagers and appliances.

What is Java SE?

Java Standard Edition, it provides all the essential software tools necessary for writing Java applications and applets.

This programming language can be used in a Web site to perform simple operations.

Javascript, despite it's name it is not related to Java.

These are words that have a special meaning in the programming language. They may be used for their intended purposes only, they may also be known as 'reserved words'.

Key Words

What is this called? {

Left Brace or Opening Brace

What does this relational operator mean? <

Less than

What does this relational operator mean? <=

Less than or equal to

Often, the contents of a program are thought of in terms of this.

Lines and Statements

What is a logical operator?

Logical operators connect two or more relational expressions into one or reverse the logic of an expression.

The boolean data type allows you to create variables that?

May hold one of two possible values: true or false.

What does the following symbol mean? %

Modulus, this is a binary operator.

What does the following symbol mean? *

Multiplication, this is a binary operator.

What does this binary logical operator indicate? !

NOT The ! reverses the truth of a boolean expression. If it is applied to an expression that is true, then the operator returns false.

When is a nested loop needed?

Nested loops are necessary when a task performs a repetitive operation and that task itself must be repeated.

What does the following escape sequence and control character do? \n

NewLine, it advances the cursor to the next line for subsequent printing.

Would this boolean expression execute? boolean1 > 10 && < 10

No, it is not a complete expression as it is missing the variable.

Can a boolean expression be tested if it is not in parenthesis?

No, it must be enclosed in parenthesis otherwise it will result in error.

Are braces required in if statements?

No, they are not required. But using braces make statements easier to read.

When an object's data is hidden from outside code, can it be accidentally corrupted?

No, when hidden from outside code and access the data is protected from accidental corruption.

What does this relational operator mean? !=

Not equal to

What does this binary logical operator indicate? ||

OR Connects two boolean expressions into one. One or both expressions must be true for the overall expression to be true.

What was Java originally named?

Oak

How many public classes can be used in a Java file?

One, other classes can be used multiple times.

These are symbols or words that perform operations on one or more operands. An operand is usually an item of data, such as a number.

Operators

This programming language is primarily used for developing Web server applications and dynamic Web pages.

PHP

This programming language is a structured, general-purpose, procedural language designed primarily for teaching programming.

Pascal

This programming language is general-purpose and is widely used on Internet servers.

Perl

What are the main two methods of programming in use today?

Procedural and Object-oriented.

What is a 'procedure'?

Procedures are a set of programming statements that, together, perform a specific task.

Unlike key words, which are part of the programming language, these are words or names that are defined by the programmer. They are used to identify storage locations in memory and parts of the program that are created by the programmer. They may also be called 'identifiers'.

Programmer-Defined Names

What should you write as a guideline before coding a program?

Pseudocode

Most programming languages require the use of these characters. These characters serve specific purposes, such as marking the beginning or ending of a statement, or separating items in a list.

Punctuation

This programming language is object-oriented and is used in both business and academia. Many popular Web sites contain features developed in this language.

Python

What does the following escape sequence and control character do? \r

Return, it causes the cursor to go to the beginning of the current line, not the next line.

What is this called? }

Right Brace or Closing Brace

This programming language is a simple but powerful object-oriented programming language. It can be used for a variety of purposes, from small utility programs to large Web applications.

Ruby

What does the following escape sequence and control character do? \'

Single quote, it causes a single quotation mark to be printed.

What is SDK?

Software Development Kit

Statements written by the programmer are called:

Source Code

How to add input to a dialog box:

String name; name = JOptionPane.showInputDialog("Enter your name."); This will create a dialog box with a text area for input.

What does the following symbol mean? -

Subtraction or negation operator. This is a binary operator.

These are rules that must be followed when writing a program. It dictates how key words and operators may be used, and where punctuation symbols must appear.

Syntax

How do you end the dialog boxes?

System.exit(0); This statement causes the program to end, and is required if you use the JOptionpane class. If this method is not called then the 'thread' will execute continuously.

Describe Ternary.

Ternary operators work with three operands.

What was the original name of the team that developed Java?

The Green Team

What is the standard input device?

The Keyboard

How is charAt(index) used?

The argument index is an int value and specifies a character position in the string. The first character is at positon 0, the second at position 1 and so forth. The method returns the character as the specified positon. ex. char letter; String name = "Herman"; letter = name.charAt(3); letter = 'm'

What are the typical rules of naming an identifier?

The first character must be an upper or lowercase letter, underscore or dollar sign. (but $ signs should be used in special circumstances) After the first character you may use any of the above noted characters as well as numbers. Spaces cannot be used.

What is the loop header?

The first line of the for loop is known as the loop header.

What is a for loop?

The for loop tests for its boolean expression before it performs and iteration, it is a pretest loop.

What is an if statement?

The if statement is used to create a decision structure, which allows a program to have more than one path of execution.

What is an if-else statement?

The if-else statement will execute one group of statements if the boolean or flag expression is true, or another group if its boolean or flag expression is false.

What does postfix mode mean?

The increment and decrement operators are placed after the variable.

What does prefix mode mean?

The increment and decrement operators are placed before the variable.

What is a trailing else?

The last else clause, which does not have an if statement following it, is referred to as the trailing else.

What is a priming lead?

The read operation that takes place just before the loop is called the priming lead.

What is the scope of a variable?

The scope of a variable is limited to the block in which it is declared.

What is a switch statement?

The switch statement lets the value of a variable or expression determine where the program with branch to.

What happens when this statement is executed? --number

The variable number is decreased by one.

What happens when this statement is executed? number --

The variable number is decreased by one.

What happens when this statement is executed? ++number

The variable number is increased by one.

What happens when this statement is executed? number++

The variable number is increased by one.

Programming style refers to:

The way source code is visually arranged. It includes techniques for consistently putting spaces and indentations in a program so visual cues are created. These cues quickly tell a programmer important information about a program.

What are Documentation comments?

These can be read and processed by a program named javadoc, which comes with JDK.

What is a conditional loop?

These loops execute as long as a particular condition exists.

What are character literals?

They are characters enclosed in single quotation marks

What is the 'print' and 'println' methods for?

They are members of the out object, they actually perform the work of writing characters on the screen.

What are the following symbols used for? ( )

They are used in method headers.

What is an exception?

Think of an exception as a signal indicating that the program cannot continue until the unexpected event has been dealt with.

How is the PrintWriter class used?

This class allows you to open a file for writing. It also allows you to write data to the file using the same print and println methods that you use to display data on the screen.

What is the Math.PI constant?

This constant has the assigned value of 3.1415926558979323846, which is an approximation of the mathematical value of pi.

What is the test expression?

This is a boolean expression that controls the execution of the loop. As long as the expression is true, the body of the for loop will repeat.

In pseudocode, what is 'output'?

This is a display of text.

What is an infinite loop?

This is a loop that does not have a way of stopping, it continues to repeat until the program in interrupted.

What is a do-while loop?

This is a posttest loop, which means the boolean expression is tested after each iteration. At least one iteration will occur before the boolean expression is tested.

What is a counter variable?

This is a variable that keeps count of the number of iterations.

What is the following line of code? public static void main (String [] args)

This is known as the method header, it marks the beginning of a method.

In pseudocode what is 'process'?

This is the calculation within coding.

What is a 'class name'?

This is the name made up by the programmer. It can be any word but must be written in lower case, or uppercase, or a mixture of both letters.

What is input validation?

This is the process of inspecting data given to a program by the user and determining whether it is valid.

In pseudocode what is 'purpose'?

This is the reason the program is running.

What is the 'main' method?

This is the starting point of an application.

What is an accumulator?

This is the variable used to keep the running total.

In pseudocode what is 'input'?

This is the variables that are identified within the program by either coding key input that does not appear in the program or by user key input while running the program.

How long will this while loop execute? while (number <= 5);

This loop will forever execute as a null statement, which does nothing and will display nothing.

What does 'Portable' mean?

This means the program may be written on one type of computer but can be run on a wide variety of computers will little to no modification.

How is toLowerCase() used?

This method returns a new string that is the lowercase equivalent of the string contained in the calling object.

How is toUpperCase() used?

This method returns a new string that is the uppercase equivalent of the string contained in the calling object.

What is the String.Format method?

This method works exactly like the system.out.printf method, except that it does not display the formatted string on the screen. Instead, it returns a reference to the formatted string.

What is truncated?

This occurs when the fractional part of a number is lost.

How is [variablename].method() used?

This passes zero or more arguments to the method, if no arguments arepassed to the method, as is the case with the length method, a set of empty parentheses must follow the name of the method.

What is a nested if statement?

This statement is used to test for more than one condition, an if statement can be nested within another if statement.

What does the following statement do in a switch? break;

This statement shows the program where to stop.

How is name.length() used?

This statement stores the length of its string in the variable.

What is an if-else-if statement?

This statement tests a series of conditions. It is often simpler to test a series of conditions with the if-else-if statement than with a set of nested if-else statements.

What is a user controlled loop?

This type of look allows the user to decide the number of iterations.

What is a sentinel value?

This value signals when the end of a list of values has been reached.

What will the following code segments print on the screen? System.out.print("Be careful\n)"; System.out.print("This might/n be a trick "); System.out.println("question. ");

This would not compile, 1st line has the quotation marks in the incorrect position and the 2nd line has /n instead of \n for new line.

A left brace in a Java program is always followed by a right brace later in the program, true or false?

True

A variable must be declared before it can be used, true or false?

True

Comments that begin with // can be processed by javadoc, true or false?

True

You cannot change the value of a variable whose declaration uses the final key word, true or false?

True

What is a console?

Typically the console is referred to as a computer system, or screen and keyboard.

Describe a Unary.

Unary operators require only a single operand.

This is a names storage location in the computer's memory. The data stored here may change while the program is running.

Variable

What is used to verify if the expected values match the actual values after you have coded a program?

Variable Table, this should be accompanied by the pseudocode.

What are local variables?

Variables that are declared inside the method are called local variables.

This is a Microsoft programming language and software development environment that allows programmers to create Windows-based applications quickly.

Visual Basic (VBA)

What are reference variables?

When a class type variable holds the address of an object, it is said that the variable references the object. For this reason, class type variables are commonly known as reference variables.

What is a sequence structure?

When statements are executed in a sequence, without branching off in another direction.

What is a keystroke buffer?

When the user types keystrokes at the keyboard, those keystrokes are stored in an area of the memory that is sometimes called the keyboard buffer.

Can a text editor or word processing program be used to edit a java file?

Yes as they can be used as editors.

Can you use relational operators to test character data?

Yes, as letters and numbers have an assigned value, they can be evaluated for equality.

Is it possible to use multiple statements in the initialization and update expressions for a for loop?

Yes, it is possible to execute more than one statement in initialization expression and the update expression. When using multiple statements in either of these expressions, simply separate the statements with commas.

Is Java a case-sensitive language?

Yes, it regards upper case letters as being entirely different characters than their lowercase counterparts. Some words in Java must be written entirely in lowercase.

Can you declare a control variable in the for loop?

Yes, not only may the control variable be initialized in the initialization expression, but it also may be declared there.

Can you create a user control in a for loop?

Yes, sometimes you want the user to determine the maximum value of the control variable in a for loop, and therefore determine the number of times the loop iterates.

Can data be passed from one procedure to another?

Yes, the data items are commonly passed from one procedure to another.

Can multiple format specifiers be used in the same statement?

Yes, they can be linked together with commas. ie. double value1 = 3.0; double value2 = 6.0; double value3= 9.0; System.out.printf("%f %f %f\n", value1, value2, value3); Output: 3.000000 6.000000 9.000000

Are Java programs 'portable'?

Yes, they care considered highly portable.

If you run the compiler in CMD.exe will you see syntax errors?

Yes, they will be provided as error messages.

What is the difference between == and the equals method to compare string objects?

You cannot use the == operator to compare the contents of a String object with another string. Instead you must use the equals or compareTo method.

When determining whether a number is inside a range, it is best to use this operator. a) && b) ! c) || d) ? :

a) &&

These characters mark the beginning of a single-line comment. a) // b) /* c) */ d) /**

a) //

You can use this class to display dialog boxes. a) JOptionPane b) BufferedReader c) InputStreamReader d) DialogBox

a) JOptionPane

To open a file for writing, you use the following class. a) PrintWriter b) FileOpen c) OutputFile d)FileReader

a) PrintWriter

Each byte is assigned a unique a) address b) CPU c) bit d) variable

a) address

A group of statements, such as the contents of a class or method, are enclosed in ...? a) braces { } b) parentheses ( ) c) brackets [ ] d) any of these will do

a) braces

This type of operator lets you manually convert a value, even if it means that a narrowing conversion will take place. a) cast b) binary c) uploading d) dot

a) cast

This is a boolean variable that signals when some condition exists in the program. a) flag b) signal c) sentinel d) siren

a) flag

This expression is executed by the for loop only once, regardless of the number of iterations. a) initialization expression b) test expression c) update expression d) pre-increment expression

a) initialization expression

This is a variable that controls the number of iterations performed by a loop. a) loop control variable b) accumulator c) iteration register variable d) repetition meter

a) loop control variable

This is an if statement that appears inside another if statement. a) nested if statement b) tiered if statement c) dislodged if statement d) structured if statement

a) nested if statement

Which Scanner class method would you use to read a double as an input? a) nextDouble b) getDouble c) readDouble d) None of these; you cannot read a double with the Scanner class.

a) nextDouble

The for loop is this type of loop. a) pretest b) posttest c) prefix d) postfix

a) pretest

The while loop is this type of loop. a) pretest b) posttest c) prefix d) postfix

a) pretest

These characters serve specific purposes, such as marking the beginning and ending of a statement, or separating items in a list. a) punctuation b) programmer-defined names c) key words d) operators

a) punctuation

>, < and == are ....? a) relational operators b) logical operators c) conditional operators d) ternary operators

a) relational operators

This is a special value that signals when there are no more items from a list of items to be processed. this value cannot be mistaken as an item from the list. a) sentinel b) flag c) signal d) accumulator

a) sentinel

These are rules that must be followed when writing a program. a) syntax b) punctuation c) key words d) operators

a) syntax

An else clause always goes with ...? a) the closest previous if clause that doesn't already have its own else clause b) the closest clause c) the if clause that is randomly selected by the compiler d) none of these

a) the closest previous if clause that doesn't already have it's own else clause

The negation operator is ...? a) unary b) binary c) ternary d) none of these

a) unary

Which of the following are not valid println statements? (indicate all that apply) a) System.out.println + "Hello World"; b) System.out.println("Have a nice day"); c) out.System.println(value); d) println.out(Programming is great fun);

a,c and d are not valid, a println statement should appear as: System.out.println("Text to appear");

Which of the following are not valid assignment statements (Indicate all that apply) a) total = 9; b) 72 = amount; c) profit = 129 d) letter = 'W';

b and c are not valid statements, the variable must be on the left of the = and the variable must be closed off with a semicolon.

How does the character 'A' compare to the character 'B'? a) 'A' is greater than 'B' b) 'A' is less than 'B' c) 'A' is equal to 'B' d) you cannot compare characters

b) 'A' is less than 'B'

These characters mark the beginning of a multi-line comment. a) // b) /* c) */ d) /**

b) /*

What will the println statement in the following program segment display? int x = 5; System.out.println(x++); a) 5 b) 6 c) 0 d) none of these

b) 5

What will the println statement in the following program segment display? int x = 5; System.out.println(++x); a) 5 b) 6 c) 0 d) None of these

b) 6

This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some outcome or resultant information. a) memory b) CPU c) secondary storage d) input device

b) CPU

This class allows you to read a line from a file. a) FileWriter b) Scanner c) InputFile d) FileReader

b) Scanner

If you were to look at a machine language program, you would see....? a) Java source code b) a stream of binary numbers c) English words d) circuits

b) a stream of binary numbers

This type of program is designed to be transmitted over the Internet and run in a Web browser. a) application b) applet c) machine language d) source code

b) applet

The Java compiler generates...? a) machine code b) byte code c) source code d) HTML

b) byte code

When a program is finished using a file, it should do this. a) erase the file b) close the file c) throw an exception d) reset the read position

b) close the file

The if statement is an example of a ....? a) sequence structure b) decision structure c) pathway structure d) class structure

b) decision structure

This section of a switch statement is branched to if none of the case expressions match the switch expression. a) else b) default c) case d) otherwise

b) default

The following data are examples of? 72 'A' "Hello World" 2.8712 a) variables b) literals c) strings d) none of these

b) literals

&&, || and! are ...? a) relational operators b) logical operators c) conditional operators d) ternary operators

b) logical operators

Which Scanner class method would you use to read a string as input? a) nextString b) nextLine c) readString d) getLine

b) nextLine

The do-while loop is this type of loop. a) pretest b) posttest c) prefix d) postfix

b) posttest

Which of these two print methods print to a separate line when used? a) print b) println

b) println although with extra coding print could be used.

These are words or names that are used to identify storage locations in memory and parts of the program that are created by the programmer. a) punctuation b) programmer-defined names c) key words d) operators

b) programmer-defined names

What is a break statement?

break; This is used with switch statements, it can also be placed inside a loop. It is considered taboo to use the break statement in a loop as it bypasses the normal condition that is required to terminate a loop, and makes code difficult to understand and debug.

You can use this method to display formatted output into a console window. a) Format.out.println b) Console.format c) System.out.printf d) System.out.formatted

c) System.out.printf

The key word used to declare a named constant. a) constant b) namedConstant c) final d) concrete

c) final

These are words that have a special meaning in the programming language. a) punctuation b) programmer-defined names c) key words d) operators

c) key words

This is an empty statement that does nothing. a) missing statement b) virtual statement c) null statement d) conditional statement

c) null statement

In the expression number++, the ++ operator is what mode? a) prefix b) pretest c) postfix d) posttest

c) postfix

This type of memory can hold data for long periods of time -- even when there is no power to the computer. a) RAM b) primary storage c) secondary storage d) CPU storage

c) secondary storage

Every complete statement ends with a ...? a) period b) parenthesis c) semicolon d) ending brace

c) semicolon

This determines whether two different String objects contain the same string. a) the == operator b) the = operator c) the equals method d) the stringCompare method

c) the equals method

The conditional operator takes this many operands. a) one b) two c) three d) four

c) three

This is a named storage location in the computers memory. a) class b) key word c) variable d) operator

c) variable

When Java converts to a lower-ranked value to a higher-ranked type, it is called a(n) ...? a) 4-bit conversion b) escalating conversion c) widening conversion d) narrowing conversion

c) widening conversion

What is a continue statement?

continue; When this statement is encountered, all statements in the body of the loop that appear after it are ignored and the loop prepares for the next iteration. This statement should be avoided as it bypasses the loop's logic and makes the code difficult to understand and debug.

These characters mark the beginning of a documentation comment. a) // b) /* c) */ d) /**

d) /**

To open a file for reading, you use for the following classes. a) File and Writer b) File and Output c) File and Input d) File and Scanner

d) File and Scanner

JVM stands for ...? a) Java Variable Machine b) Java Variable Method c) Java Virtual Method d) Java Virtual Machine

d) Java Virtual Machine

This class allows you to use the print and println methods to write data to a file. a) File b) FileReader c) OutputFile d) PrintWriter

d) PrintWriter

This is a variable that keeps a running total. a) sentinel b) sum c) total d) accumulator

d) accumulator

A byte is made up of eight a) CPUs b) addresses c) variables d) bits

d) bits

This type of expression has a value of either true or false. a) binary expression b) decision expression c) unconditional expression d) boolean expression

d) boolean expression

To create a block of statements, you enclose the statement int these. a) parentheses ( ) b) square brackets [ ] c) angled brackets < > d) braces { }

d) braces

What is each repetition of a loop known as? a) cycle b) revolution c) orbit d) iteration

d) iteration

These are symbols or words that perform operations on one or more operands. a) punctuation b) programmer-defined names c) key words d) operators

d) operators

How can you ignore case in compareTo and equals?

equalsIgnoreCare and compareToIgnoreCase will ignore the upper or lower case attribute of a character string.

It is not necessary to initialize accumulator variables, true or false.

false

One limitation of the for loop is that only one variable may be initialized in the initialization expression, true or false.

false

The = operator and the == operator perform the same operation, true or false?

false

The do-while loop is a pretest loop, true or false?

false

The for loop is a postest loop, true or false.

false

To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops, true or false?

false

What is the value of this expression? !true

false

What is the value of this expression? false && false

false

What is the value of this expression? false && true

false

What is the value of this expression? false || false

false

What is the value of this expression? true && false

false

How do you define a named constant?

final is written before the data type, the value must be initialized in this declaration. ie. final double INTEREST_RATE = 0.069;

What import is require to work with the Java API files?

import java.io.*;

How do you read a single character from a string input?

input = keyboard.nextLine(); // Get a line of input answer = input.charAt(0); //Get the first character. answer will hold the single character.

In CMD.exe what prompt will allow you to run a java class?

java 'ClassFilename'

In CMD.exe what prompt will allow you to run a java file from the folder you have navigated to?

javac 'filename'

In CMD.exe what prompt will allow you to compile a java file from the folder you have navigated to?

javac 'filename.java'

What is the scanner method for Byte inputs?

nextByte

What is the scanner method for Double inputs?

nextDouble

What is the scanner method for Float inputs?

nextFloat

What is the scanner method for Int inputs?

nextInt

What is the scanner method for String inputs?

nextLine ornext

What is the scanner method for Long inputs?

nextLong

What is the scanner method for Short inputs?

nextShort

What will this code output? double number; number = 5 / 2;

number = 2 because the numbers are stored as integers, the fractional part of the result will be thrown away.

What will this code output? double number; number = 5.0 / 2;

number = 2.5 5.0 is treated as a floating-point number so the division operation will return a floating-point number.

When the program is finished writing data to the file, it must close the file. To close the file the PrintWriter class uses this method:

ouputFile.close();

List the logical operators in order of precedence.

! && ||

What was the Green Team's first project that's man purpose was to develop handheld devices that could speak to any other electronic using any programming language called?

*7 (pronounced start seven)

Programs that calculate the total of a series of numbers typically use two elements, what are they?

- A loop that reads each number in the series. - A variable that accumulates the total of the numbers as they are read.

What are the three main rules of writing an if statement?

- The conditionally executed statement should appear on the line after the if statement - The conditionally executed statement should be indented one level from the if statement. - You do not put a semicolon after the if (expression) portion of the if statement.

In general there are two types of files, what are they?

- text file: contains data that has been encoded as text, using a scheme such as Unicode. - binary file: contains data that has not been converted to text.

What is the integer range that a 'byte' data type holds?

-128 to 127

What is the integer range that a 'int' data type holds?

-2,147,483,648 to 2,147,438,647

What is the integer range that a 'short' data type holds?

-32,768 to 32,767

What is the integer range that a 'long' data type holds?

-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

How do you start and end multi-line comments?

/** begins the multi-line comments and **/ ends the comment.

What will the following code segments print on the screen? int freeze = 32, boil = 212; freeze = 0; boil = 100; System.out.println(freeze + "\n" + boil + "\n");

0 100

How many bytes can a 'byte' data type hold?

1 byte

What 5 parts makeup a format specifier?

1) % 2) flags 3) width 4).precision 5) conversion

List the prescedence of all operators.

1) - (unary negation) 2) * % 3) + - 4) < > <= >= 5) == != 6) && 7) || 8) = += -= *= /= %=

What are three different ways can you reference strings to literals?

1) if (name1 == "mark") 2) StringReference1.equals("mark") 3) if (name1.equals("mark"))

What are three different ways to reference strings objects?

1) if (name1 == name 2) 2) StringReference1.equals(StringReference2) 3) if (name1.equals(name2))

How many bytes are in each Unicode number?

2 bytes

How many bytes can a 'short' data type hold?

2 bytes

How many bytes does char data types hold?

2 bytes

How many bytes can a 'float' data type hold?

4 bytes

How many bytes can a 'int' data type hold?

4 bytes

How many bytes can a 'double' data type hold?

8 bytes

How many bytes can a 'long' data type hold?

8 bytes

What is the difference between == and =?

= is the assignment operator and == tests for equality.

What is a buffer?

A buffer is a small "holding section" of memory. When a program writes data to a file, that data is first written to the buffer.

What is a class header?

A class header marks the beginning of a class definition. ie. public class [filename] {

What is the body of a loop called?

A conditionally executed statement.

What is a delimiter?

A delimiter is an item that separates other items.

What is a flag?

A flag is a boolean variable that signals when some condition exists in the program.

What is a block?

A group of statements enclosed in braces.

Why would a Nested Decision Structure be better to use than an if-else-if statement?

A long series of nested if-else statements has two particular disadvantages when you are debugging code. - The code can grow complex and become difficult to understand. - Because indenting is important in nested statements, a long series of if-else statements can become too long to be displayed on the computer screen without horizontal scrolling.

What is a loop?

A loop is a control structure that causes the statement or group of statements to repeat in Java.

What is a nested loop?

A loop that is inside another loop is called a nested loop.

What is a count-controlled loop?

A loop that repeats a specific number of times is known as a count-controlled loop.

What is a 'method'?

A method can be thought of as a group of one or more programming statements that collectively has a name.

What is a null statement?

A null statement is an empty statement that does nothing.

What is the while loop known as?

A pretest loop, which means it tests its expression before each iteration. This means if the expression is false prior to the loop running then the loop will not execute.

What is a rational operator?

A rational operator determines whether a specific relationship exists between two values.

What is a decrement?

A value means to decrease it by one.

What is increment?

A value means to increase it by one.

When the ++ or -- is added after the variable what is this called?

postfix mode ie: variable++ variable--

What does this binary logical operator indicate? &&

AND Connects to boolean expressions into one. Both expressions must be true for the overall expression to be true.

What does the following symbol mean? +

Addition, this is a binary operator.

In format specifiers what is width?

After any flags, you can optionally specify the minimum field width for the value.

In format specifiers what is flags?

After the % character, one or more optional flags may appear. Flags cause the value to be formatted in a variety of ways. You can insert into a format specifier to cuase a vlaue to be formatted in a particular way. There are several optional flags that y - To display numbers with comma separators - To pad numbers with leading zeros - To left-justify numbers

What is a decision structure?

Algorithms require a program to execute some statements only under certain circumstances, this is a decision structure.

In format specifiers what is conversion?

All format specifiers must end with a conversion character, such as f for floating-point, or d for decimal integer.

In format specifiers what is %?

All formats begin with this character

What is contained within braces?

All programming statements that are part of the class are enclosed in a set of braces.

What is an API?

An API is a standard library of pre-written classes for performing specific operations.

What does the following character represent? \

An escape sequence, it is normally followed by one or more control characters.

What is an input file?

An input file is a file that a program reads data from. It is called an input file because the data stored in it serves as input to the program.

What is a loop repetition known as?

An iteration.

What are attributes?

An object's attributes are data values that are stored in the object.

What is an output file?

An output file is a file that a program writes data to. it is called an output file because the program stores output in the file.

What is API?

Application Programmer Interface

When the ++ or -- is added before the variable what is this called?

prefix mode ie. ++variable --variable

This programming language is a general-purpose, procedural programming language that was originally designed for beginners to learn.

BASIC (Beginners All-purpose Symbolic Instruction Code)

What does the following escape sequence and control character do? \\

Backslash, it causes a backslash to be printed.

What does the following escape sequence and control character do? \b

Backspace, it causes the cursor to go back up, or move left, one position.

Should you modify the control variable in the body of the for loop?

Be careful not to place a statement that modifies the control variable in the body of the for loop. All modifications of the control variable should take place in the update expression, which is automatically executed at the end of each iteration.

Describe Binary.

Binary operators work with two operands.

How can you use a conditional operator as an if-else statement?

BooleanExpression ? Value1: Value2; This can be used in a text output to decide what will be shown on the screen depending on the Boolean Expression.

What is the base code behind Java?

Byte Code

This programming language is a structured, general-purpose, procedural language developed at Bell Laboratories.

C

This programming language was invented by Microsoft for developing applications based on the Microsoft .NET platform.

C#

This programming language is based on the C language, it offers object-oriented features not found in C and was also developed at Bell Laboratories.

C++

This programming language is a procedural language designed for business applications.

COBOL (Common Business-Oriented Language)

How is the Math.pow method used?

result = Math.pow(4.0, 2.0); result = 4^2. This method takes two arguments, it raises the first argument to the power of the second argument and returns the result as a double.

How is the Math.sqrt method used?

result = Math.sqrt(9.0); This method will return the square root of 9.0, which is assigned to the result variable.

How is length() used?

this method returns the number of characters in the string.

A conditionally executed statement should be indented one level from the if clause, true or false.

true

A variable may be defined in the initialization expression of the for loop, true or false?

true

All lines in a conditionally executed block should be indented one level from the if clause, true or false?

true

In a nested loop, the inner loop goes through all of its iterations for every iteration of the outer loop, true or false?

true

The scope of a variable is limited to the block in which it is defined, true or false.

true

The while loop is a pretest loop, true or false?

true

What is the value of this expression? !false

true

What is the value of this expression? false || true

true

What is the value of this expression? true && true

true

What is the value of this expression? true || false

true

What is the value of this expression? true || true

true

When an if statement is nested in the else clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer if statement is true, true or false?

true

When an if statement is nested in the if clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer statement is true, true or false?

true

How do you convert a string to a byte?

variable1 = Byte.parseByte(variable2);

How do you convert a string to a double?

variable1 = Double.parseDouble(variable2);

How do you convert a string to a float?

variable1 = Float.parseFloat(variable2);

How to convert a string to an Int?

variable1 = Integer.parseInt(variable2);

How to convert a string to a long?

variable1 = Long.parseLong(variable2);

How to convert a string to a short?

variable1 = Short.parseShort(variable2);

What is a string concatenation operator?

Concatenation means to append, so the use of this operator will add one string to another. The symbol for this operator is +. ie. System.out.println("This is " + "one string") will output: This is one string.


Ensembles d'études connexes

New Hampshire Adjuster Exam Prep: Series 12-75

View Set

AP World Midterm (First 29 First Part- Next 38 Second Part of 45 Question Test - Next 24 Third Part from December 6th - Next 24 from December 7th - Next 23 From December 11th)

View Set

Combine business data in Google Analytics

View Set

Fundamentals of Literature Test 3, Unit 3: Theme

View Set

Types of Angles: Vertical, Corresponding, Alternate Interior & Others

View Set

History of Western Art II -- Quiz 4

View Set

Mrs. Welch Math 2 Midterm Review

View Set

Finance 450-Test #4 CONCEPT REVIEW

View Set

Verbes Réguliers -ER (e, es, e, ons, ez, ent)

View Set