Difference between revisions of "Misc"
From Suhrid.net Wiki
Jump to navigationJump to searchLine 17: | Line 17: | ||
* String $; | * String $; | ||
− | Literals | + | == Literals == |
* Default type of an integer literal is int. | * Default type of an integer literal is int. | ||
Line 36: | Line 36: | ||
* Float is denoted by suffix f or F | * Float is denoted by suffix f or F | ||
− | Comments | + | * Integers are stored in 2 complements's notation |
+ | * Leftmost bit is the sign bit, the remaining bits are used to store the value | ||
+ | * Byte - 1 byte = 8 bits. | ||
+ | * Leftmost bit is to store the sign. So 7 bits are available for the value, so 2^7 = 128 values | ||
+ | * Negative range is -128 to -1 (128 numbers) | ||
+ | * Positive range is 0 to 127 (128 numbers, 0 is stored as a positive number) | ||
+ | * So a byte can store | ||
+ | <math> | ||
+ | -2^7 to 2^7 | ||
+ | </math> | ||
+ | |||
+ | |||
+ | <u> Comments </u> | ||
* Comment start sequences like //, /*. /** are ignored within comment blocks. | * Comment start sequences like //, /*. /** are ignored within comment blocks. | ||
* So trying to nest multiple-line comments will result in an error | * So trying to nest multiple-line comments will result in an error |
Revision as of 00:29, 21 June 2011
This covers Objective 1.3
Legal Identifiers
- Can be composed of characters, numbers, currency-symbols and connecting chars such as underscore.
- Definition of characters are interpreted according to the charset.
- NO special chars such as #, :, ;, @, -, etc...
- Must start with letter, currency char, underscore but CANNOT start with a digit !
- Java identifiers are case-sensitive.
Illegal identifiers:
- int 23age;
- String em@iladd;
- List all-accounts;
These are legal!:
- int __;
- String $;
Literals
- Default type of an integer literal is int.
- Long can be specified by adding l or L
- Octal prefix with 0
- Hex prefix with 0x or 0X
- Floating point literals default type is double.
float pi = 3.14; // This will be a compiler error, because 3.14 is a fp literal which is double by default
double pi = 3.14; //OK
float pi = 3.14f; //OK
- Double can also be explicitly by adding the suffix d or D
- Float is denoted by suffix f or F
- Integers are stored in 2 complements's notation
- Leftmost bit is the sign bit, the remaining bits are used to store the value
- Byte - 1 byte = 8 bits.
- Leftmost bit is to store the sign. So 7 bits are available for the value, so 2^7 = 128 values
- Negative range is -128 to -1 (128 numbers)
- Positive range is 0 to 127 (128 numbers, 0 is stored as a positive number)
- So a byte can store
<math> -2^7 to 2^7 </math>
Comments
- Comment start sequences like //, /*. /** are ignored within comment blocks.
- So trying to nest multiple-line comments will result in an error
/* This is the foo algorithm
/* which takes foo's and sort's bars */
*/