A SIMPLE JAVA PROGRAM Class Declaration The Main Line INDEX The Line Contains Three Keywords The Output Line COMMENTS Single Line Comment Multiline Comment Documentation Comment TYPE CASTING Implicit Type Casting Explicit Type Casting
A SIMPLE JAVA PROGRAM class SampleOne { public static void main(string args[ ]) { System.out.println( WELCOME ); } }
CLASS DECLARATION Class SampleOne Class is a keyword and declare a new class is being defined. SampleOne is a java identifier that is name of class.
MAIN LINE THE public static void main (String args[ ]) Java program must contain the main method. It is the starting point for interpreter to being execution of program. THE LINE CONTAIN THREE KEYWORDS public:- The keyword public is access specifier therefore it is access to all other classes.
Static:- void :- The keyword static allows main to be called without having to instantiate a particular instance of class. Since main() method is called by java interpreter before any object are made. The type modifier void state that main() method does not return any type of value.
String args[ ]:- String args declares a parameter named args, which is an array of instance of class string. args receives any command line argument present when the program is executed.
The output line statement System.out.println( WELCOME ); The println method is a member of out object. Which is static data member of system class. The output of the program is WELCOME
COMMENTS IN A PROGRAM Single Line Comment ( // ) Multiline Comment (/* and */) Documentation Comment(/**and */)
SINGLE LINE COMMENT ( // ):- For a single line comment we use double slash(//) to begine comments. It end at end of line. E.g:- //program for stack operation. MULTI LINE COMMENTS ( /*AND*/ ):- For more than one line of information we use this comments. Multiline are start with /*and end with */. E.g:- /*program for stack is designed by Vijay Bhaskar*/.
DOCUMENTATION COMMENT ( /**&*/ ) For the documentation we use documentation comments. Documentation comment start with /** and end with */. Eg:- /** test of jdk Author S.P.Prabhu Version 1.0*/
TYPE CONVERSION AND CASTING Java permits mixing of constants and variables of different types, but during execution it follows type conversions. In java type casting can done using two ways. They are: 1. Implicit Type Casting 2. Explicit Type Casting
IMPLICIT TYPE CASTING:- In an expression, if the operand are of different types the lower type is automatically converted to the higher type before the operation proceeded by the java interpreter. The result is of higher type. Such type of casting is called implicit casting. In this type of casting there is no loss of data. The following are some implicit type of casting with no loss of data. From To byte short, char, int, long, float, double short char, int,long, float, double char int, long, float, double int long, float, double long float, double float double
EXPLICIT TYPE CASTING:- If we want to force to convert the operand of an expression from one type to another type depending upon user choice, such type of casting is called Explicit type casting. In explicit type casting there is a chance of data loss when we convert the operand from higher type to lower type. The process of converting value is known as casting value. E.g:-int x=(int)7.5