Atomic elements of Java

Almost every Codes of any programming languages are collection of whitespace, identifiers, literals, comments, operators, separators and keywords.

Whitespace

Java is a free-form language. It means there is no need to follow any special indentation rules as like in python.
You can write your entire program in a single line but, a developer that's not a good practice.
In java whitespace is a space, tab, or newline.

Identifiers

An identifier is a name name assigned to an element in a program.

Rules for defining Java Identifiers

  • It contains of alphanumeric characters including '$' (dollar sign) and '_' (underscore).
  • It should not start with digits.
  • Java identifiers are case-sensitive.
  • Keywords can't be used as identifiers.
Examples

valid Identifiers
Myvariable, i, j, count, i10, $test, this_is_good

Invalid identifiers
My variables //contains space
4thsem //first character is a digit
a&b // & character is not allowed

Literals

Literals are the constant values assigned to the variable. A literal can be a number, character, or a string.
e.g. x = 20; here x is variable and 20 is literal.

Comments

Comments are developer-readable explanation in the source code of a any program. They are never executed and always ignored at the time of compilation or interpretation.
 //this is single line comment 
/* this is a multiline comment */
/** This is a documentation comment */

Separators

Few characters are used as separators. The most commonly used separator in java is semicolon. It terminates the statements.

separators in java

Java Keywords

They are reserved words and are predefined. These keywords cannot be used as names for a variable, class or method. There are 50 keywords currently defined in the Java language.
java keywords



java is not purely object oriented programming language because it supports primitive data types like byte, int, long, float, double etc., which are not objects.


Comments

YouTube

Popular posts from this blog

GTU OOP Programs - 11

Mini project ideas for Operating System

GTU OS Program - 8