0% found this document useful (0 votes)
13 views8 pages

Java Data Types and Character Sets Explained

The document provides an overview of Java programming language, covering character sets, tokens, data types, and operators. It explains the significance of keywords, identifiers, literals, and various operator types, including arithmetic, relational, and logical operators. Additionally, it discusses variable declaration, comments, operator precedence, expressions, and type conversion in Java.

Uploaded by

Amrit Tandan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Java Data Types and Character Sets Explained

The document provides an overview of Java programming language, covering character sets, tokens, data types, and operators. It explains the significance of keywords, identifiers, literals, and various operator types, including arithmetic, relational, and logical operators. Additionally, it discusses variable declaration, comments, operator precedence, expressions, and type conversion in Java.

Uploaded by

Amrit Tandan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

VALUES AND DATA TYPES

Java is a versatile, high-level programming language that was


developed by Sun Microsystems (now part of Oracle) and released in
1995. It's designed to be platform-independent, meaning that Java
code can run on any device that has a Java Virtual Machine (JVM).
CHARACTER SET
A character set is a defined list of characters recognized by a
language. it is compressed of
Alphabets: Letters (A – Z) and (a – z)
numerals: Digits(0-9)
special characters: ? , .
The alphabets and numerals are known as the alphanumeric
character set. 2 standard character set are ASCII and UNICODE
ASCII
ASCII stands for American Standard code for information Interchange
it is a 7 bit set of code that defines 128 different characters. The ascii
character set is enough to represent every upper case letter and
lower case letter, digit and special characters used in English
language keyboard.
Unicode
Unicode is a universal character encoding standard that assigns a
unique number (code point) to every character in almost all
languages and symbols.
TOKEN
All characters in a Java program are grouped into symbols called
tokens. tokens are the smallest individual unit in a program. There
are five categories of tokens in Java they are
1. Keywords
2. Identifiers
3. Literals
4. Punctuators
5. Operators
Keywords
Keywords also known as reserved words are the words that have
special meaning to the Java compiler. Some of the java keywords
are
abstract const float private void
Boolean continue if protected while
Break default import public
bit do int return
case double long short
char else new static
class final package switch
Identifier
Identifiers are fundamental building blocks of a program and are used to
name different components of a program such as variables methods and
objects
Java identifiers naming conventions
1. All identifier can consist of any combination of letters digits _and $
sign
2. It cannot start with a digit
3. It may be of any length
4. An identifier cannot be used as a keyword or a Boolean literal or a
null literal
5. White spaces are not allowed
6. Java is case sensitive which means upper case and lower case are
different.
Literals
Literals are a sequence of characters that represent a value in a program
and stored in a variable. The literals are made up of digit letters and
other characters.
Literals are of four types numeric, nonnumeric, Boolean, Null.
Punctuators
Punctuators(separators) are symbols used for grouping and separating
the code.
Punctuator Name Uses
{ } Curly Curly brackets are used to define a block of
brackets code in Java program. They are also used to
initialize the values of arrays
[ ] Square Square brackets are used to declare arrays
bracket and refers the values at a particular index
( ) Parenthesis Parenthesis or round brackets are used to
define methods they are also used to define
the precedence of operators in an expression
and conditions in control structures
; Semi colon The most commonly used separator in Java is;
it is used to separate statements
, Comma It is used to separate consecutive identifiers in
a variable declaration
. Dot(period) The dot operator in Java is used to access
member variables and member methods. it is
also used to differentiate the package name
from sub packages and class names.

Operators
Operators are symbols which are used to perform calculations in a given
expression.
The forms of operators are unary, binary and ternary
Unary operator
An operator that has just one operand is known as unary operator
Binary operator
An operator that has two operand is known as a binary operator.
Ternary operator
An operator that has three operand is known as ternary operator

Types of operators
Arithmetic operators
operator Name
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
(Remainder)

Relational operators
operator Name
< Less than
<= Less than or
equal
> Greater than
>= Greater than
or equal
== Equal
!= Not equal

Logical operators
Logical operators operate only on Boolean operands and are used to
construct complex decision making expressions. the following are some of
the logical operator.
operator Name
&& AND
|| OR
! NOT

Truth table for AND


INPUT OUTPUT
A B A && B
True True True
True False False
False True False
False False False
Truth table for OR
INPUT OUTPUT
A B A || B
True True True
True False True
False True True
False False False

Truth table for AND


INPUT OUTPUT
A !A
True False
False True

Conditional operator (? : )
The conditional operator is also called as ternary operator because it has
three operand.
Syntax
Expression ? statement1 : statement2;
Assignment operator
A assignment operator is used to assign the value of an expression to a
variable.
Eg : x = 5;
New operator
The new operator is used to allocate memory for objects.
Dot operator
Objects have been declared and the memory has been allocated member
variables and member brothers can be accessed using the dot(.) operator
DATA TYPES
Java has a variety of data types that allows programmers to choose the
data types suitable to needs of the application. These data types can be
broadly divided into two categories.
1. Primitive data types
2. Non Primitive data types
Primitive data types
The fundamental data types that are integral part of the Java
programming language are called primitive data types. They are also
called intrinsic, built in, predefined.
They are byte, boolean, short, char, int, float, long, double.
Non Primitive data types
The data types that are derived from the premier data types are called
non primitive data types. They are also called reference types derived
types composite types. They are class, array and interface
VARIABLES
A variable is an identifier that denotes a location in a computer memory
to store a data value.
Syntax for variable declaration
Data type variable name;
Eg : int x;
COMMENTS
Comments are usually added in a program to give an overview of the
code and provide additional information that is not readily available in it.
The primary purpose of comments is to document the code so that even a
layperson can understand the purpose of the written code. Comments are
ignored by the Java compiler and do not affect the execution of the
program. Comments are of three
1. Single line comment ( //)
2. Multi line comment ( /*-------- */)
3. Documentary comment (/**-----------*/)
PRECEDENCE
Precedence is the priority of an operator according to which it is
evaluated. This precedence is used to determine the order of evaluation
of an expression involving more than one operator. There are different
levels of precedence from high to low.
ASSOCIATIVITY
If two operators have the same precedence (priority), then they are
either evaluated from left to right or from right to left this is termed as
associativity.
EXPRESSION
An expression is a combination of constants, variables, operators and
method calls. Java expression can be categorized into various types.
They are arithmetic expression, string expression and boolean
expression.
Arithmetic expression
An arithmetic expression represents a numeric value it can be further
categorized into three subtypes namely integer, real and mixed
expressions.
Integer Expression
An expression containing integer constants and variables joined by
arithmetic operators is known as integer expression.
Real Expression
An expression containing real constants and variable joined by arithmetic
operators is known as real expression
Mixed Expression
An expression which it contains a combination of integer and real
expression is known as mixed expression.
String Expression
A string expression represents a string value. You cannot add and
subtract strings, like numbers, but Java does provide a + operator for
concatenation of strings.
Boolean Expression (Logical Expression)
A Boolean expression represent a Boolean value true or false.
TYPE CONVERSION
A type conversion is a process that converts a value of one data type to
another data type. There are two forms of type conversion in Java -
implicit type conversion and explicit type conversion.
Implicit Type Conversion
The type conversion which are automatically performed by the Java
compiler are known as implicit type conversion. They are also known as
automatic type conversion, type promotion, widening conversion or
coercion.
Explicit Type Conversion
A programmer has to force the conversion as is referred to as explicit
type conversion or type casting.
Syntax:
( data type) expression
The keyword final makes the variable constant that is whose value cannot
be changed.

*******************

You might also like