Java Chapter 3, Ch3 CheckPoint-Introduction to Java Programming, Includes Data Structures, Eleventh Edition, Y. Daniel Liang Chapter 3 Check Point Questions, Introduction to Java - Ch. 1 - Ch.3, Ch2 Vocab -Introduction to Java Programming, Includes D...

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

expression

Represents a computation involving values, variables, and operators, which evaluates to a value.

keyword

Reserved words that have a specific meaning in java and cannot be used for variables

If your program needs to read integers, but the user entered strings, an error would occur when running this program. What kind of error is this?

Runtime error.

Bytecode

Similar to machine instructions, but can run on any platform with a JVM

algorithm

Statements that describe how a problem is solved in terms of the actions to be executed, and specifies the order in which these actions should be executed. Algorithms can help the programmer plan a program before writing it in a programming language.

decrement operator (--)

Subtracts one from a numeric variable or a char variable.

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

Syntax error.

What are syntax errors (compile errors), runtime errors, and logic errors?

Syntax errors are detected by compilers. Runtime errors occur during execution of the program. Logic errors results in incorrect results.

casting

an operation that converts a value of one data type into a value of another data type

Block

anything inside of a {xxxxxx}

operands

are the values operated by an operator.

int type

an exact number, 1, 4 or 10

This type of expression has a value of either true or false.

boolean expression

declaration

Defines variables, methods, and classes in a program.

Which of the following is not permanent storage devices? A. floppy disk B. hard disk C. flash stick D. CD-ROM E. main memory

E. main memory

5 == !=

Equal to, not equal to

Conditional Expression ( ? :)

Evaluates an expression based on a condition (pg 103)

List five major hardware components of a computer.

Five major hardware components: CPU, Memory, Storage Devices, Input/Out Devices, and Communication Devices.

What does IDE stand for?

IDE stands integrated development environment.

expression statement

If an expression is used as a statement, it is called an expression statement.

What is the output of the code in (a) and (b) if number is 30? What if number is 35? (a) if (number % 2 == 0) System.out.println(number + " is even."); System.out.println(number + " is odd."); (b) if (number % 2 == 0) System.out.println(number + " is even."); else System.out.println(number + " is odd.");

If number is 30, (a) displays 30 is even 30 is odd (b) displays 30 is even If number is 35, (a) displays 35 is odd (b) displays 35 is odd

overflow

If you try to store a value in a data type that cannot handle it.

This determines whether two different String objects contain the same string

The stringCompare method

indentation

The use of tabs and spaces to indent the source code to make it easy to read and understand.

Boolean Value

can be true or false

narrowing (of types)

casting a data type from a large range to a smaller range - Java does this automatically

widening (of types)

casting from a small type to a larger type, this is done manually

name of type

char

bytecode verifier

checks the validity of a bytecode

Java Development Toolkit

consists of a set of separate programs, each invoked from a command line, for developing and testing Java programs

This section of a switch statement is branched to if none of the case expressions match the switch expression.

default

declare variable

defines a variable with a data type.

final keyword

denotes a value as a constant

final

denotes names

pseudocode

describes the program logic using natural language mixed with some programming code.

operator associativity

determine the order in which operators are evaluated

keywords

do, else, and break

true && true

true

1 − (unary negation) !

Unary negation, logical NOT

data type

Used to define variables to indicate what kind of value the variable can hold.

identifier

Variable

variable

Variables are used to store data and computational results in the program.

What is the difference between an interpreted language and a compiled language?

What is the difference between an interpreted language and a compiled language? An interpreter reads one statement from the source code, and translates it to the machine code or virtual machine code, and then executes it right away. A compiler translates the entire source code into a machine code file, and the machine code file is then executed.

underflow

When a floating-point number is too small (i.e., too close to zero) to be stored, it causes underflow. Java approximates it to zero, so normally you don't need to be concerned about underflow.

overflow

When a variable is assigned a value that is too large (in size) to be stored, it causes overflow.

true && false

false

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

flag

name of a type

float

Write an if statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10.

if (a < 10) { b = 0; c = 1; }

Assume the variables name1 and name2 reference two different String objects, containing different strings. Write code that displays the strings referenced by these variables in alphabetical order.

if (name1.compareTo(name2) < 0) System.out.println(name1 + " " + name2); else System.out.println(name2 + " " + name1);

Write an if-else statement that assigns 0.10 to commission unless sales is greater than or equal to 50000.0, in which case it assigns 0.2 to commission.

if (sales >= 50000.0) commission = 0.2; else commission = 0.1;

Write an if statement that increases pay by 3% if score is greater than 90.

if (score > 90) pay *= 1.03;

Write an if statement that increases pay by 3% if score is greater than 90, otherwise increases pay by 1%.

if (score > 90) pay *= 1.03; else pay *= 1.01;

Write an if statement that displays the message "The number is not valid" if the variable speed is outside the range 0 through 200.

if (speed < 0 || speed > 200) System.out.println("The number is not valid");

Write an if-else statement that assigns 20 to the variable y if the variable x is greater than 100. Otherwise, it should assign 0 to the variable y.

if (x > 100) y = 20; else y = 0;

Write an if statement that assigns 20 to the variable y and assigns 40 to the variable z if the variable x is greater than 100.

if (x > 100) { y = 20; z = 40; }

Write an if-else statement that assigns 1 to x when y is equal to 100. Otherwise, it should assign 0 to x.

if (y == 100) x = 1; else x = 0;

Write an if statement that assigns 0 to x when y is equal to 20.

if (y == 20) x = 0;

Write an if statement that assigns 1 to x if y is greater than 0.

if (y > 0) x = 1;

directive

import

preprocessor

import statement

wildcard import

imports all the classes in a package by using a ** (import java.util.**;)

wildcard import

imports all the classes in a package. For example, import java.util.* imports all classes from package java.util.

IPO

input, process, output - describes simple code

statement

instructions for a high-level program

name of type

int

primitive data type

int, real numbers, characters and booleans

requirement specification

is a formal process that seeks to understand the problem that the software will address and to document in detail what the software system needs to do.

scope of a variable

is the part of the program where the variable can be referenced.

system design

is to design a process for obtaining the output from the input. This phase involves the use of many levels of abstraction to break down the problem into manageable components and design strategies for implementing each component.

What is the command to run a Java program?

java is the JDK command to run a program.

What is the command to compile a Java program?

javac is the JDK command to compile a program.

&&, ||, and ! are __________.

logical operators

nextDouble

method that is applied to objects of Scanner

This is an if statement that appears inside another if statement.

nested if statement

This is an empty statement that does nothing.

null statement

logic error

occurs when a program does not perform the way it was intended to

comment

on a program denoted by //xxxxx or /**xxxx**/

if (temp > 45) population = base * 10; else population = base * 2;

population = temp > 45 ? base * 10 : base * 2;

!false

true

True or False: A conditionally executed statement should be indented one level from the if clause.

true

True or False: All lines in a conditionally executed block should be indented one level.

true

True or False: The scope of a variable is limited to the block in which it is defined.

true

True or False: 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 if statement is true.

true

false || true

true

true || false

true

true || true

true

Assembly Language

uses a short descriptive word to represent each of the machine-language instructions

fall-through behavior

using no breaks in a switch

concatenate strings

using the (+) sign to combine strings

operator precedence

var++, + and -, casting, !, * / %, + - concaction, (See page 105)

if (hours > 40) wages *= 1.5; else wages *= 1;

wages = hours > 40 ? wages * 1.5 : wages * 1;

floating point/pi

3.14159E1

Floating point

scientific notation

IPO

stands for Input, Process, and Output.

dot pitch

the amount of space between pixels, measured in millimeters

dangling else ambiguity

when else matches with the most recent if statement

Assuming that x is 1, show the result of the following Boolean expressions: x > 0 x < 0 x != 0 x >= 0 x != 1

x > 0 true x < 0 false x != 0 true x >= 0 true x != 1 false

if (x > y) z = 1; else z = 20;

z = x > y ? 1 : 20;

When determining whether a number is inside a range, it's best to use this operator.

&&

If you forget to put a closing quotation mark on a string, what kind of error will be raised? A. a compile error B. a runtime error C. a logic error

A. a compile error

Every statement in Java ends with ________. A. a semicolon (;) B. a comma (,) C. a period (.) D. an asterisk (*)

A. a semicolon (;)

Computer can execute the code in ____________. A. machine language B. assembly language C. high-level language D. none of the above

A. machine language

Explain what is meant by the phrase "conditionally executed."

Conditionally executed code is executed only under a condition, such as an expression being true.

Unix epoch

January 1, 1970 GMT is known as the Unix epoch because 1970 was the year when the Unix operating system was formally introduced.

Literal

Constant value directly in a program that stands for itself

byte type

-128 to 127

boolean operators

!, &&, ||, ^

Bit

Binary digits

How does the character 'A' compare to the character 'B'?

'A' is less than 'B'

increment operator

++

postincrement

++ placed after variable. uses original variable in expression then increases by 1

preincrement

++ placed before variable. increases variable by one, then uses it in the expression

operators

+, -, *, /, %

Augmented assignment operators

+=, -=, **=, /= and %= (i+= 8 is i = i + 8)

decrement operator

--

Write nested if statements that perform the following test: If amount1 is greater than 10 and amount2 is less than 100, display the greater of the two.

1 1

illegal identifier

4thQtrSales

Byte

8 bits to 1 byte

statement terminator

;

List six relational operators.

<, <=, ==, !=, >, >=

Relational Operators (Boolean)

<, <=, ==, !=, >, >=

assignment operator

=

conditional operator

? : for if statement shorthand

What is a bit? What is a byte?

A bit is a binary digit 0 or 1. A byte is a sequence of 8 bits.

What are hardware and software?

A computer is an electronic device that stores and processes data. A computer includes both hardware and software. In general, hardware is the physical aspect of the computer that can be seen, and software is the invisible instructions that control the hardware and make it work. The hardware of a computer consists of a CPU, cache, memory, hard disk, floppy disk, monitor, printer, and communication devices.

literal

A constant value that appears directly in the program. A literal may be numeric, character, boolean, or null for object type.

backslash (\)

-- A character that precedes another character to denote the following character has a special meaning. For example, '\t' denote a tab character. The backslash character is also used to denote a Unicode character like '\u00FF'.

postdecrement

-- placed after variable. uses original variable in expression then decreases by 1

predecrement

-- placed before variable. decreases variable by one, then uses it in the expression

identifier

-names that refer to values or names - letters, digits, _, and $. -rules for creating a name in a program

Block Comment

/**XXXXXXXXXXXXX**/

octa integer

075

Explain the purpose of a flag variable. Of what data type should a flag variable be?

A flag is a boolean variable that signals when some condition exists in the program. When the flag variable is set to false, it indicates the condition does not yet exist. When the flag variable is set to true, it means the condition does exist.

Why is it good advice to indent all the statements inside a set of braces?

By indenting the conditionally executed statements, you are causing them to stand out visually. This is so you can tell at a glance what part of the program the if statement executes.

If a NoClassDefFoundError occurs when you run a program, what is the cause of the error?

Java interpreter cannot find the .class file. Make sure you placed the file in the right place, and invoked java command with appropriate package name.

Is Java case sensitive? What is the case for Java keywords?

Java source code is case sensitive. Java keywords are always in lowercase.

6 &&

Logical AND

if (result >= 0) System.out.println("The result is positive."); else System.out.println("The result is negative.");

System.out.println(result >=0 ? "The result is positive" : "The result is negative");

What is the statement to display a string on the console?

System.out.println(string);

Application Program Interface ( API)

A library in Java that contains predefined classes and interfaces

When does a constructor execute? What is its purpose?

The object memory is allocated, the field variables with initial values are initialized, and then the constructor is called, but its code is executed after the constructor code of the object super class.

scope of a variable

The part of a program where the variable can be referenced

Write an if-else statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10. Otherwise, it should assign -99 to the variable b and assign 0 to the variable c.

if (a < 10) { b = 0; c = 1; } else { b = -99; c = 0; }

Write an if statement that multiplies payRate by 1.5 if hours is greater than 40.

if (hours > 40) payRate *= 1.5;

Write an if statement that sets the variable fees to 50 if the boolean variable max is true.

if (max) fees = 50;

Write an if statement that displays "Goodbye" if the variable myCharacter contains the character 'D'.

if (myCharacter == 'D') System.out.println("Goodbye");

Assume the variable name references a String object. Write an if statement that displays "Do I know you?" if the String object contains "Timothy".

if (name.equals("Timothy")) System.out.println("Do I know you?");

Modify the statement you wrote in response to Checkpoint 3.20 so it performs a case-insensitive comparison.

if (name.equalsIgnoreCase("Timothy")) System.out.println("Do I know you?");

Write an if statement that assigns 0.2 to commission if sales is greater than or equal to 10000.

if (sales >= 10000) commission = 0.2;

Write an if statement that displays the message "The number is valid" if the variable speed is within the range 0 through 200.

if (speed >= 0 && speed <= 200) System.out.println("The number is valid");

Write code that tests the variable x to determine whether it is greater than 0. If x is greater than 0, the code should test the variable y to determine whether it is less than 20. If y is less than 20, the code should assign 1 to the variable z. If y is not less than 20, the code should assign 0 to the variable z.

if (x > 0) { if (y < 20) { z = 1; } else { z = 0; } }

specific import

specifies a single class in the import statement. For example, import java.util.Scanner imports Scanner from package java.util.

selection statement

statements that let you choose actions with alternative choices

Boolean Expression

An expression that evaluates a Boolean value to be true or false

final keyword

A modifier that specifies a constant.

identifier

A name of a variable, method, class, interface, or package.

floating-point number

A number that includes a fractional part.

byte type

A primitive data type that represents an integer in a byte. The range a byte value is from -27 (-128) to 27 -1 (127).

short type

A primitive data type that represents an integer in the range from - 215 (-32768) to 215-1 (32767).

int type

A primitive data type to represent an integer in the range from -231 (- 2147483648) to 231-1 (2147483647).

long type

A primitive data type to represent an integer in the range from -263 to 263-1.

double type

A primitive data type to represent double precision floating-point numbers with 14 to 15 significant digits of accuracy.

float type

A primitive data type to represent single precision floating-point numbers with 6 to 7 significant digits of accuracy. The double type is used to represent double precisions with 14 to 15 significant digits of accuracy.

debugger

A program that facilitates debugging. It enables the program to be executed one statement at a time and enables the contents of the variable to be examined during execution.

incremental code and testing

A programming methodology that develop and test program incrementally. This approach is efficient and productive. It helps eliminate and isolate errors.

assignment statement

A simple statement that assigns a value to a variable using an assignment operator (=). When a value is assigned to a variable, it replaces the previous value of the variable, which is destroyed.

constant

A variable declared final in Java. A local constant is a constant declared inside a method.

The extension name of a Java source code file is A. .java B. .obj C. .class D. .exe

A. .java

_ is the physical aspect of the computer that can be seen. A. Hardware B. Software C. Operating system D. Application program

A. Hardware

_ is the physical aspect of the computer that can be seen. A. Hardware B. Software C. Operating system D. Application program

A. Hardware

________ is architecture-neutral. A. Java B. C++ C. C D. Ada E. Pascal

A. Java

________ is interpreted. A. Java B. C++ C. C D. Ada E. Pascal

A. Java

Java compiler translates Java source code into _________. A. Java bytecode B. machine code C. assembly code D. another high-level language code

A. Java bytecode

________ is a technical definition of the language that includes the syntax and semantics of the Java programming language. A. Java language specification B. Java API C. Java JDK D. Java IDE

A. Java language specification

_________ is a software that interprets Java bytecode. A. Java virtual machine B. Java compiler C. Java debugger D. Java API

A. Java virtual machine

_____________ is a program that runs on a computer to manage and control a computer's activities. A. Operating system B. Java C. Modem D. Interpreter E. Compiler

A. Operating system

Java was developed by ____________. A. Sun Microsystems B. Microsoft C. Apple D. IBM E. Cisco Systems

A. Sun Microsystems

Which JDK command is correct to run a Java application in ByteCode.class? A. java ByteCode B. java ByteCode.class C. javac ByteCode.java D. javac ByteCode E. JAVAC ByteCode

A. java ByteCode

Which of the following are the reserved words? A. public B. static C. void D. class

A. public B. static C. void D. class

3 + −

Addition, subtraction

increment operator (++)

Adds one to a numeric variable or a char variable.

logic error

An error that causes the program to produce incorrect result.

What is an interpreter? What is a compiler?

An interpreter is a software that reads one statement from the source code, translates it to the machine code or virtual machine code, and then executes it right away. A compiler is a software that translates a program in high-level language into machine language code.

What programming language does Android use?

Android uses the Java programming language.

What is an assembly language? What is an assembler?

Assembly language is a low-level programming language in which a mnemonic is used to represent each of the machine language instructions. Assembler is a software that translates assembly language into machine language.

8 = += −= *= /= %=

Assignment and combined assignment

assignment operator (=)

Assigns a value to a variable.

One byte has ________ bits. A. 4 B. 8 C. 12 D. 16

B. 8

___________ translates high-level language program into machine language program. A. An assembler B. A compiler C. CPU D. The operating system

B. A compiler

_ is the brain of a computer. A. Hardware B. CPU C. Memory D. Disk

B. CPU

__________ is the brain of a computer. A. Hardware B. CPU C. Memory D. Disk

B. CPU

Which of the following statements is correct? A. Every line in a program must end with a semicolon. B. Every statement in a program must end with a semicolon. C. Every comment line must end with a semicolon. D. Every method must end with a semicolon. E. Every class must end with a semicolon.

B. Every statement in a program must end with a semicolon.

________ contains predefined classes and interfaces for developing Java programs. A. Java language specification B. Java API C. Java JDK D. Java IDE

B. Java API

____________ are instructions to the computer. A. Hardware B. Software C. Programs D. Keyboards

B. Software C. Programs

Which of the following statements is correct to display Welcome to Java on the console? A. System.out.println('Welcome to Java'); B. System.out.println("Welcome to Java"); C. System.println('Welcome to Java'); D. System.out.println('Welcome to Java"); E. System.out.println("Welcome to Java');

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

Due to security reasons, Java ___________ cannot run from a Web browser in the new version of Java. A. applications B. applets C. servlets D. Micro Edition programs

B. applets

Why do computers use zeros and ones? A. because combinations of zeros and ones can represent any numbers and characters. B. because digital devices have two stable states and it is natural to use one state for 0 and the other for 1. C. because binary numbers are simplest. D. because binary numbers are the bases upon which all other number systems are built.

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

A block is enclosed inside __________. A. parentheses B. braces C. brackets D. quotes

B. braces

variable name

Bool

Which of the following lines is not a Java comment? A. /** comments */ B. // comments C. -- comments D. /* comments */ E. ** comments **

C. -- comments E. ** comments **

The extension name of a Java bytecode file is A. .java B. .obj C. .class D. .exe

C. .class

________ is not an object-oriented programming language. A. Java B. C++ C. C D. C# E. Python

C. C

________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line. A. Java language specification B. Java API C. Java JDK D. Java IDE

C. Java JDK

____________ is an operating system. A. Java B. C++ C. Windows D. Visual Basic E. Ada

C. Windows

If a program compiles fine, but it produces incorrect result, then the program suffers __________. A. a compilation error B. a runtime error C. a logic error

C. a logic error

Programming style is important, because ______________. A. a program may not compile if it has a bad style B. good programming style can make a program run faster C. good programming style makes a program more readable D. good programming style helps reduce programming errors

C. good programming style makes a program more readable D. good programming style helps reduce programming errors

The JDK command to compile a class in the file Test.java is A. java Test B. java Test.java C. javac Test.java D. javac Test E. JAVAC Test.java

C. javac Test.java

The speed of the CPU may be measured in __________. A. megabytes B. gigabytes C. megahertz D. gigahertz

C. megahertz D. gigahertz

The main method header is written as: A. public static void main(string[] args) B. public static void Main(String[] args) C. public static void main(String[] args) D. public static main(String[] args) E. public void main(String[] args)

C. public static void main(String[] args)

What does the acronym CPU stand for? What unit is used to measure CPU speed?

CPU stands for Central Processing Unit. It is the brain of the computer. The unit of measurement of clock speed is the hertz (Hz), with 1 hertz equaling 1 pulse per second. The clock speed of a computer is usually stated in megahertz (MHz) (1 MHz is 1 million Hz).

narrowing (of types)

Casting a variable of a type with a larger range to a variable of a type with a smaller range.

widening (of types)

Casting a variable of a type with a smaller range to a variable of a type with a larger range.

What is a comment? Is the comment ignored by the compiler? How do you denote a comment line and a comment paragraph?

Comments are used to document what a program is for and how a program is constructed. Comments help the programmers or users to communicate and understand the program. Comments are not programming statements and are ignored by the compiler. In Java, comments are preceded by two forward slashes (//) in a line or enclosed between /* and */ in multiple lines. When the compiler sees //, it ignores all text after // in the same line. When it sees /*, it scans for the next */ and ignores any text between /* and */.

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!"); } } A. Both I and II can compile and run and display Welcome to Java, but the code in II has a better style than I. B. Only the code in I can compile and run and display Welcome to Java. C. Only the code in II can compile and run and display Welcome to Java. D. Both I and II can compile and run and display Welcome to Java, but the code in I has a better style than II.

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

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!"); } } A. I B. II C. III D. IV

D. IV

________ 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. A. Java language specification B. Java API C. Java JDK D. Java IDE

D. Java IDE

____________ is a device to connect a computer to a local area network (LAN). A. Regular modem B. DSL C. Cable modem D. NIC

D. NIC

Suppose you define a Java class as follows, the source code should be stored in a file named _________. public class Test { } A. Test.class B. Test.doc C. Test.txt D. Test.java E. Any name with extension .java

D. Test.java

Briefly describe how the && operator works.

It takes two boolean expressions as operands and creates a boolean expression that is true only when both subexpressions are true

What happens when you compare two String objects with the == operator?

It will only evaluate it as truer vecause == is used for primitive operators such as boolean, int, and double.

What does JDK stand for? What does JRE stand for?

JDK stands for Java Development Toolkit. JRE stands for Java Runtime Environment.

What is the JVM?

JVM is the Java virtual machine that runs a Java program.

What is a Java applet?

Java applet is a special program that runs from a Web browser. Due to security reasons, applets are no longer allowed to run from Web browsers.

Can Java run on any machine? What is needed to run Java on a computer?

Java can run on any machine with a JVM.

Who invented Java? Which company owns Java now?

Java was invented by a team led by James Gosling at Sun Microsystems in 1991. Originally called Oak, it became Java in 1995 when it was redesigned for developing Internet applications. Oracle bought Sun and Oracle now owns Java.

What is a keyword? List some Java keywords.

Keywords have specific meaning to the compiler and cannot be used for other purposes in the program such as variables or method names. Examples of keywords are class, static, and void.

4 < > <= >=

Less than, greater than, less than or equal to, greater than or equal to

Identify and fix the errors in the following code: 1 public class Welcome { 2 public void Main(String[] args) { 3 System.out.println('Welcome to Java!'); 4 } 5 )

Line 2. Main should be main. Line 2. static is missing. Line 3: Welcome to Java! should be enclosed inside double quotation marks. Line 5: The last ) should be }.

Suppose you write a program for computing the perimeter of a rectangle and you mistakenly write your program so that it computes the area of a rectangle. What kind of error is this?

Logic error.

7 ||

Logical OR

What are the major responsibilities of an operating system?

Major responsibilities: a. Controlling and monitoring system activities b. Allocating and assigning system resources c. Scheduling operations

What is memory for? What does RAM stand for? Why is memory called RAM?

Memory is like a work area for programs. Before a program is executed, it is brought into the memory. RAM stands for random-access memory. It is called RAM because a memory cell can be accessed directly.

What is the primary difference between memory and a storage device?

Memory is volatile, because information is lost when the power is turned off. Programs and data are permanently stored on storage devices and are moved, when the computer actually uses them, to memory, which is much faster than storage devices.

What unit is used to measure memory size? What unit is used to measure disk size?

Memory size is measured in bytes. Disk size is measured in bytes.

2 * / %

Multiplication, division, modulus

What is multiprocessing?

Multiprocessing, or parallel processing, uses two or more processors together to perform a task.

What is multiprogramming?

Multiprogramming allows multiple programs to run simultaneously by sharing the CPU.

What is multithreading?

Multithreading allows concurrency within a program, so that its subtasks can run at the same time.

Are tools like NetBeans and Eclipse different languages from Java, or are they dialects or extensions of Java?

NetBeans and Eclipse are not programming languages, nor dialects, nor extensions of Java. They are Java development tools.

Can the following conversions involving casting be allowed? Write a test program to verify it. boolean b = true; i = (int)b; int i = 1; boolean b = (boolean)i;

No. Boolean values cannot be cast to other types.

floating-point number

Numbers with a decimal point (var double)

input error

Occurs when the user inputs a value the program cannot handle

operator

Operations for primitive data type values. Examples of operators are +, -, *, /, and %.

Show the output of the following code: public class Test { public static void main(String[] args) { System.out.println("3.5 * 4 / 2 - 2.5 is "); System.out.println(3.5 * 4 / 2 - 2.5); } }

Output is 3.5 * 4 / 2 - 2.5 is 4.5

You can use this method to display formatted output in a console window.

System.out.printf

What is the Java language specification?

The Java language specification specifies the syntax for the Java language.

If a NoSuchMethodError occurs when you run a program, what is the cause of the error?

The class does not have a main method, or the signature of the main method is incorrect.

What is a high-level programming language? What is a source program?

The high-level languages are English-like and easy to learn and program. The program written in a programming language is called a source program.

What are the input and output of a Java compiler?

The input of a Java compiler is a Java source code file and the output is a Java class file.

What language does the CPU understand?

The machine language is a set of primitive instructions built into every computer. This is the language understood by a computer and executed by a computer.

What is an operating system? List some popular operating systems.

The operating system (OS) is a program that manages and controls a computer's activities. The examples of OS are Windows 98, NT, 2000, XP, or ME. Windows. Application programs such as an Internet browser and a word processor run on top of an operating system.

What is wrong in the following code? if radius >= 0 { area = radius * radius * PI; System.out.println("The area for the circle of " + " radius " + radius + " is " + area); }

The parentheses is reuqired for the conidition radius >= 0.

An else clause always goes with __________.

The previous if clause that doesn't already have its own else clause.

primitive data type

The primitive data types are byte, short, int, long, float, double, boolean, and char.

casting

The process of converting a primitive data type value into another primitive type.

debugging

The process of finding and fixing errors in a program.

Briefly describe how the || operator works.

The program must fit either case in the || operator in order for the code to complete.

Explain why a misplaced semicolon can cause an if statement to operate incorrectly.

The semicolon indicates the end of a statement. if you end a statement early, or end something that is not a statement, java will not understand what you are trying to do.

What is the Java source filename extension, and what is the Java bytecode filename extension?

The source file extension is .java and the bytecode file extension is .class.

What risk does a programmer take when not placing a trailing else at the end of an if-else-if statement?

There is a chance that the program will not compile because Java is looking for other factors that may be possible. No code executed.

Why are the relational operators called "relational"?

They determine whether a specific relationship exists between two values. The relationships are greater-than, less-than, equal-to, not equal-to, greater-than or equal-to, and less-than or equal-to.

escape character

\n

util

a class name in the system library that contains different java functions

literal

a constant value that appears directly in a program

Assembler

a device used to translate assembly-language programs into machine code

source code/program

a high-level program's code

constant

a number in the program that never changes, denoted by "final"

String

a type

long type

a very large int, more precise

keyword

abstract is a

Integrated development environment

an environment for developing Java programs

To create a block of statements, you enclose the statements in these.

curly braces {}

The if statement is an example of a __________.

decision structure

runtime error

errors that cause a program to terminate early, an impossible operation is detected

\"

escape sequence

assignment statement

evaluates to the value to be assigned to a variable (=)

!true

false

True or False: The = operator and the == operator perform the same operation.

false

True or False: 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.

false

false && false

false

false && true

false

false || false

false

Reformat the following program according to the programming style and documentation guidelines. Use the end-of-line brace style. public class Test { // Main method public static void main(String[] args) { /** Display output */ System.out.println("Welcome to Java"); } }

public class Test { // Main method public static void main(String[] args) { /** Display outpput */ System.out.println("Welcome to Java"); } }

double type

real numbers, decimal places, twice as precise as float

preincrement

refers to the syntax such as ++x where the ++ operator is place before a variable.

predecrement

refers to the syntax such as --x where the -- operator is place before a variable.

postincrement

refers to the syntax such as x++ where the ++ operator is place after a variable.

postdecrement

refers to the syntax such as x-- where the -- operator is place after a variable.

>, <, and == are __________.

relational operators

expression

represents a computation involving values, variables, and operators that, taking them together, evaluates to a value

variable

represents a value stored in the computers memory

syntax error

result from errors in code construction, such as misspellings, wrong punctuation, etc.

short circuit operator

same as lazy operator - && or || (and, or)

system analysis

seeks to analyze the data flow and to identify the system's 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.

data type

the kind of data stored in each variable

operands

the values operated on by a operator

The conditional operator takes this many operands.

three

compiler

translates a Java source file into a Java bytecode file

interpreter

translates source code into machine code


Kaugnay na mga set ng pag-aaral

7B And Probability: Independent Events

View Set

A R A L I N G P A N L I P U N A N

View Set

2022 Nissan Rogue Sport Certification

View Set

Nutrition exam chap 4,5,6 study

View Set