JAVA Tutorials
What is java?
Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun Microsystems.
First Java Program -HelloWorld.java
HelloWorld class is an application thatmore>>
"Hello World!" to the standard output.
public class HelloWorld {
// Display "Hello World!"
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
Objects in Java - Introduction
What is a Type?
A type is a category or grouping that describes a piece of data. Every data in Java can be identified by its type. Java has two general categories of types: primitives and classes.Classes Describe Objects
Classes are the basic building blocks of Java programs. Classes can be compared to the blueprints of buildings. Instead of specifying the structure of buildings, though, classes describe the structure of "things" in a program.//Contents of SomeClassName.java
[public] [( abstract | final )] class ClassName [extends ParentClass] [implements Interfaces]
{
// variables and methods are declared within the curly braces
}
- A class can have public or default (no modifier) visibility.
- It can be either abstract, final or concrete (no modifier).
- It must have the class keyword, and class must be followed by a legal identifier.
- It may optionally extend one parent class. By default, it will extend java.lang.Object.
- It may optionally implement any number of comma-separated interfaces.
- The class's variables and methods are declared within a set of curly braces '{}'.
- Each .java source file may contain only one public class. A source file may contain any number of default visible classes.
- Finally, the source file name must match the public class name and it must have a .java suffix.
public class Dog extends Animal implements Food
{
//Dog's variables and methods go here
What is an Object?
Objects are the physical instantiations of classes. They are living entities within a program that have independent lifecycles and that are created according to the class that describes them.
more tutorials click here
Attributes
A class describes what attributes an object will have but each object will have its own values for those attributes.Behaviors
Behaviors are represented by methods. An object may call, or invoke, its own methods, or it may call another object's methods that are visible to it.Constructors
In order to be used by a program, an object must first be instantiated from its class definition. A special type of method called a constructor is used to define how objects are created.Messages
Objects cooperate and communicate with other objects in a program by passing messages to one another.Class Inheritance via extends and implements
As you saw in the Horse example, a class can extend one other class and implement many Java interfaces. Extending and implementing is the Java mechanism for representing class inheritance.more tutorials click here