| SAP NetWeaver |
| Home |
| Europe Universities |
| Simple Forum |
| Blog |
| Links |
| Contact Us |
| Search |
| Java Tutorial |
| Web Services |
| Share Point |
| Students Coming to USA |
| Live Cricket |
| TomTom Go 720 Review |
| Simple search |
Archive
| Java Tutorial |
|
|
|
What Are Objects Java is an object-oriented programming language. But what are objects? An object is a self-contained entity which has its own private collection of properties (ie. data) and methods (ie. operations) that encapsulate functionality into a reusable and dynamically loaded structure. After a class definition has been created as a prototype, it can be used as a template for creating new classes that add functionality. Objects are programing units of a particular class. Dynamic loading implies that applications can request new objects of a particular class to be supplied on an 'as needed' basis. Objects provide the extremely useful benefit of reusable code that minimizes development time. The Basic Structure of a Java ApplicationA Java application resembles programs in most compiled languages. Code in object format resides on the user's machine and is executed by a run-time interpreter that normally has to be user installedPreviously you wrote a simple 'hello world!' application to test the development environment. Now comes the explanation of the basic structure of Java applications using it as an example. Applications are stand alone and are invoked (or executed) by using a Java interpreter. /** * The HelloWorldApp class implements an application * that displays "Hello World!" to the standard output. */ public class HelloWorldApp { public static void main(String args[]) { // Display Hello World! now System.out.println("Hello World!"); } } The first four lines is a comment on the application's function. Comments are not required but are extremely useful as documentation within the source. Other notes and doc files may get lost but these stay right where they are most useful. A long comment starts with a /* or /** and ends with a */ Short one line comments begin with // and end with the <return>.The fifth line starts with the reserved word public. This indicates that objects outside the object can invoke (or use) it. The reserved word class indicates that we are building a new object with the name that follows. HelloWorldApp is the object name (your choice) and is case sensitive. Java 'style' is to capitalize the first letter of each word only. The line concludes with an opening curly bracket that marks the start of the object definition.Line six is an invocation of an initialization method (or procedure in older languages). static indicates that it calls the class and not an 'instance' of the class. The concept of 'instance' will be discussed later in the tutorials. The method's name is main and the reserved word void indicates that no result is returned back. Main has arguments (aka parameters) in round brackets. String args[] indicates that any command line values given are being passed to main as an array of String type in the variable args. The line finishes with an opening bracket for the main() method.Line eight invokes the println() method of the system.out object. What is to be printed is passed in the argument as a string parameter. Note that each Java statement concludes with a semicolon. Finally closing curly brackets are used for the main and for the object definition |


