Primative types

The previous lesson introduced the general concept of objects. This lesson introduces the idea of primative types.

Primative types are simpler than objects. They dont do anything; they exist simply to represent a value, such as a number.

The two types

There are two basic types of data in almost all languages: Strings, and numbers.
Strings are nothing more than a few letters strung together.
The most common numbers are basic counting numbers. It's important to know that "floating point" numbers (numbers with decimal points in them) have a special type, but it isn't neccessary to get into detail on that right now.

Technically, Strings can be thought of as being composed of individual characters, which do have their own type. However, it is very rare to use "char(acter)" types directly.

Stringing you along

It is possible to do various tweaks and manipulations to Strings. The simplest thing to do is to add them together. Java allows you to use the familiar "+" sign to do this. Here's an example:
class my_object {
	public static void main(String arguments[]){
		System.out.println("Strings can be joined" + " as easy as that");
	}
}
There are two things you should take notice of in this example:
  1. Strings should always be surrounded by "double-quotes"
  2. There is a leading space at the beginning of the second String.
The "+" sign joins together whatever two Strings you give it, with no alterations. If you don't put in a space yourself, you will get the unsightly result of
   Strings can be joinedas easy as that
So, it's easy to the point of being braindead!

Numbers

Numbers and Strings are technically different types. As such, there are things you can do to a string, that you cannot do with a number, and vice versa.

That being said, there are times when a number type, will get automatically converted to a string type for you:

class my_object {
	public static void main(String arguments[]){
		System.out.println("You are #" + 1);
		System.out.println("But " + (1+1) = "s company");
	}
}
Note the use of parenthesis in the example above. That forces java to look at the numbers first, as numbers. It then treats the plus sign, as simple addition. If you take it away, however, then it looks at the first plus sign from the context of strings, and will convert the numbers to strings. As such, it will then print out "11", rather than "2".

Prev Lesson: Primative types --
Next Lesson: Variables --