0% found this document useful (0 votes)
2 views

3) Datatypes and Operators

The document outlines essential concepts in Java programming, including types of comments, variables, and data types. It details three variable types (local, instance, static) and distinguishes between primitive and non-primitive data types. Additionally, it lists various operators and Java keywords, explaining their functions within the language.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

3) Datatypes and Operators

The document outlines essential concepts in Java programming, including types of comments, variables, and data types. It details three variable types (local, instance, static) and distinguishes between primitive and non-primitive data types. Additionally, it lists various operators and Java keywords, explaining their functions within the language.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

COMMENTS:

Comments are ignored by Java Compiler.

There are 3 types of comments:

 // comment - Single line comment

 /* comment */ - Multi line comment

 /** documentation comment */

TYPES OF VARIABLES:
Variable is a named memory location to hold a value.

There are 3 types of variables:

1. Local variables – they are declared inside a method

2. Instance variables – they are declared inside a class but outside methods. Separate copies
are created for this variable when they are accessed by many instances of the class.

3. Static variables – they are declared with a keyword “static” and it can be accessed
without any creation of objects. Only one copy of this variable will be available for all
instances of the class.

DATATYPES:

There are 2 types:

 Primitive data type

 Non Primitive data type


Primitive Data Type:

1. byte – 1 byte

2. char – 2 byte

3. short – 2 byte

4. int – 4 byte

5. long – 8 byte

6. float – 4 byte

7. double – 8 byte

8. Boolean – true / false

Non Primitive Data Type: String, Array, etc (uses new operator)

OPERATORS:
1. Arithmetic Operators : +, -, /, *, %, ++, --

2. Relational Operators : ==, !=, >, <, >=, <=

3. Bitwise Operators : & (Binary AND)

i. | (Binary OR)

ii. ^ (Binary XOR)

iii. ~ (Binary Ones Complement)

iv. << (Binary Left Shift)

v. >> (Binary Right Shift)

vi. >>> (Shift right zero fill)

4. Logical Operators : && (Logical AND)

i. || (Logical OR)

ii. ! (Logical NOT)

5. Assignment Operators : =, +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^=
JAVA KEYWORDS:

Keyword What It Does


Indicates that the details of a class, a method, or an interface are given elsewhere in
abstract
the code.
assert Tests the truth of a condition that the programmer believes is true.
boolean Indicates that a value is either true or false, in the Java sense.
break Jumps out of a loop or switch.
byte Indicates that a value is an 8-bit whole number.
case Introduces one of several possible paths of execution in a switch statement.
Introduces statements that are executed when something interrupts the flow of
catch
execution in a try clause.
Indicates that a value is a character (a single letter, digit, punctuation symbol, and
char
so on) stored in 16 bits of memory.
class Introduces a class — a blueprint for an object.
You can’t use this word in a Java program. The word has no meaning. Because it’s
const
a keyword, you can’t create a const variable.
continue Forces the abrupt end of the current loop iteration and begins another iteration.
Introduces a path of execution to take when no case is a match in a switch
default
statement.
Causes the computer to repeat some statements over and over again (for instance,
do
as long as the computer keeps getting unacceptable results).
Indicates that a value is a 64-bit number with one or more digits after the decimal
double
point.
Introduces statements that are executed when the condition in an if statement isn’t
else
true.
enum Creates a newly defined type — a group of values that a variable can have.
Creates a subclass — a class that reuses functionality from a previously defined
extends
class.
Indicates that a variable’s value cannot be changed, that a class’s functionality
final
cannot be extended, or that a method cannot be overridden.
finally Introduces the last will and testament of the statements in a try clause.
Indicates that a value is a 32-bit number with one or more digits after the decimal
float
point.
Gets the computer to repeat some statements over and over again (for instance, a
for
certain number of times).
You can’t use this word in a Java program. The word has no meaning. Because it’s
goto
a keyword, you can’t create a goto variable.
Tests to see whether a condition is true. If it’s true, the computer executes certain
if
statements; otherwise, the computer executes other statements.
implements Reuses the functionality from a previously defined interface.
import Enables the programmer to abbreviate the names of classes defined in a package.
instanceof Tests to see whether a certain object comes from a certain class.
int Indicates that a value is a 32-bit whole number.
Introduces an interface, which is like a class, but less specific. (Interfaces are used
interface
in place of the confusing multiple-inheritance feature that’s in C++.)
long Indicates that a value is a 64-bit whole number.
Enables the programmer to use code that was written in another language (one of
native
those awful languages other than Java).
new Creates an object from an existing class.
package Puts the code into a package — a collection of logically related definitions.
private Indicates that a variable or method can be used only within a certain class.
protected Indicates that a variable or method can be used in subclasses from another package.
public Indicates that a variable, class, or method can be used by any other Java code.
return Ends execution of a method and possibly returns a value to the calling code.
short Indicates that a value is a 16-bit whole number.
Indicates that a variable or method belongs to a class, rather than to any object
static
created from the class.
Limits the computer’s ability to represent extra large or extra small numbers when
strictfp
the computer does intermediate calculations on float and double values.
super Refers to the superclass of the code in which the word super appears.
Tells the computer to follow one of many possible paths of execution (one of many
switch
possible cases), depending on the value of an expression.
synchronized Keeps two threads from interfering with one another.
this A self-reference — refers to the object in which the word this appears.
Creates a new exception object and indicates that an exceptional situation (usually
throw
something unwanted) has occurred.
Indicates that a method or constructor may pass the buck when an exception is
throws
thrown.
Indicates that, if and when an object is serialized, a variable’s value doesn’t need to
transient
be stored.
Introduces statements that are watched (during runtime) for things that can go
try
wrong.
void Indicates that a method doesn’t return a value.
volatile Imposes strict rules on the use of a variable by more than one thread at a time.
while Repeats some statements over and over again (as long as a condition is still true).

You might also like