22.02.04 - Java and C, using Objects
String Class - const char * String Buffer class - const char
Do not create any static methods apart from main Can create other static methods in a class
- Methods can call other static methods
- Can pass parameters
- Like global functions Using static methods, the code is not being executed on a specific object, so not really object oriented
Java Conventions
Use capital first letter for class names Use lower case first letter for variable names and method/function names With multiple words, capitalise the first letter of subsequent words
Data types in Java
'char' in Java is a 2 byte number to allow for extended character sets
Objects
- Use object references to refer to object
- Object references act like C struct pointers
- Need to use new to create the object
- Assigning one reference to another means 'make it refer to the same object'
- Passing an object reference into a function, or returning one, means referring to the same object, NOT creating a new one.
String
- Do not need to create them
- using + operator with
String
objects create a newString
- without new - Passed around like objects
- Use
StringBuffer
object if need to change a strings contents
Auto-boxing and unboxing
Classes to wrap each of the basic data types Can sometimes treat basic types as if they are objects
Java command line args
use .length
to find the length
Array of commands inside args
There is no filename as the first argument
Applying Functions
Expressed as object,function()
Means apply the function on the object and pass the parameters