Exam 1 Flashcards
Algorithm
A step-by-step description of how to accomplish a task.
Program
A list of instructions to be carried out by a computer.
Hardware
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
Software
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.
Digital
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
Binary Number
A number composed of just 0s and 1s, also known as a base-2 number.
Program Execution
The act of carrying out the instructions contained in a program.
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).
executable
A compiler that translates directly into machine language creates a program that can be executed directly on the computer, known as an executable.
native compilers
We refer to such compilers as native compilers because they compile code to the lowest possible level (the native machine language of the computer).
Java bytecodes
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).
Java Virtual Machine
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).
Java Runtime
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.
Java
A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded, dynamic language.2
Java Class Libraries
The collection of preexisting Java code that provides solutions to common programming problems.
platform independent
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.
The Java Programming environment (steps):
Type in a program as a Java class.
Compile the program file.
Run the compiled version of the program.
File extensions
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.
Integrated Development Environments, or IDEs
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.
Console Window
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.
Class
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.
basic form of a Java class
public class {
...
}
class header
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.
Method
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) { ; ; ... ; }
Statement
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.
String Literals (Strings):
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.”
System.out.println
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.
Escape Sequences:
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?”);
Identifier
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
Naming Conventions
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.
Comment
Text that programmers include in a program to explain their code. The compiler ignores comments. /* like this */ System.out.println("You win!"); // Good job!
Program Errors
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.
Decomposition
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.
Iterative Enhancement or stepwise refinement
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.
Static Methods
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 () { ; ; ... ; }