Strings are IMMUTABLE
I watched the CBTNugget video on Strings and explored the Javadocs for Strings and StringBuffer.
Strings are immutable objects; they cannot change their value. Characters in a String are represented by 16 bit Unicode. There are 3 ways to instantiate a string.
public class StringDemo1
{
public static void main(String[] args)
{
String myString = new String();
myString = "Hey,I'm a new string";
String myString = String("Hey, I'm a new");
}
Wink Demo Program
I also use a program called Wink to help in my studies of Java. Wink makes it easy to create animated demonstrations and render them as flash (.swf) files. During a wink session, an icon that looks like an eye is placed into the tray. I push the ‘pause’ button to capture a screen shot with the cursor. The eye in the tray looks like it winks each time a screen shot is taken. After I’m finished collecting screen shots, each screen shot becomes a slide. I can rearrange the order of the slides, change the position of the cursor and add text boxes. The entire sequence can then be rendered as a single compressed flash file (.swf) and retrieved on my hard drive or web page for review.
Arrays
Arrays are objects that hold data and store multiple values of the same type. An array is identified by square brackets []. Multiple sets of brackets indicate additional capacity to hold data. An array is contructed with the operator ‘new’.
A one dimensional array would be declared as:
String[] MyList;
MyList = new String[25]; // The size of an array is only declared when it is created.
A two dimensional array is like a table:
String[][] Information;
Information = new String[][];
a three dimensional array is like a rubic cube
String[][][] MySongs
MySongs = new String[100][2][2];
The main method in Java uses an array of String[]
public static void main(String[] args)
Flow Control I
I watched Java Fundamentals cbtNugget videos about Flow Control. I test coded the sample programs as I watched.
- flow control: If then else and switch case statements
- boolean statements
In this example, I see that a boolean statement ‘x>10′ would return ’true’ or ‘false’ performing a test within the println statement. I also tested an if statement by not inserting a curly brace–the next statement is executed if it is true. On a Switch statement, you need to use break statements or it will continue to execute statements or fall through.
public class flow1
{
public static void main(String[] args)
{
int x = 10; if (x>=10)
{
System.out.println("x is greater than 10");
System.out.println(x > 10);
}
else
{
System.out.println("x is not greater than 10");
System.out.println(x > 10);
}
System.out.println("done...");
}
}
Java Fundamentals
I watched cbtNugget’s Java Fundamentals today. I recreated each sample program as I watched. There are two steps to write and execute a Java program. First, save the source code with a class name and ‘.java’ appended to it, e.g. ’Demo1.java’. I saved it in a folder on my hard drive; c:/Java. I started a command prompt and opened the Java directory and compiled the source code by typing “javac Demo1.java”. A file ’Demo1.class’ was generated. To test the program, I typed ‘java Demo1′.
I learned about:
- variable scope
- explicit and implicit cast
- The ranges of data types and how they affect a cast
In this code snippet, I saw how variables declared on a class level differ from variables declared in a method:
public class Demo1
{
// Variables declared at class level become fields
// variables are initialized to default values at class level but not within methods
public static int myAge;
public static int myInt1 = 12;
public static boolean isFunny;public static void main(String[] args)
{
// variables declared in a Method become local variables
int MyInt2;
System.out.println(MyInt2); // This didn't compile saying that the variable needed to be initialized.
}
}
Working with 3-D
I visited a friend who has ambitions of designing a game engine based on Mech Commander 2. He wants to take the game engine written in C and designed to work with DirectX 7 and bring it up to date to DirectX 9. We talked about the basic principles of creating terrain in a 3-D environment. Everything is created in quadrilaterals split in half into triangles.
Using UML
I want to use UML to document my Java source code. I am looking at severak UML editors that I could use to create class diagrams. I am most familiar with using Visio but the interface is difficult to use. I am looking at ArgoUML at the present. I’d like to explore other tools that are available. I would be grateful for any suggestions.
Objective: Learn The Rules
Objective 1.3 states “Develop code that declares, initializes, and uses primitives, arrays, enums and objects as static, instance and local variables. Also use legal identifiers for variable names.”What are identifiers? They are names for declared variables that hold typed values. Naming a variable starts with a letter (Aa-Zz), currency character ($) or an underscore (_). After the first character, identifiers can use any combination of letters, currency characters or numbers. I can name a variable like children with all sorts of strange and off-the-wall names like mOnday$ and Fridayz but I can’t use names like 3-Dgenerator because it starts with a number and has a dash or R#ads because of the #. Identifiers can’t use Java keywords. All keywords are lower case, so I could use an uppercase version of the keyword but that would likely confuse the next developer charged to maintain the code.
What is an enum? According to the Javadocs, it is a common base class of all Java language enumeration types.
What are JavaBeans? naming rules for creating components that can be used in a plug-and-play manner. Source files have declaration rules. There are lots of rules to define boundaries that help keep things ordered and to avoid confusion–learn the rules and stick to them. This is a lot like learning the rules for a game, once you have learned the rules–the game is fun and allows a lot of freedom. I had a hard time with some sports because I didn’t understand the basic rules.
I joined the Sun Developers Network which gives me access to “… a wide variety of services such as newsletters, forums, bug database, and more.”
Chapter 1
I watched the second cbtnugget video today: Java Language Fundamentals. I created some basic fill in the blanks in my notes. I think I know these fundamental rules but I want to make sure I have the fundamentals understood. I have had too many bad experiences with tests that asked questions about topics I thought I knew and understood. I read several more pages from chapter 1.
Today at work was a lesson in patience. I am writing help documentation for an emerging web service called ContractPal. We have made some progress but more often I’ve seen regression. Often times parts of the application will work and then it is taken away–again. I have developed several working prototypes: W-4, a Lease Agreement and an school enrollment form. It started with a meeting that took place several weeks ago. It was announced that some of the classes were too tightly coupled, that the code base was difficult to maintain and had some shortcomings with regard to scalibility. Functionality was scaled back.
Meanwhile, I am working to understand the changes that have been impemented. I download the latest code from Subversion each day and see if my prototypes will work. So far, I am getting closer and closer. The service is morphing and changing so much andI feel badly for not progressing more in my documentation efforts.
A Chapter a week
My goal is to complete a chapter from SCJP every 2 weeks. There are 10 chapters so if everything goes as planned I will be prepared to take the test within 20 weeks. I will take the test in the first week of March 2007.
I will log my progress here, write my notes with RecallPlus, watch 1 CBT nugget video per week.
-
Recent
- API Introduction
- Preparing a Technical Writing Portfolio
- What are Documentation Services worth?
- Move Networks Silverlight Developer Guide
- Writing Usable Documentation
- Learning Java Head First
- Whizlab SCJP 5.0 Preparation
- Writing PHP Script
- Java Language Specification
- Yellow Belt Passed
- Passed Object Oriented Test
- A Java App of My Own
-
Links
-
Archives
- December 2008 (4)
- November 2007 (1)
- January 2007 (2)
- December 2006 (7)
- November 2006 (16)
- October 2006 (17)
-
Categories
-
RSS
Entries RSS
Comments RSS
