Basic Language Constructs of Java

Java » Basic Language Constructs of Java

Language constructs are part of a program that is formed from a combination of one or more tokens which syntactically acceptable and is as per specified rules of programming language.

In JAVA, these are the following language constructs:-

  • Datatypes
  • Keywords
  • Literals
  • Methods
  • Operators
  • Control Statements
  • Arrays
  • Identifiers
  • Comments
  • Class Libraries

JAVA Datatypes

Datatype tells the compiler, what kind of data can be assigned to a variable. A datatype can be defined as a type that a variable can have. It can be of two type:

Primitive data type: A primitive data type refers to a type which is predefined in a language such as int, float and char etc. and have a fixed range that a variable can store.

User-defined data type: On the other hand, User defined data type refers to a type which is defined by the programmer comprising of various built-in data types such as Class, Interface and Arrays.

JAVA Keywords

These are reserved words in JAVA that cannot be used as a variable name or identifier. There are 50 Keywords in JAVA.

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

JAVA Literals

These are constant values assigned to a variable for example numbers, strings and floating values.

Methods

It refers to the behaviour of objects responsible for the changed state of that object. A method is a set of statements which consists a name and invoked by calling it. It performs a specific task and enhances the reusability of code in a program.

Operators

Operators can be defined as anything that operates on one or more operands forming an expression and give some output. There are various types of operators such as Assignment operator, Logical operator,Arithmetic operator, increment/decrement operator and  Relational operator and bitwise operator.

Control Statements

These statements control the flow of the program and a programmer can use them in order to have proper control over a program.

It can be categorized into three types:

Selection Statement:- It is used to control the flow of a program based on some specific condition and helps to make a decision. If a condition is true, then executes a particular block, otherwise execute other blocks. IF ELSE,IF,Switch statement are selection statement.

Iteration Statement:- It also controls the flow of a program by executing a set of statement repeatedly for a certain number of times Symentenusly based on a specific condition. It can be of two types:-

Exit control loop:- When a given loop block executes first, then after the condition is checked, known as Exit control loop. DO While is exit control loop.

 Entry control loop::- Opposite to Exit control loop, When a test condition is tested first, after that the loop block is exccuted. WHILE and FOR are entry control loop

Control transfer statement:- A statement that forcefully changes the flow of the program. Return, break, continue , Try-catch and more.

Arrays

It is a user defined data type in which elements are stored in a contiguous manner having same data type. Each and every element can be directly accessed by index number.

Identifiers

An identifier is a name given to a variable ,method, classes and interfaces. The naming is done by considering certain rules. A reserved keyword cannot be used as an identifiers.

Comments

A comment is a statement which is not considered by a compiler during compilation of the given program. It is very helpful for programmers as it enhances the readibilty of the program. It can be of two types: Singleline comments that limits to a single line whereas multilin comments which limits to two or more lines.

Class Libraries

These are automatically loaded in the program at runtime.


You must be logged in to take the quiz.

error: Content is protected !!