Basic 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 the name of the class, every internal word’s first letter ought to be in Upper Case. For example, a common class name is as follows:

class Sample class

  • 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. If a 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 following:

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 keep 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

sample.java.

  • public static void main(string args[])

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

Java Keywords

Keywords, or we can say reserved words in Java. As a rule, these words cannot be used as names for variables or constants.

List of Java keywords

  • abstract
  • break
  • boolean
  • case
  • byte
  • char
  • catch
  • const
  • class
  • default
  • continue
  • double
  • do
  • enum
  • else
  • final
  • extends
  • float
  • finally
  • goto
  • for
  • implements
  • if
  • instance of
  • import
  • int
  • long
  • interface
  • new
  • native
  • private
  • package
  • protected
  • return
  • public
  • static
  • short
  • super
  • strictfp
  • synchronized
  • switch
  • throw
  • this
  • transient
  • throws
  • while
  • try
  • volatile
  • void
Comments in Java

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:

/**/

The Java compiler simply ignores all characters that exist in the comments region.

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.

Inheritance:

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 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 current class is referred to as the super class.

Interfaces:

As mentioned previously, Java is all about the interaction between objects. How different objects communicate with each other is defined in what is called an ‘interface.’ Moreover, interfaces are also an essential 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.

Copyright 1999- Ducat Creative, All rights reserved.