Wednesday 9 December 2015

Java Code Structure

Code Structure in Java


A source file contains code, written in the Java programming language, that you and other programmers can understand.The Java programming language compiler (javac) takes your source file and translates its text into instructions that the Java virtual machine can understand. The instructions contained within this file are known as bytecodesThe Java application launcher tool (java) uses the Java virtual machine to run your application. But for all this to happen the first step remains of creating a source file. For creating any source code there set of rules and instructions that need to be followed by programmers. 




What goes in a Source File

A source code file with java extension holds one class definition. The class represents a piece of your program, although a very tiny application might need just a single class. The number classes should be used when creating the source code depends upon the complexity of work that needs to be carried out via the Source code. The class must go within a pair of curly braces.


What goes in Class

A class has one or more methods. In the car class, the door method will hold instructions for how the door should open or close. In a class you can have more than one method say another method for tail lights how and when they will operate. Your methods should be declared in a class(in other words, within curly braces of the class). A class might have single or multiple methods for example in this case a our class car can have methods like door(), steering(), backLights() etc.








What goes in method

Within a curly braces of a method, write your instructions for that method should be performed. Method code is basically a set of statements, and for now you can think of a method kind of like a function or procedure. For example the door method will hold the details of door or check the condition of door or instructions for how the door should open or close. Same goes for other methods.