Sunday, March 18, 2012

The char data type

The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff'


"Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)" ( http://bit.ly/xesQuj )



The Java Tutorials

Great site to get you started

"Lesson: Language Basics (The Java™ Tutorials > Learning the Java Language)" ( http://bit.ly/FP6evY )

What is a String?

DOWNLOAD THE CODE: IntroToStringPkg.zip

A string is a collection of any keyboard characters such as "I love chocolate 100 times more than you !!!"

Where a String has not been assigned a value, by default it's value is null.

In the example below, 2 Strings are created (lines 1 and 2). 

The 3rd statement concatenates (joins) the 2 Strings together (using the addition character). 

The fourth statement returns the number of characters in the String called firstName, by calling the String length() function (all Strings have this function, it returns an int). 

The fifth line finds the first character of the String by calling the String charAt() function (all Strings have this function, returns the character at the specified position). 

The final statement concatenates all of the values together and prints to screen.



The output:


A variable, such as String, can be declared in one statement and assigned a value in another statement, as below:

String myString;
myString = "This is a String!"; 

...or it can be declared and assigned a value in a single statement:

String myString = "This is a String!";







Literal String values (the actual charcters) are always enclosed in double quotation marks. 


See also: "Strings (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)" ( http://bit.ly/K4kbDz )

"String (computer science) - Wikipedia, the free encyclopedia" ( http://bit.ly/AgRVuH )

Here's a cat:



System.out.print(String)

DOWNLOAD THE CODE: PrintToConsolePkg

We can use a System.out.print(String) to display a prompt
such as "Input a number : "

If we want to make sure that the line is terminated we can use:

Screen shot:
and the output:


The Main method

A Java project many contain many packages and each package may contain many classes. There must be at least one class containing a main method.

The main method is a static method, belonging to the class, where program execution begins - it's the front door, so to speak. The main method begins the chain of events that load the program into memory, ready for use.

In the Java programming language, every application must contain a main method whose signature is:

public static void main(String[] args)


The main method can optionally take a String array as a parameter, as shown in the parenthesis.

(String[] args)


Java API specification

"Overview (Java Platform SE 7 )" ( http://bit.ly/xIonzZ )

Eclipse and Java for Total Beginners



From http://eclipsetutorial.sourceforge.net/totalbeginner.html

Companion document http://eclipsetutorial.sourceforge.net/Total_Beginner_Companion_Document.pdf