Application Programming
Application programming also referred as console based programming will be syntactically and semantically similar to ‘C’ (or) ‘C++’ programs. These application programs are executed for the MS-Dos prompt.
Structure of a Java program:
-
- class class_name
- {
- public static void main(String args[])
- {
- …………
- body of the method;
- ….….….
- }
- }
- Class: – A reserved keyword with which we create classes.
- Main: – like in languages such as C and C++, we have the main function where the program execution begins. Similarly in Java the program execution begins at the main method.
- Method: – method is nothing but the functions in C and C++. In Java we call the functions by the name Methods.
- Write a source code and save the code with the name of the class and the extension ” .java”.
- Invoke the command prompt and switch to the folder where you saved source code.
- Compile the source code using the compiler ” javac”.
- Syntax: – javac filename.java
Note: If you get back your Dos-prompt, that itself is a conformation that there are no errors in the source code. - When you compile the source code the result is a byte code file with the extension ” .class”. Execute the byte code file using the Interpreter “java”. This is the Java run time system.
- Syntax: – java filename
The output statements in Java is
- System.out.print();
- System.out.println();
