Core Java Tutorial

Define Java

C vs C++ vs Java

Java Virtual Machine

Java First Program

Java Data Types

Java Tokens

Java Keywords

Java Operators

Operator Precedence

Java Type Casting

Java Statement

Java If statement

Java Switch statement

Java Loops

Java Jumping Statement

Java Arrays 1D

Java Arrays 2D

Java Variable Size Array

Java Vector

Java Math Methods

Java String Methods

Java String Buffer

User-Defined Method

Java Method Overloading

Java Class & Object

Java Constructor

Java Inheritance

Java Interface

Java Packages

Java Multi-threading

Exceptional Handling

File Handling

Java Applets

Java DataBase Connectivity

Page Stats

Visitor: 303

Java Tokens

Smallest individual units in a program are known as tokens. In simple terms, a Java program is a collection of tokens, comments and white spaces. Java language includes 5 types of tokens. They are:

  1. Identifiers
  2. Constants/Literals
  3. Special Symbols
  4. Keywords
  5. Operators

Identifiers

Identifiers are the name, designed by the programmer. Identifiers are used for naming classes, methods, variables, objects, labels, packages and interfaces in a program. Java identifiers follow the following rules:

  1. Identifiers can have alphabets, digits, underscore and dollar sign characters.
  2. Identifiers must not begin with a digit.
  3. Uppercase and lowercase letters are distinct.
  4. Identifiers can be of any length.

Identifier must be meaningful, short enough to be quickly and easily typed and long enough to be descriptive and easily read.

Example of valid identifiers: sum, sum2, average, totalMarks, PRINCIPAL_AMOUNT, $result, sum_of_array.

Example of invalid identifiers: total Marks, 2sum, sum-2, sum&array

Constants/Literals

Constants are like normal variables, only difference is that their values can not be modified in the program once they are defined. Constants refer to the fixed value. They are also known as literals. Constants may belong to any of the data type: Integer, Floating point, Character, String, Boolean

final data_type variable_name;

Special Symbols

The following special symbols are used in Java having some special meaning and thus, cannot be used for some other purpose.

  • Brackets[] Opening and closing brackets are used as array element. It is use for 1D and 2D array.
  • Parentheses() These special symbols are used to indicate function calls and function parameters.
  • Braces{} These opening and ending curly braces marks the start and end of a block of code containing more than one executable statement.
  • comma (, ) It is used to separate more than one statements for eg: separating parameters in function calls, declaring multiple variables.
  • semicolon It is used for ending statement, it is also known as statement terminator.

Java Escape Sequences

Escape Sequence Description
\' Single Quotation Mark
\" Double Quotation Mark
\\ Back slash
\t Tab
\b Back space
\r Carriage Return
\n New line
.
Updated: 30-Dec-19