What differs Java from C
|
|
|
|
| Articles Reviews Java | |
| Written by Bogdan V | |
| Wednesday, 21 February 2007 | |
|
{mos_sb_discuss:34}
This article also points out similarities and differences between Java and C++. C++ programmers should beware, though: While Java borrows a lot of terminology and even syntax from C++, the analogies between Java and C++ are not nearly as strong as those between Java and C. One of the main areas in which Java differs from C, of course, is that Java is an object-oriented language and has mechanisms to define classes and create objects that are instances of those classes. The Program Structure and Environment A program in Java consists of one or more class definitions, each of which has been compiled into its own .class file of Java Virtual Machine object code. One of these classes must define a method main(), which is where the program starts running. Method is an object-oriented term for a procedure or function. To invoke a Java program, you run the Java interpreter, java, and specify the name of the class that contains the main() method. You should omit the .class extension when doing this. Command-Line Arguments The single argument to main() is an array of strings, conventionally named args or argv. The length of this array (which would be passed as the argc argument in C) is available as argv.length, as is the case with any Java array. The elements of the array are the arguments, if any, that appeared on the interpreter command line after the class name. An Echo Program in Java Note that main() must be declared to return void. Thus you cannot return a value from your Java program with a return statement in main(). If you need to return a value, call System.exit() with the desired integer value. Environment Powered by jReviews |
|
| Last Updated ( Saturday, 07 July 2007 ) | |
| < Prev | Next > |
|---|







