Exam 1 Flashcards

1
Q

Algorithm

A

A step-by-step description of how to accomplish a task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Program

A

A list of instructions to be carried out by a computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Hardware

A

The physical components that make up a computer: central processing unit, or CPU, memory (often called random access memory, or RAM, hard disk as a larger permanent storage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Software

A

Computer programs are collectively called software. The primary piece of software running on a computer is its operating system. An operating system provides an environment in which many programs may be run at the same time; it also provides a bridge between those programs, the hardware, and the user (the person using the computer). The programs that run inside the operating system are often called applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Digital

A

Based on numbers that increase in discrete increments, such as the integers 0, 1, 2, 3, etc
Modern computers are digital because everything that is stored on the computer is stored as a sequence of integers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Binary Number

A

A number composed of just 0s and 1s, also known as a base-2 number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Program Execution

A

The act of carrying out the instructions contained in a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Compiler

A

A program that translates a computer program written in one language into an equivalent program in another language (often, but not always, translating from a high-level language into machine language).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

executable

A

A compiler that translates directly into machine language creates a program that can be executed directly on the computer, known as an executable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

native compilers

A

We refer to such compilers as native compilers because they compile code to the lowest possible level (the native machine language of the computer).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Java bytecodes

A

Instead of compiling into machine language, Java programs compile into what are known as Java bytecodes. One set of bytecodes can execute on many different machines. These bytecodes represent an intermediate level: They aren’t quite as high-level as Java or as low-level as machine language. In fact, they are the machine language of a theoretical computer known as the Java Virtual Machine (JVM).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Java Virtual Machine

A

A theoretical computer whose machine language is the set of Java bytecodes.
To actually execute a Java program, you need another program that will execute the Java bytecodes. Such programs are known generically as Java runtimes, and the standard environment distributed by Oracle Corporation is known as the Java Runtime Environment (JRE).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Java Runtime

A

A program that executes compiled Java bytecodes.
Most people have Java runtimes on their computers, even if they don’t know about them. For example, Apple’s Mac OS X includes a Java runtime, and many Windows applications install a Java runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Java

A

A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded, dynamic language.2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Java Class Libraries

A

The collection of preexisting Java code that provides solutions to common programming problems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

platform independent

A

Java is extremely platform independent; unlike programs written in many other languages, the same Java program can be executed on many different operating systems, such as Windows, Linux, and Mac OS X.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The Java Programming environment (steps):

A

Type in a program as a Java class.
Compile the program file.
Run the compiled version of the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

File extensions

A

The Java program files that you create must use the extension .java. When you compile a Java program, the resulting Java bytecodes are stored in a file with the same name and the extension .class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Integrated Development Environments, or IDEs

A

Most Java programmers use what are known as Integrated Development Environments, or IDEs, which provide an all-in-one environment for creating, editing, compiling, and executing program files. Some of the more popular choices for introductory computer science classes are Eclipse, IntelliJ, NetBeans, jGRASP, DrJava, BlueJ, and TextPad. Your instructor will tell you what environment you should use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Console Window

A

A special text-only window in which Java programs interact with the user.

The console window is a classic interaction mechanism wherein the computer displays text on the screen and sometimes waits for the user to type responses. This is known as console or terminal interaction. The text the computer prints to the console window is known as the output of the program. Anything typed by the user is known as the console input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Class

A
A unit of code that is the basic building block of Java programs.
Oracle has established the convention that class names always begin with a capital letter, which makes it easy to recognize them. Java requires that the class name and the file name match, so this program must be stored in a file called Hello.java.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

basic form of a Java class

A

public class {

...

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

class header

A

The first line of the class is known as the class header. The word public in the header indicates that this class is available to anyone to use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Method

A
Simple methods are like verbs: They command the computer to perform some action. Inside the curly braces for a class, you can define several different methods. At a minimum, a complete program requires a special method that is known as the main method. It has the following syntax:
public static void main(String[] args) {
    ;
    ;
    ...
    ;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Statement

A

An executable snippet of code that represents a complete command.
Each statement is terminated by a semicolon; it is used to terminate statements in the same way that periods terminate sentences in English.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

String Literals (Strings):

A

In Java you specify a string literal by surrounding the literal text in quotation marks, as in
“This is a bunch of text surrounded by quotation marks.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

System.out.println

A

One of the simplest and most common statements is System.out.println, which is used to produce a line of output.

Each println statement produces a different line of output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Escape Sequences:

A

The solution is to embed what are known as escape sequences in the string literals. Escape sequences are two-character sequences that are used to represent special characters. They all begin with the backslash character ().

System.out.println(“What "characters" does this \ print?”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Identifier

A

A name given to an entity in a program, such as a class or method.
Identifiers must start with a letter, which can be followed by any number of letters or digits. The following are all legal identifiers:
first hiThere numStudents TwoBy4
The Java language specification defines the set of letters to include the underscore and dollar-sign characters (_ and $), which means that the following are legal identifiers as well:
two_plus_two _count $2donuts MAX_COUNT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Naming Conventions

A
AllMyChildren for a class name (each word starts with a capital)
allMyChildren for a method name (starts with a lowercase letter, subsequent words capitalized)
ALL_MY_CHILDREN for a constant name (all uppercase, with words separated by underscores
Don’t hesitate to use long identifiers. The more descriptive your names are, the easier it will be for people (including you) to read your programs. Descriptive identifiers are worth the time they take to type. Java’s String class, for example, has a method called compareToIgnoreCase.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Comment

A
Text that programmers include in a program to explain their code. The compiler ignores comments.
/* like this */
System.out.println("You win!"); // Good job!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Program Errors

A

Syntax errors occur when you misuse Java. They are the programming equivalent of bad grammar and are caught by the Java compiler.
Logic errors (bugs) occur when you write code that doesn’t perform the task it is intended to perform.
Runtime errors are logic errors that are so severe that Java stops your program from executing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Decomposition

A

A separation into discernible parts, each of which is simpler than the whole.
With procedural programming languages like C, decomposition involves dividing a complex task into a set of subtasks. This is a very verb- or action-oriented approach, involving dividing up the overall action into a series of smaller actions. This technique is called procedural decomposition.
Java was designed for a different kind of decomposition that is more noun- or object-oriented. Instead of thinking of the problem as a series of actions to be performed, we think of it as a collection of objects that have to interact.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Iterative Enhancement or stepwise refinement

A

The process of producing a program in stages, adding new functionality at each stage. A key feature of each iterative step is that you can test it to make sure that piece works before moving on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Static Methods

A
Java is designed for objects, and programming in Java usually involves decomposing a problem into various objects, each with methods that perform particular tasks. You will see how this works in later chapters, but for now, we are going to explore procedural decomposition. We will postpone examining some of Java’s details while we discuss programming in general.
public static void () {
    ;
    ;
    ...
    ;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Method Call

A

A command to execute another method, which causes all of the statements inside that method to be executed.

37
Q

flow of control

A

The order in which the statements of a program are executed

38
Q

type-safe language

A

Java is a type-safe language, which means that it requires you to be explicit about what kind of information you intend to manipulate and it guarantees that you manipulate the data in a reasonable manner. Everything that you manipulate in a Java program will be of a certain type, and you will constantly find yourself telling Java what types of data you intend to use.

39
Q

Data Type

A

A name for a category of data values that are all related, as in type int in Java, which is used to represent integer values. A decision was made early in the design of Java to support two different kinds of data: primitive data and objects.

40
Q

Primitive Types

A

There are eight primitive data types in Java: boolean, byte, char, double, float, int, long, and short. Four of these are considered fundamental: boolean, char, double, and int. The other four types are variations that exist for programs that have special requirements.

41
Q

Expression

A

A simple value or a set of operations that produces a value. The simplest expression is a specific value, like 42 or 28.9. We call these “literal values,” or literals.

42
Q

Evaluation

A

The process of obtaining the value of an expression.

The value obtained when an expression is evaluated is called the result.

43
Q

Operator

A

A special symbol (like + or *) that is used to indicate an operation to be performed on one or more values.
The values used in the expression are called operands.

44
Q

JShell

A

Starting with Java 9, the Java Development Kit now includes a tool called JShell that you can use to explore Java’s syntax and features. JShell is a program with a prompt where you can type arbitrary Java expressions. Once you press Enter, the expression you typed will immediately be evaluated and its result will be displayed. This kind of tool is often called a Read-Evaluate-Print Loop or REPL for short.

45
Q

Read-Evaluate-Print Loop (REPL)

A

A program that prompts the user for an individual code expression, then executes the expression and displays its result immediately.

46
Q

Literals:

A

The simplest expressions refer to values directly using what are known as literals. An integer literal (considered to be of type int) is a sequence of digits with or without a leading sign:
3 482 −29434 0 92348 +9812

47
Q

remainder operator (%)

A

The remainder operator (%) is usually referred to as the “mod operator,” or simply “mod.” The mod operator lets you know how much was left unaccounted for by the truncating division operator.

48
Q

Precedence

A

The binding power of an operator, which determines how to group parts of an expression.

49
Q

unary

A

Another concept in arithmetic is unary plus and minus, which take a single operand, as opposed to the binary operators we have seen thus far (e.g., *, /, and even binary + and −)

50
Q

Java Operator Precedence

A

unary operators
multiplicative operators
additive operators
assignment operators

51
Q

Mixing Types

A

mixing values of different types and wanting to convert from one type to another. Java has simple rules to avoid confusion and provides a mechanism for requesting that a value be converted from one type to another.
Two types that are frequently mixed are ints and doubles. Java converts the int into a double and performs the computation entirely with double values

52
Q

cast

A

Sometimes you want Java to go the other way, converting a double into an int. You can ask Java for this conversion with a cast. Think of it as “casting a value in a different light.”

53
Q

Variable

A

`A memory location with a name and a type that stores a value.

54
Q

Declaration

A

A request to set aside a new variable with a given name and type. Each variable is declared just once

55
Q

uninitialized variables

A

So how do we get values into those cells? The easiest way to do so is using an assignment statement. The general syntax of the assignment statement is
= ;
height = 70;

56
Q

incrementing

A

x = x + 1;

x += 1;

57
Q

Assignment statement

A

We have been referring to the “assignment statement,” but in fact assignment is an operator, not a statement. When you assign a value to a variable, the overall expression evaluates to the value just assigned. That means that you can form expressions that have assignment operators embedded within them. Unlike most other operators, the assignment operator evaluates from right to left

58
Q

String Concatenation

A

Combining several strings into a single string, or combining a string with other data into a new, longer string.

59
Q

promote

A

The technical term is that Java promotes the integer into a double.
x = (int) (3.4 * 2.9); // now legal

60
Q

Control Structure

A

A syntactic structure that controls other statements.

The for loop is the first example of a control structure that we will study.

61
Q

For loop pattern

A
for (int  = 1;  <= n; ++) {
    ;
    ;
    ...
    ;
}
62
Q

Scope

A

The part of a program in which a particular declaration is valid.

63
Q

Local Variable

A

A variable declared inside a method that is accessible only in that method.

64
Q

Localizing Variables

A

Declaring variables in the innermost (most local) scope possible. In general, you will want to declare variables in the most local scope possible

65
Q

Infinite Loop

A

A loop that never terminates.

66
Q

Pseudocode

A

As you write more complex algorithms, you will find that you can’t just write the entire algorithm immediately. Instead, you will increasingly make use of the technique of writing pseudocode. English-like descriptions of algorithms. Programming with pseudocode involves successively refining an informal description until it is easily translated into Java.

67
Q

Class Constant

A
A named value that cannot be changed. A class constant can be accessed anywhere in the class (i.e., its scope is the entire class).
Constants are declared with the keyword final, which indicates the fact that their values cannot be changed once assigned, as in
public static final   = ;
You can declare a constant anywhere you can declare a variable, but because constants are often used by several different methods, we generally declare them outside methods.
68
Q

Parameters

A

Any of a set of characteristics that distinguish different members of a family of tasks. To parameterize a task is to identify a set of its parameters.

69
Q

Formal Parameter

A

A variable that appears inside parentheses in the header of a method that is used to generalize the method’s behavior.

70
Q

Actual Parameter

A

A specific value or expression that appears inside parentheses in a method call.

The word “argument” is often used as a synonym for “parameter,” as in “These are the arguments I’m passing to this method.” Some people prefer to reserve the word “argument” for actual parameters and the word “parameter” for formal parameters.

71
Q

Method Overloading

A

The ability to define two or more different methods with the same name but different method signatures.

72
Q

Method Signature

A

The name of a method, along with its number and type of parameters.

73
Q

Return

A

To send a value out as the result of a method that can be used in an expression in your program. Void methods do not return any value. When Java encounters a return statement, it evaluates the given expression and immediately terminates the method, returning the value it obtained from the expression.

74
Q

return type

A

You can tell whether or not a method returns a value by looking at its header. All the methods you’ve written so far have begun with public static void. The word void is known as the return type of the method.

75
Q

The Math Class

A

Whenever you want to refer to something declared in another class, you use dot notation:
.

76
Q

Object

A

A programming entity that contains state (data) and behavior (methods).
As we said in Chapter 1, classes are the basic building blocks of Java programs. But classes also serve another purpose: to describe new types of objects.

77
Q

Class

A
A category or type of object.
When it is used this way, a class is like a blueprint of what the object looks like. Once you’ve given Java the blueprint, you can ask it to create actual objects that match that blueprint. We sometimes refer to the individual objects as instances of the class. We tend to use the words “instance” and “object” interchangeably.
78
Q

String objects

A

String objects are one of the most useful and most commonly used types of objects in Java, so they make a good starting point. They aren’t the best example of objects, though, because there are a lot of special rules that apply only to strings. You’ll notice that the type String is capitalized (as are the names of all object types in Java)

79
Q

Index

A

An integer used to specify a location in a sequence of values. Java generally uses zero-based indexing (with 0 as the first index value, followed by 1, 2, 3, and so on).

80
Q

Exception

A

A runtime error that prevents a program from continuing its normal execution.
We say that an exception is thrown when an error is encountered. When an exception is thrown, Java looks to see if you have written code to handle it If not, program execution is halted and you will see what is known as a stack trace or back trace. The stack trace shows you the series of methods that have been called, in reverse order.

81
Q

Useful String methods

A

charAt(index); indexOf(text); length(); replace(s1, s2); substring(start, stop); toLowerCase()

82
Q

Immutable Object

A

An object whose value cannot be changed. ex Strings

83
Q

Console Input

A
Responses typed by the user when an interactive program pauses for input.
When you refer to System.out, you are accessing an object in the System class known as the standard output stream, or “standard out” for short.  There is a corresponding object for standard input known as System.in, but Java wasn’t designed for console input, and System.in has never been particularly easy to use for this purpose. Fortunately for us, there is an easier way to read console input: Scanner objects.
84
Q

Constructor (Construct)

A

Most objects have to be explicitly constructed by calling a special method known as a constructor. A special syntax used to create and initialize an object. Objects in Java programs must be constructed before they can be used. Remember that a class is like a blueprint for a family of objects. Calling a constructor is like sending an order to the factory asking it to follow the blueprint to get you an actual object that you can manipulate.

85
Q

Constructor syntax

A
In Java, constructors are called using the special keyword new, followed by the object’s type and any necessary parameters. For example, to construct a specific Scanner object, you have to pass information about the source of input. In particular, you have to provide an input stream. To read from the console window, pass it System.in:
Scanner console = new Scanner(System.in);
Once you’ve constructed the Scanner, you can ask it to return a value of a particular type.
int n = console.nextInt();
86
Q

Token

A

A single element of input (e.g., one word, one number).

By default, the Scanner uses whitespace to separate tokens.

87
Q

Whitespace

A
Spaces, tab characters, and newline characters.
hello     there. "how are"        "you?"  all-one-token
would be split into six tokens:
hello
there.
"how
are"
"you?"
all-one-token
88
Q

Package

A

A collection of related Java classes. For example, the Scanner class is stored in a package known as java.util. Java programs don’t normally have access to a package unless they include an import declaration.

89
Q

Import Declaration

A

A request to access a specific Java package. Java allows you to use an asterisk to import all classes from a package:
import java.util.*;