Sunday, May 27, 2012
Visibility
"Controlling Access to Members of a Class (The Java™ Tutorials > Learning the Java Language > Classes and Objects)" ( http://bit.ly/JgfUgH )
What is a Constant? Final keyword
DOWNLOAD THE CODE: FinalValuePkg
We can store a value in a constant. Very similar to a variable except that a constant has a constant value. That is, the stored value is never changed as a result of processing.
Constants are used where a value should never be changed such as a maximum, minimum, number of hours in a day, days in a week, etc.
A constant begins with the keyword final. Just as with a variable, a type & identifier must be given.
CIRCLE_WIDTH and CIRCLE_HEIGHT are defined using uppercase and have each been assigned a value.
"Java Syntax: Declaring and Using Constants in Java" ( http://bit.ly/JmgF5S )
Here's a cat:
We can store a value in a constant. Very similar to a variable except that a constant has a constant value. That is, the stored value is never changed as a result of processing.
Constants are used where a value should never be changed such as a maximum, minimum, number of hours in a day, days in a week, etc.
A constant begins with the keyword final. Just as with a variable, a type & identifier must be given.
The compiler will not allow any processing statements to change the values of these constants.
UML Class Diagram Notation
The UML Class Diagram notation for a constant (final) is as below:
CIRCLE_WIDTH and CIRCLE_HEIGHT are defined using uppercase and have each been assigned a value.
"Java Syntax: Declaring and Using Constants in Java" ( http://bit.ly/JmgF5S )
Here's a cat:
Wednesday, May 23, 2012
The split function
DOWNLOAD THE CODE: usingSplit.java.zip
Example 1: split a string using a space as the delimiter:
Output:
Example 2: split a string using a comma (,) as the delimiter:
Output:
Boolean
The boolean datatype can store the value True or False.
Where a boolean has not been assigned a value, by default it's value is false.
The format for declaring a boolean variable is:
Type identifier;
Where the Type is boolean and the identifier is exists:
boolean exists;
...and where a value of true has been assigned:
boolean exists = true;
Where a boolean has not been assigned a value, by default it's value is false.
The format for declaring a boolean variable is:
Type identifier;
Where the Type is boolean and the identifier is exists:
boolean exists;
...and where a value of true has been assigned:
boolean exists = true;
You can declare a boolean in one statement and assign it a value in another statement:
boolean exists;
// other statements...
exists = true;
Monday, May 21, 2012
Scanner class - Part 2.
DOWNLOAD THE CODE: Scanner.zip
<< Continued from part 1
In the next example, we will nominate a character to use as a delineation token - the semi-colon (;).
Below is the text file shoppinglist2.txt. Note that each line contains a semi-colon. Now, rather than defaulting to whitespace as the delineation token, the Scanner will look for the semi-colon character.
<< Continued from part 1
In the next example, we will nominate a character to use as a delineation token - the semi-colon (;).
Below is the text file shoppinglist2.txt. Note that each line contains a semi-colon. Now, rather than defaulting to whitespace as the delineation token, the Scanner will look for the semi-colon character.
Here's the code:
Note that the Scanner's property useDelimiter has been set to use the semi-colon (;). Each token is now measured by the presence of a semi-colon.
Here's the result:
Related: Using the split() function >>>
Labels:
delineator,
Demo Code Project,
Loop,
Scanner,
split,
useDelimeter,
While
Unified Modelling Language - UML
"Unified Modeling Language - Wikipedia, the free encyclopedia" ( http://bit.ly/Lk7zXy )
"UML basics: The class diagram" ( http://ibm.co/Jwpxv3 )
"UML basics: The sequence diagram" ( http://ibm.co/Lk8yqN )
"Activity diagram - Wikipedia, the free encyclopedia" ( http://bit.ly/Jwq4Nu )
Eclipse Tip: Correct indentation
Code indentation can become messy and as a result, the code can be difficult to read.
Eclipse has an option to 'Correct Indentation'.
Eclipse has an option to 'Correct Indentation'.
- Right click the code you wish to clean up
- Select Source
- Select Correct Indentation
Subscribe to:
Posts (Atom)












