Chapter 2 Flashcards
structure
Building ideas together so that a complex program involves a simple set of smaller parts combined.
coding
would then refer to filling in
the details of that design.
syntax
The rules that determine what is allowed in a programming language. Syntax rules specify the basic vocabulary of the language and how programs can be constructed using things like loops, branches, and subroutines. A syntactically correct program is one that
can be successfully compiled or interpreted; programs that have syntax errors will be rejected
(hopefully with a useful error message that will help you fix the problem).
semantics
Ensuring that the meaning of the results is correct or follows the logical assumptions of what the answer should be.
pragmantics/style
ensuring that the design of a program visually makes sense to the user.
subroutine call statement
It uses a “built-in subroutine”
named System.out.println to do the actual work. Recall that a subroutine consists of the
instructions for performing some task, chunked together and given a name. That name can be
used to “call” the subroutine whenever that task needs to be performed.
built-in subroutine
is one that is already defined as part of the language and therefore automatically available for use in any program.
comments
Comments in a program are entirely ignored by the computer; they are there for human readers only. // or starts with /* and ends with */
class
Not every class is a program. In order to define a program, a class must include a subroutine named main, with a definition that takes the form:
public static void main(String[] args) {
{ statements }
}
public
used in the first line of main() means that the routine can be called from outside the program. This is essential because the main() routine is called by the Java interpreter,
which is something external to the program itself
where is the subroutine located in a Java program?
between { and }.
packages
A package is a group of classes.
Class and file name rules
If the name of the class is HelloWorld, then the class must be saved in a file called HelloWorld.java
identifiers
Identifiers can be used to name classes, variables, and subroutines. An identifier is a sequence of one or
more characters. It must begin with a letter or underscore and must consist entirely of letters,
digits, and underscores. No spaces are allowed in identifiers;
reserve words
words reserved for special uses in Java that can’t be used as identifiers, such as:
class, public, static, if, else, while, and several dozen other words
What character set does Java use?
Unicode
compound names
which consist of several simple names separated by periods. (Compound names are also
called qualified names.) You’ve already seen an example: System.out.println. The idea
here is that things in Java can contain other things. A compound name is a kind of path to an
item through one or more levels of containment. The name System.out.println indicates that
something called “System” contains something called “out” which in turn contains something
called “println”.
variable
a name used to refer to data stored into memory. Its a memory location of where the data is stored.
strongly typed
means that Java strictly enforces holding the data type it was designed for and doesn’t allow you to change it.
primitive types
The primitive types are named
byte, short, int, long, float, double, char, and boolean. The first four types hold integers
(whole numbers such as 17, -38477, and 0). The four integer types are distinguished by the
ranges of integers they can hold.
float and double
types hold real numbers (such as 3.6 and
-145.99). Again, the two real types are distinguished by their range and accuracy.
char
holds a single character from the Unicode character set.
boolean
holds the logical values of true or false
byte
a variable type that holds 8 bits, which can represent any of the integers between -128 and 127, inclusive.
short
corresponds to two bytes (16 bits). Variables of type short have values in the range
-32768 to 32767.
int
corresponds to four bytes (32 bits). Variables of type int have values in the range
-2147483648 to 2147483647.
long
corresponds to eight bytes (64 bits). Variables of type long have values in the range
-9223372036854775808 to 9223372036854775807.
double
takes up 8 bytes, can range up to about 10 to the power 308, and has about
15 significant digits. Ordinarily, you should stick to the double type for real values.
literals
constant values used in variables. Example of declaring a literal is ch = ‘A’; The single quote marks are used to declare constants
tab
‘\t’ , using the escape character
carriage return
‘\r’
linefeed
‘\n’
backslash
’\’
How to express powers of 10?
“e12” and “e-108” represent powers of 10, so that
1.3e12 means 1.3 times 1012 and 12.3737e-108 means 12.3737 times 10−108.