Java Data Types And Values

Java Data Types And Values

Hello, I'm Harmanjot, a network analyst with a specialization in computer networking. I Love to share the knowledge I've gained through my experience with the Java. In This guide, I will be going through Basics of Java such as data types and Values

As we all know, all programming languages have rules, elements and defined character sets. Tokens in Java are basic elements that are the smallest individual element of a program. Different types of tokens supported by Java are as follows

  • Keywords
  • Identifiers
  • Variables
  • Constants
  • Operators
  • Punctuators

Keywords

Words that are set of predefined words with meaning to compiler which cannot ne used as identifiers and are reversed is called Keywords. Some of keywords are:-

  • abstract , for, new, switch, super, while, float ,long, native, class, char ,case, const.
  • do, double, return, public, this, throw, try, void, int, interface.

Identifiers

sequence of characters used to name variables, interfaces, packages, methods, and classes is called an identifier. For example MY_NAME

There are some rules for identifiers such as it cannot contain space, can't begin with a digit. It can't be Boolean.

Variables

A variable is a location in the memory that stores a value. For example, to store the multiplication of two numbers, we need location in memory to store the value

Constants/Literals

A program element whose value remains unchanged during the course of the program is called constant/literals though Java Doesn't support constant it can be achieved by using the assignment operator and keyword 'Final'.

Integer Constant

Integer Constant are constant data elements that have no fractional parts. Java treats it as int type. Some key points are:-

  • it cannot have decimal point,
  • It can be - or +.
  • it can be represented in decimal, octal, or hexadecimal form.

Floating Decimal

floating constant represents decimal values with fractional part and can be expressed in either Notation or Scientific Notation.

Standard Notation consist of whole number followed by decimal point and fractional component. There are some rules followed when writing standard notation.

  • it must have at least one digit before and after the decimal point.
  • comma cannot ne included.
  • it can have either + or- sign before it.

To indicate exponent, scientific notation uses standard notation plus a suffix E or e. The part appearing before E is mantissa and the part appearing after E is Called exponent.

Character Constant

A Character Constant is a character enclosed between quotes ('). The character can be a character from the basic character set. Java treats it as a char type.

Examples 'a','A"

String Constant

A string constant consists of a sequence of zero or more characters from the basic character set enclosed within double quotation(").

Examples "A", "Hello123"

Boolean Constant

Boolean Constant can have only two logical values. True And False. Java Does not convert True And False in 1 and 0 respectively. Boolean constant is always of boolean type.

Null Constant

Java has defined Null as a reserver word. It is basically used to indicate the absence of some value.

Operators

Variables and Constants store information and operators are used to operate on them. Operators perform some sort of computation. In Simple words, an Operator is a symbol that performs certain operations on one or more operands to produce a result.

Java Operators can be classified as

  • Unary Operator that needs only one operand.
  • Binary Operator that takes two operands
  • Ternary Operator that takes three operands.

Punctuators

In Java, punctuators are special symbols that serve various syntactic and semantic functions. They include characters such as {, }, (, ), [, ], ;, ,, ., and :. These symbols help in defining the structure and organization of the code.

Curly braces {}: Used to group statements into blocks, defining classes, methods, and control flow constructs like loops and conditionals.

Parentheses (): Primarily used for method invocation and for grouping expressions to control the order of evaluation.

Square brackets []: Denote array declarations and access.

The semicolon;: Marks the end of statements.

Comma ,: Separates elements in lists, such as parameter lists in method declarations.

Period: Accesses members of classes and objects.

Colon:: Used in enhanced for-loops and ternary conditional operations.

These punctuators collectively enable clear and structured Java programming.


To view or add a comment, sign in

More articles by Harmanjot Panesar

Others also viewed

Explore content categories