Chapter 1 Flashcards

1
Q

What is a program?

A

consists of instructions executing one at time. Basic instruction types include Input, Process, output.

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

Define input

A

A program gets data, perhaps from a file, keyboard, touchscreen, network.

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

Define a Process

A

A program performs computations on data such as adding two values like x+y

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

Define Output

A

A program puts that data somewhere like a file, screen, network, etc…

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

Define computational thinking

A

creating a sequence of instructions to solve a problem

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

Define an algorithm

A

Sequence of instructions that solves a problem

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

Each statement typically appears alone on a line and ends with a _?

A

semicolon

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

int stands for?

A

Integer. example: int wage. The statement int wage; creates a variable named wage that is used to hold the variable. The variable wage can be assigned with a different value later in the program, so because the value held can vary, the item is called a variable. Program variables are different from variables in algebra.

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

Program execution begins at main() and executes statements surrounded by which symbols?

A

{ }

Program execution begins at main() and executes statements surrounded by which symbols?

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

Define Scanner

A

a text parser that can get numbers, words, or phrases from an input source such as the keyboard.

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

What is the statement to create a scanner onject

A

scnr = new Scanner(System.in);. System.in corresponds to keyboard input. Then, given Scanner object scnr, the following statement gets an input value and assigns x with that value: x = scnr.nextInt()

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

Define String Literal

A

Text in double quotes “ “ Outputting text is achieved via: System.out.print(“desired text”);

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

How do you out out a blank line?

A

System.out.println().

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

Define comment

A

Text ap rogrammer adds to code, to be read by humans to better understand the code but ignored by the compiler. Two common kinds of comments exist:

A single-line comment starts with // and includes all the following text on that line. Single-line comments commonly appear after a statement on the same line.
A multi-line comment starts with /* and ends with /, where all text between / and */ is part of the comment. A multi-line comment is also known as a block comment.

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

Define a single-line comment

A

A single-line comment starts with // and includes all the following text on that line. Single-line comments commonly appear after a statement on the same line.

Example
/*
This program calculates the amount of pasta to cook, given the
number of people eating.

Author: Andrea Giada
Date: May 30, 2017
*/

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

Define a multi-line comment

A

starts with /* and ends with /, where all text between / and */ is part of the comment. A multi-line comment is also known as a block comment. Example
int totalOuncesPasta; // Total ounces of pasta to serve numPeople

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

Define Whitespace

A

Whitespace refers to blank spaces (space and tab characters) between items within a statement and blank lines between statements (called newlines). A compiler ignores most whitespace.

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

Describe Good practice is to deliberately and consistently use whitespace to make a program more readable. Programmers usually follow conventions defined by their company, team, instructor, etc., such as:

A

Use blank lines to separate conceptually distinct statements.
Indent lines the same amount.
Align items to reduce visual clutter.
Use a single space before and after any operators like =, +, *, or / to make statements more readable.

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

Define Syntax error

A

is to violate a programming language’s rules on how symbols can be combined to create a program. An example is forgetting to end a statement with a semicolon

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

Find the syntax errors. Assume variable numDogs has been declared.

1)
System.out.print(numDogs).

A

Error Statements end with a semicolon, not period.

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

Find the syntax errors. Assume variable numDogs has been declared

System.out.print(“Dogs: “ numDogs);

A

Error

Missing + before numDogs

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

Find the syntax errors. Assume variable numDogs has been declared

system.out.print(“Everyone wins.”);

A

Error

Should be an uppercase S in System.

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

Find the syntax errors. Assume variable numDogs has been declared

System.out.print(“Hello friends!);

A

Error

Missing the ending “, as in: System.out.print(“Hello friends!”);

24
Q

Find the syntax errors. Assume variable numDogs has been declared

System.out.print(“Amy // Michael”);

A

NO error

Some might think // creates a problem, but the compiler does not treat // as a comment when within a string literal.

25
Q

Find the syntax errors. Assume variable numDogs has been declared

System.out.print(NumDogs);

A

Error

The declared variable was numDogs, not NumDogs. The compiler will report that NumDogs has not been declared.

26
Q

Find the syntax errors. Assume variable numDogs has been declared

int numCats
numCats = 3;
System.out.print(numCats)

A

Error

Missing a semicolon after int numCats.

27
Q

Find the syntax errors. Assume variable numDogs has been declared

System.print(numDogs);

A

Error

Should be System.out.print, not System.print

28
Q

True or False

When a compiler says that an error exists on line 5, that line must have an error.

A

False

The error may actually exist in an earlier line, but the compiler didn’t get confused until reaching line 5

29
Q

True or False

If a compiler says that an error exists on line 90, the actual error may be on line 91, 92, etc.

A

False

The actual error may be in an earlier line, but the compiler wasn’t able to realize the error immediately, so proceeds to subsequent lines, then gets confused and reports an error.

30
Q

True or False

If a compiler generates a specific message like “missing semicolon”, then a semicolon must be missing somewhere, though maybe from an earlier line.

A

False

The actual error could be different, like missing parentheses. If a programmer makes a mistake, the statement and subsequent statements may still be valid code, but eventually the compiler cannot make sense of the code and generates an error message.

31
Q

What is a compile -time-error?

A

Syntax error

32
Q

What is a logic error? AKA a Bug?

A

an error that occurs while a program runs. For example, a programmer might mean to type numBeans * numJars but accidentally types numBeans + numJars (+ instead of *). The program would compile but would not run as intended.

33
Q

Define Compiler warnings

A

A compiler will sometimes report a warning, which doesn’t stop the compiler from creating an executable program but indicates a possible logic error. Ex: Some compilers will report a warning like “Warning, dividing by 0 is not defined” if encountering code like: totalItems = numItems / 0 (running that program does result in a runtime error). Even though the compiler may create an executable program, good practice is to write programs that compile without warnings.

34
Q

Define Processors and instruction

A

circuits called processors were created to process (aka execute) a list of desired calculations, with each calculation called an instruction. Instructions are stored in a memory.

35
Q

Define memory

A

A memory is a circuit that can store 0s and 1s in each of a series of thousands of addressed locations, like a series of addressed mailboxes that each can store an envelope (the 0s and 1s). Instructions operate on data, which is also stored in memory locations as 0s and 1s.

36
Q

Define App and Application

A

programmer-created sequence of instructions is called a program or application,

Another word for program.
The programmer-created sequence of instructions is called a program, application, or just app.

37
Q

How are Machine Instructions represented?

What do you call a sequence of machine instruction?

Define Machine Instructions

A

Instructions represented as 0s and 1s.

Executable Program

A series of 0s and 1s, stored in memory, that tells a processor to carry out a particular operation like a multiplication.
0s and 1s are hard to comprehend. Most programmers specify the program’s functionality in a high-level language, which is then automatically translated to low-level machine instructions.

38
Q

Define assembly

Define Assembly language

A

programmers soon created programs called assemblers to automatically translate human readable instructions, such as “Mul 97, #9, 98”, known as assembly language instructions, into machine instructions. The assembler program thus helped programmers write more complex programs.

Human-readable processor instructions.
An assembler is a program that translates assembly language instructions into machine instructions

39
Q

Define Compiler

A

programs that automatically translate high-level language programs into executable programs.

Translates a high-level language program into low-level machine instructions.
A compiler ensures a program is valid according to the language’s rules, performs optimizations, then converts to the low-level machine instructions.

40
Q

Define bytecode

Define Virtual Machine

A

The sequence of machine instructions, AKA Executable, using machine instructions of a “virtual” processor

Real processor runs a program, sometimes called a virtual machine, that executes the instructions in the bytecode.

40
Q

Define bytecode

Define Virtual Machine

A

The sequence of machine instructions, AKA Executable, using machine instructions of a “virtual” processor

Real processor runs a program, sometimes called a virtual machine, that executes the instructions in the bytecode.

41
Q

Computers consist of seveal componets

A

Input/output devices: A screen (or monitor) displays items to a user. The above examples displayed textual items, but today’s computers display graphical items, too. A keyboard allows a user to provide input to the computer, typically accompanied by a mouse for graphical displays. Keyboards and mice are increasingly being replaced by touchscreens. Other devices provide additional input and output means, such as microphones, speakers, printers, and USB interfaces. I/O devices are commonly called peripherals.

Storage: A disk (aka hard drive) stores files and other data, such as program files, song/movie files, or office documents. Disks are non-volatile, meaning they maintain their contents even when powered off. They do so by orienting magnetic particles in a 0 or 1 position. The disk spins under a head that pulses electricity at just the right times to orient specific particles (you can sometimes hear the disk spin and the head clicking as the head moves). New flash storage devices store 0s and 1s in a non-volatile memory, rather than disk by tunneling electrons into special circuits on the memory’s chip and removing them with a “flash” of electricity that draws the electrons back out.

Memory: RAM (random-access memory) temporarily holds data read from storage and is designed such that any address can be accessed much faster than disk, in just a few clock ticks (see below) rather than hundreds of ticks. The “random access” term comes from being able to access any memory location quickly and in arbitrary order, without having to spin a disk to get a proper location under a head. RAM is costlier per bit than disk, due to RAM’s higher speed. RAM chips typically appear on a printed-circuit board along with a processor chip. RAM is volatile, losing its contents when powered off. Memory size is typically listed in bits or in bytes, where a byte is 8 bits. Common sizes involve megabytes (million bytes), gigabytes (billion bytes), or terabytes (trillion bytes).

Processor: The processor runs the computer’s programs, reading and executing instructions from memory, performing operations, and reading/writing data from/to memory. When powered on, the processor starts executing the program whose first instruction is (typically) at memory location 0. That program is commonly called the BIOS (basic input/output system), which sets up the computer’s basic peripherals. The processor then begins executing a program called an operating system (OS). The operating system allows a user to run other programs and interfaces with the many other peripherals. Processors are also called CPUs (central processing units) or microprocessors (a term introduced when processors began fitting on a single chip, the “micro-“ suggesting something small). Because speed is so important, a processor may contain a small amount of RAM on its own chip, called cache memory, accessible in one clock tick rather than several, for maintaining a copy of the most-used instructions/data.

Clock:

42
Q

Define transistors and integrated circuits

A

After computers were invented and occupied entire rooms, engineers created smaller switches called transistors, which in 1958 were integrated onto a single chip called an integrated circuit, or IC. Engineers continued to make transistors smaller, leading to Moore’s Law: the doubling of IC capacity roughly every 18 months, which continued for several decades.

43
Q

Define Clock

A

Rate at which a processor executes instructions.
A faster clock means faster running programs, but more electrical cost, more heat (and hence a need for cooling fans), and shorter battery life.

A processor’s instructions execute at a rate governed by the processor’s clock, which ticks at a specific frequency. Processors have clocks that tick at rates such as 1 MHz (1 million ticks/second) for an inexpensive processor ($1) like those found in a microwave oven or washing machine, to 1 GHz (1 billion ticks/second) for costlier ($10-$100) processors like those found in mobile phones and desktop computers. Executing about 1 instruction per clock tick, processors thus execute millions or billions of instructions per second.

44
Q

Define Operating System

A

Manages programs and interfaces with peripherals.
Common operating systems include Windows, Mac OS X, and Linux for desktop computers, and iOS and Android for tablets and smartphones.

45
Q

Define Disk

A

Nonvolatile storage with slower access.

Disks are nonvolatile, meaning a disk maintains stored contents even when powered off.

46
Q

Define Ram

A

Volatile storage with faster access usually located off processor chip.
Memory is also called RAM, short for Random Access Memory.

47
Q

Define Cache

A

Relatively small volatile storage with fastest access, which is located on the processor chip.
The CPU is usually accessing items in the cache, and only occasionally has to copy needed items between memory and cache. A larger cache results in faster-running programs due to less time spent copying.

48
Q

What language was discovered in 1978, Brian Kernighan and Dennis Ritchie at AT&T Bell Labs (which used computers extensively for automatic phone call routing) published a book describing a new high-level language

A

C

49
Q

In 1985, Bjarne Stroustrup published a book describing a C-based language

A

called C++, adding constructs to support a style of programming known as object-oriented programming, along with other improvements. The unusual ++ part of the name comes from ++ being an operator in C that increases a number, so the name C++ suggests an increase or improvement over C.

50
Q

In 1991, James Gosling and a team of engineers at Sun Microsystems (acquired by Oracle in 2010) began developing what language?

A

he Java language with the intent of creating a language whose executable could be ported to different processors, with the first public release in 1995.
The language had a C/C++ style and for portability reasons was designed to execute on a virtual machine. Java was initially intended to be run on consumer appliances like interactive TVs. Web browsers like Netscape Navigator began providing support for running Java programs within the browser, bringing much attention to the language. The Java language continues to evolve for the programming of traditional computers and consumer devices. Java should not be confused with JavaScript, which is an entirely different language used for developing web applications that was named similarly.

51
Q

Define problem solving

A

creating a methodical solution to a given task.

52
Q

For program output, Define whitespace

A

any blank space or newline. Most coding activities strictly require a student program’s output to exactly match the expected output, including whitespace.

53
Q

The following codes do what?

import java.util.Scanner;

Scanner scnr = new Scanner(System.in);

A

the code at the top of a file enables the program to get input:

Getting input is achieved by first creating a Scanner object via the statement System.in corresponds to keyboard input. Then, given Scanner object scnr,

54
Q
What does this cod output?
public class Salary {
   public static void main(String [] args) {
      int wage;
      Scanner scnr = new Scanner(System.in);
      wage = scnr.nextInt();
  System.out.print("Salary is ");
  System.out.println(wage * 40 * 52);
A

Salary is 41600

55
Q
Outputting multiple items using one output statement.
public class Salary {
   public static void main (String [] args) {
      int wage;
  wage = 20;

  System.out.println("Wage is: " + wage); 
  System.out.println("Goodbye.");     } }
A
Outputting multiple items using one output statement.
public class Salary {
   public static void main (String [] args) {
      int wage;
  wage = 20;
      System.out.println("Wage is: " + wage); 
      System.out.println("Goodbye."); 
   }
}
Wage is: 20
Goodbye.