0% found this document useful (0 votes)
160 views7 pages

Java Keywords, Comments, Variables, Identifiers, Data Types and Literals

This document provides an overview of basic Java language elements including keywords, comments, variables, identifiers, data types, and literals. It discusses the different types of comments in Java, how variables are used to store changing data during program execution and how they require a name and type. It also outlines Java's main primitive data types including integer, floating-point, character, and boolean, and describes how literals directly represent fixed values in code without computation.

Uploaded by

Diana Hartan
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)
160 views7 pages

Java Keywords, Comments, Variables, Identifiers, Data Types and Literals

This document provides an overview of basic Java language elements including keywords, comments, variables, identifiers, data types, and literals. It discusses the different types of comments in Java, how variables are used to store changing data during program execution and how they require a name and type. It also outlines Java's main primitive data types including integer, floating-point, character, and boolean, and describes how literals directly represent fixed values in code without computation.

Uploaded by

Diana Hartan
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
You are on page 1/ 7

Core Java Tutorial: Java keywords, comments,

variables, identifiers, data types and literals

Dr. Soumadip Ghosh


Associate Professor, Academy of Technology
Basic Language Elements
o Keywords
o Comments
o Variables
o Identifiers
o Data Types
o Literals
o Operators

Keywords

2
Comments

Java supports three comment styles:

•Block style  comments begin with /* and terminate


with */ that spans multiple lines.

•Line style  comments begin with // and terminate at


the end of the line.

•Documentation style comments begin with /** and


terminate with */ that spans multiple lines. They are
generally created using the automatic
documentation generation tool, such as javadoc.

3
Variables & Identifiers
Variables are used for data that change during program execution. All
variables have a name, a type, and a scope.
The programmer assigns the names to variables, known as identifiers.
Variables have a data type that indicates the kind of value they can store.

When we declare a variable we assign it an identifier & a data type.


E. g., String message = “hello world”;

4
Data Types
Java has four main primitive data types built into the language. We can also
create our own data types called reference types.
Integer: byte, short, int, and long.
Floating-Point: float and double.
Character: char.
Boolean: true or false.
The following chart summarizes the default values for the Java built in data types.
Data Type Default Value (for fields) Range
byte
0 -127 to +128

short
0 -32768 to +32767

int
0 -2,147,483,648 to 2,147,483,647

-9,223,372,036,854,775,808 to
long 0L
9,223,372,036,854,775,807
According to single-precision 32-bit IEEE
float 0.0f
754 floating point format
According to double-precision 64-bit IEEE
double 0.0d
754 floating point format
char
‘\u0000′ 0 to 65535

boolean
false Is not precisely defined
5
Literals

A literal is the source code representation of a fixed


value; literals are represented directly in our code
without requiring computation.

As shown below, it's possible to assign a literal to a


variable of a primitive type:
boolean result = true;
char ch = 'C';
byte b = 100;
short s = 10000;
int i = 100000;

6
References

■ Book Resources:
• Herbert Schildt. Java: The complete Reference. Tata McGraw Hill (TMH),
9th Edition.
• Cay S. Horstmann, Gary Cornell. Core Java Volume-I and Volume-II.
Pearson Education, 8th Edition.
• Kathy Sierra, Bert Bates. Head First Java. O'Reilly Media, 2nd Edition.
• E. Balagurusamy, Programming with Java A Primer. TMH, 3rd Edition.

■ URL Resources:
• https://docs.oracle.com/javase/tutorial/java/package/index.html
• https://www.w3schools.com/java/default.asp

You might also like