Language Constructs of Java – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Thu, 14 Jul 2022 06:37:52 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg Language Constructs of Java – Programmerbay https://programmerbay.com 32 32 Basic Language Constructs of Java https://programmerbay.com/basic-language-constructs-of-java/ https://programmerbay.com/basic-language-constructs-of-java/#respond Sat, 01 Feb 2020 16:43:55 +0000 https://programmerbay.com/?p=5090 Language constructs are part of a program that is formed from a combination of one or more tokens which syntactically acceptable and are 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 types:

Primitive data type: A primitive data type refers to a type that is predefined in a language such as an int, float and char, etc. and has 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 switch
assert default goto package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
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 behavior of objects responsible for the changed state of that object. A method is a set of statements which consists of a name and is 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 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 execute a particular block, otherwise execute other blocks. IF-ELSE, IF, Switch statement is selection statements.

Iteration Statement:- It also controls the flow of a program by executing a set of statements 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 an 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 executed. 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 the same data type. Each 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 identifier.

Comments

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

Class Libraries

These are automatically loaded in the program at runtime.

]]>
https://programmerbay.com/basic-language-constructs-of-java/feed/ 0