Java Basic Syntax
Java Basic Syntax
4. INSTANCE VARIABLES: Every object is assigned their own unique set of instance
variables.
The attributes of an object are created by the values that are assigned to these
instance variables.
5. COMMENTS: Comments are descriptive texts that do not affect the execution
process of the program at runtime.
Note that there are three types of comments, single line,multiline, and
documentation. (Samples sill be shown below)
6. SOURCE FILE NAME: The source file name should exactly match the class name with
the extension of Java.
Ex. BasicSyntax.java - Valid
basicSyntax.java - Invalid
8. CLASS NAMES: The naming convention for classes in java is the Pascal Case where
each first letter
of a word must be capitalized.
Ex. ThisIsSomeClass, AnotherClass,UpperClass,Class
10. METHOD NAMES: The naming convention for methods is the Camel Case where the
very first is in lowercase, but the
succeeding words must have their first letters in upper case.
Ex. thisIsSomeMethod, anotherMethod, lowerMethod, method
10. IDENTIFIERS: These are names used to identify various elements in a program,
such as variables, methods, classes, interfaces, and labels.
They are essentially the names you give to these program elements to refer to them
within your code.
Ex:int myVariable;
String firstName;
BankAccount account;
calculateInterest();
MAX_VALUE;
11. WHITE SPACES: A blank line (contains only white spaces). This doesn't affect
program execution.
12. KEYWORDS: Keywords, also known as reserved words, are predefined words in the
Java language that have special meanings and functionalities.
These words are reserved and cannot be used as identifiers (e.g., variable names
or class names).
Ex: return,new,public,private,static,int,final,void,if,else,throw,for
*/
public class BasicSyntax {
/**(Documentaion / Doc Comment)
* Sample Class -> This serves as a template for what a car must be made off
and what it can do
*/
static class Car{
// Instance variables representing the state of a car
private String color; // Color of the car
private int speed; // Speed of the car