Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
133 Cards in this Set
- Front
- Back
Algorithm
|
A step-by-step description of how to accomplish a task.
|
|
Computer
|
A universal computation device that can be programmed to execute any algorithm.
A machine that manipulates data and executes lists of instructions know as programs. |
|
Program
|
A list of instructions to be carried out by a computer.
|
|
Hardware
|
All the physical components that make up a computer.
|
|
CPU
|
(Central Processing Unit) The "brain" of the computer: it is what executes the instructions.
|
|
Memory
|
Stores programs that are being accessed, along with their data.
|
|
RAM
|
(Random Access Memory - because the computer can access any part of that memory at any time) *Is limited in size, and does not retain its contents when the computer is turned off.
|
|
Hard Disk
|
A permanent storage area for data.
|
|
Software
|
The collective definition of all computer programs.
|
|
Operating System
|
The primary piece of software running on a computer.
Provides an environment in which many programs may be run at the same time. Also provides a bridge between those programs, the hardware, and the user. |
|
user
|
The person using the computer.
|
|
Applications
|
The programs that run inside the operating system.
|
|
What happens when a user selects a program for the operating system to run?
|
The instructions from that program are loaded into the computers memory from the hard disk, the operating system allocates memory for the program to use, and the instructions to run the program are fed from memory to the CPU and executed sequentially.
|
|
Digital
|
Based on numbers that increase in discrete increments, such as the integers 0,1,2,3, ...
Because computers are digital, everything stored on computers are stored as sequences of integers. |
|
Binary Number
|
A number composed of just 0's and 1's. (also known as a base-2 number).
Computers are Binary - they store integers as binary numbers. |
|
What do the binary numbers 1, 10, 100, and 1000 have in common?
|
All are perfect powers of 2 (2^0, 2^1, 2^2, 2^3).
|
|
bit
|
A single binary digit.
|
|
byte
|
8 bits.
|
|
kilobyte (KB)
|
2^10 (1,024 bits)
|
|
megabyte
|
2^20 (1,048,576 bits)
|
|
gigabyte
|
2^30 bits
|
|
terabyte
|
2^40 bits
|
|
petabyte
|
2^50 bits
|
|
code
|
Program fragments ("these four lines of code), or the act of programming ("let's code this into java").
|
|
Program execution
|
The act of carrying out the instructions contained in a program.
|
|
"running"
|
The process of execution ("when my program runs it does something strange").
|
|
Machine Language
|
The language in which a computer program is stored internally (a series of binary numbers).
|
|
High-level programming languages
|
Languages in which modern programmers code (ex. Java).
Such programs cannot be run directly on a computer - they first have to be translated into a different form by a special program known as a compiler. |
|
Compiler
|
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).
|
|
A program that can be executed directly on a computer is known as ___________?
|
Executable
|
|
Native Compilers
|
Compilers that translate directly into machine language (the native machine language of the computer).
|
|
The lowest possible level of code on a computer
|
machine language
|
|
Java bytecodes
|
Represent an intermediate level language (not as high as Java or as low as machine language).
One set of bytecodes can execute on many different machines. The machine language of a theoretical computer known as the Java Virtual Machine (JVM). |
|
Java Virtual Machine (JVM)
|
A theoretical computer whose machine language is the set of Java bytecodes.
A JVM isn't an actual machine. When we compile programs to this level, there isn't much work remaining to turn the Java bytecodes into actual machine instructions. |
|
Java Runtime
|
A program that executes Java bytecodes.
|
|
Java Runtime Environment (JRE)
|
The standard environment for Java runtimes, distributed by Sun Microsystems.
|
|
Java Class Libraries
|
The collection of preexisting Java code that provides solutions to common programming problems.
|
|
File
|
The basic unit of storage on most computers.
|
|
File Extension
|
The part of a files name that follows the period.
Indicates the type of data contained in a file. |
|
.java
|
File extension for the jave files that you create.
|
|
.class
|
File extension for files containing the resulting Java bytecodes when you compile a Java program.
|
|
Integrated Development Environments (IDE)
|
Provides an all-in-one environment for creating, editing, compiling, and executing program files. Examples include: Eclipse, jGRASP, DrJava, BlueJ, and TestPad.
|
|
Console Window
|
A special text-only window in which Java programs interact with the user.
(The computer displays text on the screen and sometimes waits for the user to type responses- this is known as console or terminal interaction). |
|
Output
|
The text the computer prints to the console window.
|
|
Input
|
Anything typed by the user.
|
|
Class
|
A unit of code that is the basic building block of Java programs.
|
|
Should class names always begin with a capital or lowercase letter?
|
A capital letter.
|
|
Does Java require a class name and file name to match?
|
yes
|
|
Syntax Template
|
Used to describe the basic form of a Java construct.
|
|
Class Header
|
The first line of a class.
|
|
The word "public" in a class header indicates what?
|
That the class is available to anyone to use.
|
|
Method
|
A program unit that represents a particular (single) action or computation.
Methods are the next smallest units of code in Java, after classes. |
|
Method Header
|
The first line of a method.
|
|
Statement
|
An executable snippet of code that represents a complete command.
Each snippet is terminated by a semicolon. (you put together a method by stringing together statements) |
|
A Java program is stored in a ______.
|
class
|
|
Within a class there are ___________.
|
methods
|
|
At a minimum, a complete program requires a special method called _______.
|
main
|
|
Inside a method like main, there is a series of __________.
|
statements
|
|
A statement represents what?
|
A single command for the computer to execute.
|
|
String Literals
|
Literal text that is sent to the console window as output.
|
|
escape sequences
|
Two character sequences that are used to represent special characters.
(exmples: \t \n \* \\ ) |
|
\t
|
tab character
|
|
\n
|
new line character
|
|
\"
|
quotation mark
|
|
\\
|
backslash character
|
|
Should methods begin with upper or lowercase letters?
|
lowercase letters
|
|
Identifier
|
A name given to an entity in a program, such as a class or method.
Must always start with a letter, which can be followed by any number of letters or digits. |
|
Syntax Errors
|
They are the programming equivalent of bad grammar and are caught by the Java compiler.
|
|
Logic Errors
|
Occur when you write code that doesn't perform that task it is intended to perform.
|
|
Runtime Errors
|
Are logic errors that are so severe that Java stops your program from executing.
|
|
An algorithm must be:
|
• precise: specified in a clear and unambiguous way
• effective: capable of being carried out |
|
In programming, a group of statements that repeats
is known as a _________. |
loop
|
|
Variable
|
A named location in the computer's memory
that is used to store a value. |
|
Operators
|
Create a new value from existing values/variables.
|
|
Boolean Values
|
• true or false
|
|
Conditional Execution
|
Deciding whether to execute
one or more statements on the basis of some condition. |
|
Format of a Java Class
|
• General syntax:
public class <name> { code goes here… } where <name> is replaced by the name of the class. |
|
Methods
|
• A method is a collection of instructions that perform
some action or computation. • Every Java program must include a method called main. • contains the instructions that will be executed first when the program is run |
|
General syntax for the main method:
|
public static void main(String[] args) {
<statement>; <statement>; … <statement>; } where each <statement> is replaced by a single instruction. |
|
The main method always begins with:
|
public static void main(String[] args)
|
|
Identifiers
|
• Used to name the components of a Java program like
classes and methods. Rules: • must begin with a letter (a-z, A-Z), $, or _ • can be followed by any number of letters, numbers, $, or _ • spaces are not allowed • cannot be the same as a keyword – a word like class that is part of the language itself. |
|
Conventions for Identifiers
|
• Capitalize class names.
• example: HelloWorld • Do not capitalize method names. • example: main • Capitalize internal words within the name. • example: HelloWorld |
|
string literal
|
• A piece of text like "Hello, world".
• string: a collection of characters • literal: specified explicitly in the program ("hard-coded") |
|
simple methods (syntax):
|
public static void <name>() {
<statement>; <statement>; … <statement>; } • This type of method is known as static method. |
|
method call
|
• General syntax for a static method call:
<method-name>(); example: writeE(); • Calling a method causes the statements inside the method to be executed |
|
Flow of Control
|
• A program's flow of control is the order in which its
statements are executed. • By default, the flow of control: • is sequential • begins with the first statement in the main method • When we call a method, the flow of control jumps to the method. • After the method completes, the flow of control jumps back to the point where the method call was made. |
|
Procedural Decomposition
|
• In general, methods allow us to decompose a problem into
smaller subproblems that are easier to solve. • the resulting code is also easier to understand and maintain. |
|
structure diagram
|
Used to show procedural decomposition.
|
|
Comments
|
• Comments are text that is ignored by the compiler.
• Used to make programs more readable • Two types: 1. line comments: begin with // • compiler ignores from // to the end of the line 2. block comments: begin with /* and end with */ • compiler ignores everything in between • typically used at the top of each source file |
|
Put comments:
|
• at the top of each file, naming the author and explaining
what the program does • at the start of every method other than main, describing its behavior • inside methods, to explain complex pieces of code |
|
Overview of the Programming Process:
|
Step 1: Analysis and Specification
Step 2: Design Step 3: Implementation Step 4: Testing and Debugging |
|
Step 1: Analysis and Specification
|
• Analyze the problem (making sure that you understand it),
and specify the problem requirements clearly and unambiguously. • Describe exactly what the program will do, without worrying about how it will do it |
|
Step 2: Design
|
• Determine the necessary algorithms (and possibly other
aspects of the program) and sketch out a design for them. • This is where we figure out how the program will solve the problem. • Algorithms are often designed using pseudocode. • more informal than an actual programming language • allows us to avoid worrying about the syntax of the language |
|
Step 3: Implementation
|
• Translate your design into the programming language.
pseudocode --> code |
|
Step 4: Testing and Debugging
|
• A bug is an error in your program.
• Debugging involves finding and fixing the bug • Testing – trying the programs on a variety of inputs – helps us to find the bugs. |
|
Literals
|
Specify a particular value.
They include: • string literals: "Your total in cents is:" • are surrounded by double quotes • numeric literals: 25 3.1416 • commas are not allowed! |
|
Variables
|
Named memory locations
that are used to store a value. • Variable names must follow the rules for identifiers |
|
Expressions
|
• Expressions are pieces of code that evaluate to a value.
• They include: • literals, which evaluate to themselves • variables, which evaluate to the value that they represent • combinations of literals, variables, and operators: 25*quarters + 10*dimes + 5*nickels + pennies |
|
Numerical operators include:
|
+ addition
- subtraction * multiplication / division % modulus or mod: gives the remainder of a division |
|
println Statements
|
System.out.println(<expression>);
• Where <expression> can be any type of expression (not just text). |
|
Data Types
|
• A data type is a set of related data values.
examples: • integers • strings • characters • Every data type in Java has a name that we can use to identify it. |
|
int
|
Data type used for integers
• examples: 25 -2 |
|
double
|
Data type used for real numbers (ones with a fractional part)
• examples: 3.1416 -15.2 • used for any numeric literal with a decimal point, even if it's an integer: 5.0 • also used for any numeric literal written in scientific notation 3e8 -1.60e-19 |
|
Declaring a Variable
|
• syntax:
<type> <name>; • Java requires that we specify the type of a variable before attempting to use it. • A variable declaration can also include more than one variable of the same type: int quarters, dimes; |
|
Assignment Statements
|
• Syntax:
<variable> = <expression>; • Used to give a value to a variable. • An assignment statement does not create a permanent relationship between variables. = is known as the assignment operator. |
|
Rules for numeric operators:
|
• if the operands are both of type int, the int version of the operator is used.
• if at least one of the operands is of type double, the double version of the operator is used. |
|
The int version of the / operator performs
|
integer division,
which discards the fractional part of the result (i.e., everything after the decimal). • examples: > 5 / 3 1 > 11 / 5 2 |
|
The double version of the / operator performs
|
floating-point division, which keeps the fractional part.
• examples: > 5.0 / 3.0 1.6666666666666667 > 11 / 5.0 2.2 |
|
String Concatenation
|
• The meaning of the + operator depends on the types of the operands.
• When at least one of the operands is a string, the + operator performs string concatenation. • combines two or more strings into a single string. • example: System.out.println("total in cents: " + cents); |
|
Type Casts
|
• General syntax for a type cast:
(<type>)<variable> • Tells Java to treat at least one of the operands as a certain type (int, double, etc). • example: grade = (double)pointsEarned / possiblePoints * 100; or grade = pointsEarned / (double)possiblePoints * 100; |
|
Java’s Integer Types
|
Java’s actually has four primitive types for integers, all of which represent signed integers:
byte (8 bits), short (16 bits), int (32 bits), and long (64 bits). • We typically use int, unless there’s a good reason not to. |
|
When we allow for negative integers (which Java does)
n bits can represent any integer from: |
-2^(n-1) to 2^(n-1) -1
• there's one fewer positive value to make room for 0 |
|
Java’s Floating-Point Types
|
• Java has two primitive types for floating-point numbers:
float (32 bits) and double (64 bits). • We typically use double because of its greater precision |
|
Increment Operators
|
Syntax:
i++; • ++ is known as the increment operator. • increment = increase by 1 |
|
Decrement Operators
|
Syntax:
i--; • decrement operator (--). • decrement = decrease by 1 |
|
for Loops
|
• To repeat one or more statements multiple times, we can use a construct known as a for loop.
• Syntax: for (<initialization>; <continuation test>; <update>) } <one or more statements> } example: public static void writeL() { for (int i = 0; i < 7; i++) { System.out.println("|"); } System.out.println("+----------"); } |
|
body of a for loop
|
The statements inside the loop.
|
|
How many times is the initialization performed in a for loop?
|
Only once.
|
|
When is the body of a for loop executed?
|
Only when the test is true.
(the for loop will continue to do test, body, update until the test is false) |
|
Definite Loops
|
Repeat actions a fixed number of times(iterations).
• To repeat the body of a loop <N> times, we typically take one of the following approaches: for (int i = 0; i < <N>; i++) { <body of the loop> } OR for (int i = 1; i <= <N>; i++) { <body of the loop> } |
|
Each time that the body of a loop is executed is known an ___________ of the loop.
|
Iteration
|
|
• Instead of writing
i = i + 2; we can use a shortcut and just write: |
i += 2;
• In general <variable> += <expression>; is equivalent to <variable> = <variable> + (<expression>); |
|
<var> ++;
Equivalent to? (for loop updates) |
<var> = <var> + 1;
|
|
<var> --;
Equivalent to? (for loop updates) |
<var> = <var> – 1;
|
|
<var> += <expr>;
Equivalent to? (for loop updates) |
<var> = <var> + (<expr>);
|
|
<var> -= <expr>;
Equivalent to? (for loop updates) |
<var> = <var> – (<expr>);
|
|
<var> *= <expr>;
Equivalent to? (for loop updates) |
<var> = <var> * (<expr>);
|
|
<var> /= <expr>;
Equivalent to? (for loop updates) |
<var> = <var> / (<expr>);
|
|
<var> %= <expr>;
Equivalent to? (for loop updates) |
<var> = <var> % (<expr>);
|
|
which syntax is correct in for loop updates (shortcuts)?
+= or =+ |
+= is correct
=+ is not! |
|
nested loop
|
one loop inside another.
• When you have a nested loop, the inner loop is executed to completion for every iteration of the outer loop. example: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { System.out.print("*"); } System.out.println(); } |
|
Variable Scope
|
• The scope of a variable is the portion of a program
in which the variable can be used. • begins at the point at which it is declared • ends at the closest closing curly brace (}) that encloses the declaration • Because of these rules, a variable declared inside of a method cannot be used outside of that method. • such variables are called local variables |
|
class constants
|
• like variables, but their values are fixed
• can be used throughout the program • General syntax: public static final <type> <name> = <expression>; • conventions: • capitalize all letters in the name • put an underscore ('_') between multiple words • We declare it at the very start of the class: public class DrawTorch2 { public static final int SCALE_FACTOR = 2; ... |