09-10-2012, 11:12 AM
CORE JAVA CONCEPTS
CORE JAVA CONCEPTS.ppt (Size: 203 KB / Downloads: 399)
JAVA Classes
The class is the fundamental concept in JAVA (and other OOPLs)
A class describes some data object(s), and the operations (or methods) that can be applied to those objects
Every object and method in Java belongs to a class
Classes have data (fields) and code (methods) and classes (member classes or inner classes)
Static methods and fields belong to the class itself
Others belong to instances
Scope of Objects
Java objects don’t have the same lifetimes as primitives.
When you create a Java object using new, it hangs around past the end of the scope.
Here, the scope of name s is delimited by the {}s but the String object hangs around until GC’d
The static keyword
Java methods and variables can be declared static
These exist independent of any object
This means that a Class’s
static methods can be called even if no objects of that class have been created and
static data is “shared” by all instances (i.e., one rvalue per class instead of one per instance
Array Operations
Subscripts always start at 0 as in C
Subscript checking is done automatically
Certain operations are defined on arrays of objects, as for other classes
Constructors
Classes should define one or more methods to create or construct instances of the class
Their name is the same as the class name
note deviation from convention that methods begin with lower case
Constructors are differentiated by the number and types of their arguments
An example of overloading
If you don’t define a constructor, a default one will be created.
Constructors automatically invoke the zero argument constructor of their superclass when they begin (note that this yields a recursive process!)