This link has been bookmarked by 10 people . It was first bookmarked on 25 Sep 2008, by William Hummel.
-
01 Feb 15
-
These reserved words include: class, public, static, if, else, while, and several dozen other words.
-
a variable is not a name for the data itself but for a location in memory that can hold data.
-
An assignment statement takes the form:
variable = expression;
-
it evaluates the expression and puts the resulting data value into the variable.
-
expression represents anything that refers to or computes a data value.
-
When a variable is used on the left-hand side of an assignment statement, it refers to the box that is named by the variable.
-
For example, suppose a program includes the statement "rate = 0.07;". If the statement "interest = rate * principal;" is executed later in the program, can we say that the principal is multiplied by 0.07? No! The value of rate might have been changed in the meantime by another statement.
-
A variable in Java is designed to hold only one particular type of data; it can legally hold that type of data and no other.
-
The primitive types are named byte, short, int, long, float, double, char, and boolean
-
A literal is something that you can type in a program to represent a value. It is a kind of name for a constant value.
-
-
29 Apr 13
-
In particular, a tab is represented as '\t', a carriage return as '\r', a linefeed as ' ', the single quote character as '\'', and the backslash itself as '\\'. Note that even though you type two characters between the quotes in '\t', the value represented by this literal is a single tab character.
-
when x is a variable of type float. You have to say "x = 1.2F;". This is one reason why I advise sticking to type double for real numbers.
-
Octal numbers use only the digits 0 through 7. In Java, a numeric literal that begins with a 0 is interpreted as an octal number; for example, the literal 045 represents the number 37
-
The letters represent the numbers 10 through 15. In Java, a hexadecimal literal begins with 0x or 0X, as in 0x45 or 0xFF7A
-
'\u00E9' represents the Unicode character that is an "e" with an acute accent.
-
Variables declared inside a subroutine are called local variables for that subroutine. They exist only inside the subroutine, while it is running, and are completely inaccessible from outside.
-
-
09 Dec 11
-
names
-
Unicode
-
compound names
-
qualified names
-
simple identifiers
-
identifier
-
names are used instead of numbers to refer to data
-
variable
-
a location in memory that can hold data.
-
assignment statement
-
strongly typed
-
primitive types
-
literal
-
String
-
variable declaration statement
-
local variables
-
-
19 Dec 10
-
names of variables and of subroutines begin with lower case letters
-
names of classes to begin with upper case letters
-
camel case
-
compound names
-
A compound name is a kind of path to an item through one or more levels of containment.
-
primitive types
-
The float and double types hold real numbers
-
boolean holds one of the two logical values true or false
-
char holds a single character
-
string of eight bits is called a byte
-
other integer types
-
short corresponds to two bytes
-
int corresponds to four bytes
-
long corresponds to eight bytes
-
The value of a char variable is a single character
-
A name for a constant value is called a literal.
-
To make a literal of type float, you have to append an "F"
-
sticking to type double for real numbers
-
You can make a literal of type long by adding "L" as a suffix.
-
Within a string, special characters can be represented using the backslash notation
-
linefeed
-
-
27 Oct 10
-
10 Sep 09
-
No spaces are allowed in identifiers;
-
Certain names are reserved for special uses in Java, and cannot be used by the programmer for other purposes. These reserved words include: class, public, static, if, else, while, and several dozen other words.
-
it is customary for names of classes to begin with upper case letters, while names of variables and of subroutines begin with lower case letters;
-
do not use underscores in names, although some do use them at the beginning of the names of certain kinds of variables. When a name is made up of several words, such as HelloWorld or interestRate, it is customary to capitalize each word, except possibly the first; this is sometimes referred to as camel case,
-
In Java, the only way to get data into a variable -- that is, into the box that the variable names -- is with an assignment statement. An assignment statement takes the form:
variable = expression;
where expression represents anything that refers to or computes a data value
-
when a variable is used in an expression, it is the value stored in the variable that matters; in this case, the variable seems to refer to the data in the box, rather than to the box itself.
-
A variable in Java is designed to hold only one particular type of data
-
A variable can be used in a program only if it has first been declared. A variable declaration statement is used to declare one or more variables and to give them names. When the computer executes a variable declaration, it sets aside memory for the variable and associates the variable's name with that memory. A simple variable declaration takes the form:
type-name variable-name-or-names;
-
rence: Declare important variables at the beginning of the subroutine, and use a comment to explain the purpose of each variable. Declare "utility variables" which are not important to the overall logic of the subroutine at the point in the subroutine where they are first used
-
. A parameter provides a subroutine with information it needs to perform its task. In a subroutine call statement, any parameters are listed in parentheses after the subroutine name. Not all subroutines have parameters. If there are no parameters in a subroutine call statement, the subroutine name must be followed by an empty pair of parentheses.
-
-
02 Sep 09
-
For example, it is customary for names of classes to begin with upper case letters, while names of variables and of subroutines begin with lower case letters; you can avoid a lot of confusion by following the same convention in your own programs
-
When a name is made up of several words, such as HelloWorld or interestRate, it is customary to capitalize each word, except possibly the first;
-
-
25 Sep 08
-
Names are fundamental to programming
-
According to the syntax rules of Java, a name 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. ("Underscore" refers to the character '_'.) For example, here are some legal names:
N n rate x15 quite_a_long_name HelloWorld
No spaces are allowed in identifiers; HelloWorld is a legal identifier, but "Hello World" is not. Upper case and lower case letters are considered to be different, so that HelloWorld, helloworld, HELLOWORLD, and hElloWorLD are all distinct names.
-
reserved words include: class, public, static, if, else, while, and several dozen other words.
-
Unicode character set, which includes thousands of characters from many different languages and different alphabets, and many of these characters count as letters or digits. However, I will be sticking to what can be typed on a regular English keyboard.
-
it is customary for names of classes to begin with upper case letters, while names of variables and of subroutines begin with lower case letters; you can avoid a lot of confusion by following the same convention in your own programs. Most Java programmers do not use underscores in names, although some do use them at the beginning of the names of certain kinds of variables. When a name is made up of several words, such as HelloWorld or interestRate, it is customary to capitalize each word, except possibly the first; this is sometimes referred to as camel case, since the upper case letters in the middle of a name are supposed to look something like the humps on a camel's back.
-
Finally, I'll note that things are often referred to by compound names which consist of several ordinary 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". Non-compound names are called simple identifiers.
-
In a high-level language such as Java, names are used instead of numbers to refer to data. It is the job of the computer to keep track of where in memory the data is actually stored; the programmer only has to remember the name. A name used in this way -- to refer to data stored in memory -- is called a variable.
-
You should think of a variable as a container or box where you can store data that you will need to use later. The variable refers directly to the box and only indirectly to the data in the box. Since the data in the box can change, a variable can refer to different data values at different times during the execution of the program, but it always refers to the same box.
-
In Java, the only way to get data into a variable -- that is, into the box that the variable names -- is with an assignment statement. An assignment statement takes the form:
variable = expression;
where expression represents anything that refers to or computes a data value.
-
The variable in this assignment statement is rate, and the expression is the number 0.07. The computer executes this assignment statement by putting the number 0.07 in the variable rate, replaci
-
Java is a strongly typed language because it enforces this rule
-
There are eight so-called primitive types built into Java. 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. The 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. A variable of type char holds a single character from the Unicode character set. And a variable of type boolean holds one of the two logical values true or false.
-
the byte data type refers to a single byte of memory. A variable of type byte holds a string of eight 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.
-
The float data type is represented in four bytes of memory, using a standard method for encoding real numbers. The maximum value for a float is about 10 raised to the power 38. A float can have about 7 significant digits. (So that 32.3989231134 and 32.3989234399 would both have to be rounded off to about 32.398923 in order to be stored in a variable of type float.) A 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.
-
A variable of type char occupies two bytes in memory. The value of a char variable is a single character such as A, *, x, or a space character. The value can also be a special character such a tab or a carriage return or one of the many Unicode characters that come from different languages. When a character is typed into a program, it must be surrounded by single quotes; for example: 'A', '*', or 'x'. Without the quotes, A would be an identifier and * would be a multiplication operator. The quotes are not part of the value and are not stored in the variable; they are just a convention for naming a particular character constant in a program.
-
A name for a constant value is called a literal. A literal is what you have to type in a program to represent a value. 'A' and '*' are literals of type char, representing the character values A and *. Certain special characters have special literals that use a backslash, \, as an "escape character". In particular, a tab is represented as '\t', a carriage return as '\r', a linefeed as ' ', the single quote character as '\'', and the backslash itself as '\\'. Note that even though you type two characters between the quotes in '\t', the value represented by this literal is a single tab character.
-
Any numerical literal that contains a decimal point or exponential is a literal of type double.
-
You can make a literal of type long by adding "L" as a suffix. For example: 17L or 728476874368L. As another complication, Java allows octal (base-8) and hexadecimal (base-16) literals.
-
A variable can be used in a program only if it has first been declared. A variable declaration statement is used to declare one or more variables and to give them names. When the computer executes a variable declaration, it sets aside memory for the variable and associates the variable's name with that memory. A simple variable declaration takes the form:
type-name variable-name-or-names;
The variable-name-or-names can be a single variable name or a list of variable names separated by commas. (We'll see later that variable declaration statements can actually be somewhat more complicated than this.) Good programming style is to declare only one variable in a declaration statement, unless the variables are closely related in some way. For example:
int numberOfStudents; String name; double x, y; boolean isFinished; char firstInitial, middleInitial, lastInitial;
-
Variables declared inside a subroutine are called local variables for that subroutine. They exist only inside the subroutine, while it is running, and are completely inaccessible from outside. Variable declarations can occur anywhere inside the subroutine, as long as each variable is declared before it is used in any expression.
-
Note that the value to be displayed by System.out.print or System.out.println is provided in parentheses after the subroutine name. This value is called a parameter to the subroutine. A parameter provides a subroutine with information it needs to perform its task. In a subroutine call statement, any parameters are listed in parentheses after the subroutine name. Not all subroutines have parameters. If there are no parameters in a subroutine call statement, the subroutine name must be followed by an empty pair of parentheses.
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.