Java program structure.


A Java program is usually composed of multiple lines. Each line is composed of one or a combination of the below three input elements:

  2. Whitespace characters
  3. Tokens

comment is a sequence of non-executable characters. There are three types of comments in Java which we will learn later.

In Java, the whitespace characters are:

  1. Space ’ ’ – (ASCII SP) produced by pressing spacebar
  2. Tab ’\t’ – (ASCII HT) produced by pressing the tab key
  3. Form Feed character ’\f’ – (ASCII FF) usually used as the page separator char between lines/paragraphs
  4. Line Terminator chars (used to separate two lines) – produced by pressing Enter key:
    1. Line Feed - ’\n’ (ASCII LF also called NL - New Line) - used in all Unix and Mac OS X systems
    2. Carriage Return - ’\r’ (ASCII CR) – used in MAC OS 9 and below
    3. Carriage Return followed by Line Feed- ’\r\n’ (ASCII CRLF) – used in Windows systems

All other input elements other than comments and whitespace are called as tokens. The tokens are further classified as:

  1. Identifiers – Names used to refer or identify are called Identifiers. For example, names of variables, methods and classes are all called Identifiers.
  2. Keywords – one of the 50 reserved words in Java language like publicnewforif etc are called Keywords. These have a special meaning when used as part of the program.
  3. Literals – these are the fixed values assigned in a source code. They can be of primitive, String or a null type.
  4. Operators – in Java language we have 38 different operators like - = > < == >= etc..(which we will learn later)
  5. Separators – in Java language we have 12 Separators - ( ) { } [] ; , . ... @ ::

Select all the correct statements for the below code:

public class Test {
public int sum(int num1, int num2) {
return num1 + num2;

Q. No. 10797 :-

  • The token Test which is the name of the class is called an Identifier.
  • The token sum which is the name of the method is called an Identifier.
  • The tokens num1and num2 are called Keywords
  • The open brace { and the close brace } used to open and close the class and method blocks respectively are called Operators.

Post a Comment