Primative types are simpler than objects. They dont do anything; they exist simply to represent a value, such as a number.
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.
There are two things you should take notice of in this example:class my_object { public static void main(String arguments[]){ System.out.println("Strings can be joined" + " as easy as that"); } }
Strings can be joinedas easy as thatSo, it's easy to the point of being braindead!
That being said, there are times when a number type, will get automatically converted to a string type for you:
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".class my_object { public static void main(String arguments[]){ System.out.println("You are #" + 1); System.out.println("But " + (1+1) = "s company"); } }
Prev Lesson: Primative types --
Next Lesson: Variables --