Professional Documents
Culture Documents
• The name of a class, method, or variable in Java is called an identifier, which can be any string of characters as long as it
begins with a letter and consists of letters, numbers and underscore
• Exceptions: Reserved words cannot be used as identifiers
• Java has several base types, which are basic ways of storing data.
• An identifier variable can be declared to hold any base type and it can later be reassigned to hold another value
of the same type.
carry 1 1
1 1 1
+ 1 0 1
sum 1 1 0 0
How to represent negative numbers
• Use a sign bit
• Let us say, we have 4 bits words
• 1 bit for sign (0: +ve, 1: -ve), 3 bits for number
• Largest (positive) number: 0111: which is 1*22 + 1 * 21 + 1 * 20 = 7
• Smallest (negative) number: 1111: which is -7
• Two representations for 0: 1000, 0000 which are not required
• Two’s complement is used which has only one representation for 0
• The range of numbers: -8 to 7
• For n bit word, range is -2 n-1 to 2 n-1 -1
Arithmetic Operators
• Java supports the following arithmetic operators:
• Java supports the following operators for numerical values, which result in Boolean values:
• The and and or operators short circuit, in that they do not evaluate the second operand if
the result can be determined based on the value of the first operand.