
The figure besides shows the structure of a Java class.
The four important terms that makes up the java file are :
1. Source File
2. Class File
3. Method
4. Statement
What is a Source file?
A Java source file contains any number of classes. But the rule is, declare only one class as public and save the source file with name as that of public class. If not done so, you may get compile time error(Ugh! now what is compile-time error). Dont worry! it will be explained!.
If public class is not defined, file can be stored using any name of your choice!
Class File!
Java is considered as relatively safe and secure because of its ability to convert a java program into a file coded in a stream of 8 bits. This file is generated by Java compiler and executed by The JVM. The class file is a byte code of a java program . Byte code of a java program is portable and readable only to JVM. This file is platform independent. Class file is just a set of statements, which are the actual logic of the program. Class file is a set of instruction to the processor. How and whereabouts are taken care by the JVM. It does the rest!
Methods!
Method is group/set of statements that makes up the logic of a java program. It is a function or procedure which contains the main logic for which the program is designed. A class may contain one or many methods as per the requirements and only the required method is called at the time of execution. Consider a calculator performs 4 tasks, addition, subtraction, multiplication and division. Imagine the calculator as a class having 4 methods say, add(), subtract(), multiply() and divide(). If the user wants to multiply two numbers, he has to call only multiply() method which has the logic to multiply numbers and not all the methods.This saves storage space and time of execution.
Statements...
Statements! These are the building blocks of the programs. Without them, the program is just a useless piece of code. Statements are the Logic suppliers of any java program. Depending upon the requirements of the client, different kinds of statements are written to provide the specified feature of a software.
After understanding the structure of a Java Program, We will focus onto the syntax of the java class.
Comments
Post a Comment