INTRODUCTION TO JAVA!
Java is an Object Oriented programming language, which follows OO concepts strictly for the development of its program. In Java, even a simple program like the one that displays the message “Hello, World!” would require a class, an object-oriented element. Every program in Java starts with the word ‘class’.
Without using the basic OO concepts (Class and Object), it is not possible to write a program in Java. The following is a simple “Hello, World!” program in Java:
class Example{
public static void main(String args[]){
System.out.println(“Hello, World!”);
}
}
In this Java program, Example is the name of the program, and is defined as a class. While running this program using Java runtime system, an instance of the class Example is created and is called an Application Object. Hence, a Java program itself is an object, which will use other objects in it.
Method main() in Java:
As in the class Example, every java program will have a public member function named main( ). This function is the starting point of every Java program. As soon as an application is created, the function main( ) will be called by the OS to run the program. This function must be declared as public for start up.
The function main( ) takes one parameter, which is an array of strings. Through this parameter, user input can be passed to main( ) from command-line at the time of starting the application. As the dimension of this array is not specified, any no. of strings (messages) can be passed as input to the application.
In the above example, there is only one statement written in function main() for displaying the message “Hello, World!”:
This is an output statement using two objects: System and out. The first object ‘System’ refers to the computer that runs the program and the second object ‘out’ refers to an output device to which the message has to be sent for display. The object ‘out’ provides an operation (method) called println, using which the output can be displayed on the output device.
System.out.println(“Hello, World!”);
This is an output statement using two objects: System and out. The first object ‘System’ refers to the computer that runs the program and the second object ‘out’ refers to an output device to which the message has to be sent for display. The object ‘out’ provides an operation (method) called println, using which the output can be displayed on the output device.
Data Types in Java:
Java is a strongly typed language. It is more strictly typed than any other OOP language. This fact is justified based on the following three facts:
- Every variable and expression used in Java has a type. And every type is strongly defined.
- All assignments, whether explicit or via parameter passing in method calls are checked for type compatibility.
- There are no automatic coercion or conversions of conflicting types. All expressions and parameters are checked by Java compiler for type compatibility.
Java defines eight simple (or elementary) data types: byte, short, int, long, char, float, double and boolean. These can be put in four groups:
- Integer data types – which include byte, short, int and long
- Floating-point numbers – float and double
- Character and
- Boolean
The simple data types represent single values. We can use them for declaring ordinary variables, constructing arrays, or for defining user-defined data types like class.
The simple types are defined to have an explicit range and mathematical behavior. Because of Java’s portability requirement, all data types have a strictly defined range. For instance, an int always occupies 32 bits, regardless of the particular platform. This allows programs to be written on one platform and then ported to another platform for execution without any modification of its source code.
For further reading follow the links:
For further reading follow the links:
Introduction to Inheritance in Java
Note: You may found some useful information by following the links provided in the sidebar.
To know more about ASP mail me @
davidjlivingston@gmail.com