An application usually has a Controller Object or a Main Object which is the starting point of a program.
Every object is an instance of a blueprint or Class. Java Technology API (Application Programming Interface) provide classes which we can instantiate to be used as objects in programs. We may also create our own Class which can be easily instantiate.
Structuring Classes:
A Java Class File consists of 4 sections:
- Class Declaration
- Attribute Variable Declarations and Initialization(Optional)
- Comments (Optional)
- Methods (Optional)
[modifier] class class_identifier {
class_body_code
}
where
modifier determines the accessibility of other classes which can be public, abstract and final.
class keyword identifies the block of codes as Class Declaration
class_identifier is the name given to the Class
{ marks the start of the class_body_code
class_body_code is the statements within the Class
} marks the end of the class_body_code
Variable Declarations and Assignments Syntax:
[modifiers] type name;
where
[modifiers] determines the accessibility of the attributes which can be public and private.
type denotes the kind of values that the variable can hold, such as Integer or String.
name identifies the variable name.
Comments Syntax:
Single-line comments - //
Tradtional comments - /* */
/** */ comments can be used to create documentation using Javadoc software.
Methods Syntax:
[modifiers] return_type method_identifier ([arguments]) { method_code_block}
where
[modifiers] determines the accessibility of the methods and it is Optional as it appears in square brackets.
return_type identifies the type of value that the method returns. If the method returns nothing, then the void keyword will be used.
method_identifier is the method name
([arguments]) represents a list of variables whose values will be passed to the method.
method_code_block identifies the method statements.
0 comments:
Post a Comment