Java-Basic Syntax

Java Syntax,

About Java programs, it is paramount to remember the accompanying points.

Class Names – For all class names, the first letter ought to be in Upper Case. On the off chance that few words are utilized to structure a name of the class, every internal word’s first letter ought to be in Upper Case. For example, a standard class name is as follows: class Sampleclass Case

Sensitivity – Java is case sensitive, which implies that the identifier Hi and hi would have distinctive importance in Java.

Method Names – All system names ought to begin with a Lower Case letter. In the event that few words are utilized to structure the name of the method, then every internal word’s first letter ought to be in Upper Case. An example of this convention is follows:

public void mysamplemethod ()

Filename – The name of the system record ought to precisely match the class name. At the point when you are saving the file, you ought to save it utilizing the class name. Remember Java is case touchy and affix “.java” to the end of the name. If the document name and the class name don’t match your system won’t assemble. Consider the example of a class name Sample. In this case, you must name the file as

public static void main(string args[])

Java system handling begins from the main() function, which is a required piece of each Java program

Java Identifiers

Next java syntax is identifiers. All Java components require names. Names utilized for classes, variables and strategies are called identifiers. In Java, there are a few focuses to recall about identifiers. They are as per the following standard:

  • All identifiers ought to start with a letter (beginning to end or a to z), underscore (_) or special character ($).
  • After the first character, identifiers can have any mix of characters.
  • You cannot use a keyword as an identifier.
  • Most significantly, identifiers are case sensitive. So, Sample is not same as sample.
  • Examples of identifiers include $salary, age, __1_value and _value.
  • Examples of illicit identifiers include –compensation and 123abc.
Java Modifiers

Like is the case with any programming language, it is conceivable to alter classes and systems by utilizing modifiers. There are two classifications of modifiers:

  • Access Modifiers: public, default, protected and private
  • Non-access Modifiers: strictfp, final and abstract

We will be researching more insights about modifiers in the following chapters.

Java Variables

Several types of variables are supported by Java. These types of variables include:

  • Instance Variables (Non-static variables)
  • Class Variables (Static Variables)
  • Local Variables
Java Arrays

Arrays are contiguous memory locations that store different variables of the same sort. On the other hand, an array itself is an article on the memory. We will research how to proclaim, develop and instate these in the chapters to follow.

Java Enums

Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums.

For example, if we consider an application for a fresh juice shop, it would be possible to restrict the glass size to small, medium, and large. This would make sure that it would not allow anyone to order any size other than small, medium, or large.

class FreshJuice { 
   enum FreshJuiceSize{ SMALL, MEDIUM, LARGE } 
   FreshJuiceSize size; 
public class FreshJuiceTest { 
   public static void main(String args[]){ 
      FreshJuice juice = new FreshJuice(); 
      juice.size = FreshJuice.FreshJuiceSize.MEDIUM ; 
      System.out.println("Size: " + juice.size); 

out put – MEDIUM

Java Keywords

Very important java syntax are keywords.

Java Keywords list
Comments in Java

Our next java syntax is comments. Just as in the case of C++ and C, Java supports two types of comments namely, single line comments and multi-line comments. The syntax for these types of comments are as follows:

Single line comment:


Multiple line comment:


All characters that exist in the comments region are simply ignored by the Java compiler.

Using Blank Lines:

Any line that is only composed of whitespace characters or comments is considered a blank line. These lines are just ignored by the compiler and are not included in the executable.


Java supports inheritance. In other words, it is possible to derive one class from another class in this programming language. For instance, if you need to create a new class, which is an extension of an existing class, then you can simply derive this new class from an existing class. This allows the new class to access the elements already implemented in the existing class. In this case, the new class is called the derived class and the existing class is referred to as the super class.


As mentioned previously, Java is all about interaction between objects. The manner in which different objects communicate with each other is defined in what is called an ‘interface.’ Moreover, interfaces are also an important aspect of the inheritance feature of java. As part of an interface, the methods that can be used by a derived or sub-class are declared. However, all the methods declared as usable for the subclass must be implemented in the subclass.

Start your first program click here

Download JAVA

Leave a Reply

Your email address will not be published.

Back To Top