Tuesday, October 7, 2008

LANGUAGE FUNDAMENTALS

Language Fundamentals

This section introduces the fundamental elements of the Java programming language.

When learning a new language, the first step one must take is to learn its syntax rules and keywords. Combining the two, one creates statements, Programming Blocks, Classes, Interfaces, et al.

Use packages to avoid name collisions. To hide as much information as possible use the access modifiers properly.

Create methods that do one and if possible only one thing/task. If possible have separate method that changes the object state.

In an object oriented language, programs are run with objects; however, for ease of use and for historic reasons, Java has primitive types. Primitive Data Types only store values and have no methods. Primitive Types may be thought of as Raw Data and are usually embedded attributes inside objects or used as local variables in methods. Because primitive types are not subclasses of the object superclass, each type has a Wrapper Class which is a subclass of Object, and can thus be stored in a collection or returned as an object.

Java is a strong type checking language. There are two concepts regarding types and objects. One is the object type and the other the template/class the object was created from. When an object is created, the template/class is assigned to that object which can not be changed. Types of an object however can be changed by type casting. Types of an object is associated with the object reference that referencing the object and determines what operation can be performed on the object through that object reference. Assigning the value of one object reference to a different type of object reference is called type casting.

The most often used data structure in any language is a character string. For this reason java defines a special object that is String.

To aggregate same type java objects to an array, java has a special array object for that. Both java objects and primitive types can be aggregated to arrays

No comments: