Contents - Cultural View
Contents - Cultural View Contents - Cultural View
Java syntax 186 Primitive types Primitive types in Java include integer types, floating-point numbers, UTF-16 code units and a boolean type. There are no unsigned types in Java except char type, which is used to represent UTF-16 code units. The lack of unsigned types is offset by introducing unsigned right shift operation (>>>), which is not present in C++. Nevertheless, criticisms have been levelled about the lack of compatibility with C and C++ this causes. [1] Primitive Types Type Name Wrapper class Value Range Size Default byte java.lang.Byte integer −128 through +127 8-bit (1-byte) 0 short java.lang.Short integer −32,768 through +32,767 16-bit int java.lang.Integer integer −2,147,483,648 through +2,147,483,647 32-bit long java.lang.Long integer −9,223,372,036,854,775,808 through +9,223,372,036,854,775,807 float java.lang.Float floating point number ±1.401298E−45 through ±3.402823E+38 32-bit double java.lang.Double floating point number ±4.94065645841246E−324 through ±1.79769313486232E+308 (2-byte) (4-byte) 64-bit (8-byte) (4-byte) 64-bit (8-byte) boolean java.lang.Boolean Boolean true or false 8-bit (1-byte) false char java.lang.Character UTF-16 code unit (BMP character or a part of a surrogate pair) '\u0000' through '\uFFFF' 16-bit (2-byte) 0 0 0 0.0 0.0 Value '\u0000' char does not necessarily correspond to a single character. It may represent a part of a surrogate pair, in which case Unicode code point is represented by a sequence of two char values. Boxing and unboxing This language feature was introduced in J2SE 5.0. Boxing is the operation of converting a value of a primitive type into a value of a corresponding reference type, which serves as a wrapper for this particular primitive type. Unboxing is the reverse operation of converting a value of a reference type (previously boxed) into a value of a corresponding primitive type. Neither operation requires an explicit type cast. Example: int foo = 42; // Primitive type Integer bar = foo; /* foo is boxed to bar, bar is of Integer type, which serves as a wrapper for int */ int foo2 = bar; // Unboxed back to primitive type
Java syntax 187 Reference types Reference types include class types, interface types, and array types. When the constructor is called an object is created on the heap and a reference is assigned to the variable. When a variable of an object gets out of scope the reference is broken and when there are no references left the object gets marked as garbage. The garbage collector will then soon collect and destroy it. A reference variable is null when it does not reference any object. Arrays Arrays in Java are created at runtime, just like class instances. Array length is defined at creation and cannot be changed. int[] numbers = new int[5]; numbers[0] = 2; numbers[1] = 5; int x = numbers[0]; Initializers // Long syntax int[] numbers = new int[5] {20, 1, 42, 15, 34}; // Short syntax int[] numbers2 = {20, 1, 42, 15, 34}; Multi-dimensional arrays In Java multi-dimensional arrays are represented as arrays of arrays. Technically they are represented by arrays of references to another arrays. int[][] numbers = new int[3][3]; number[1][2] = 2; int[][] numbers2 = {{2, 3, 2}, {1, 2, 6}, {2, 4, 5}}; Due to the nature of the multi-dimensional arrays, sub-arrays may vary in length, so multi-dimensional arrays are not bound to be rectangular unlike C: int[][] numbers = new int[2][]; //Initialization of the first dimension only numbers[0] = new int[3]; numbers[1] = new int[2];
- Page 139 and 140: Todd Greanier 135 Todd Greanier Tod
- Page 141 and 142: Head First (book series) 137 Head F
- Page 143 and 144: Inner class 139 • Local class - T
- Page 145 and 146: Interface (Java) 141 The body of th
- Page 147 and 148: Internet Foundation Classes 143 Int
- Page 149 and 150: Internet Foundation Classes 145 •
- Page 151 and 152: JAD (file format) 147 JAD (file for
- Page 153 and 154: JAMWiki 149 JAMWiki Developer(s) Ry
- Page 155 and 156: JGroups 151 JGroups Stable release
- Page 157 and 158: Java Class Library 153 Java Class L
- Page 159 and 160: Java Class Library 155 Alternative
- Page 161 and 162: Java Classloader 157 User-defined c
- Page 163 and 164: Java compiler 159 Java compiler A J
- Page 165 and 166: Java Development Kit 161 • jstack
- Page 167 and 168: Java Interface Definition Language
- Page 169 and 170: Java TV 165 See also • Xlet Exter
- Page 171 and 172: Java Work Framework 167 Database db
- Page 173 and 174: Java annotation 169 programmaticall
- Page 175 and 176: Java annotation 171 component.getAt
- Page 177 and 178: Java collections framework 173 Refe
- Page 179 and 180: Java syntax 175 Java syntax The syn
- Page 181 and 182: Java syntax 177 Double quote \" Tab
- Page 183 and 184: Java syntax 179 import statement Th
- Page 185 and 186: Java syntax 181 switch statement Sw
- Page 187 and 188: Java syntax 183 outer: for (int i =
- Page 189: Java syntax 185 The catch and final
- Page 193 and 194: Java syntax 189 Foo.doSomething();
- Page 195 and 196: Java syntax 191 Modifiers • abstr
- Page 197 and 198: Java syntax 193 } public void walk(
- Page 199 and 200: Java syntax 195 Inheritance Interfa
- Page 201 and 202: Java syntax 197 /* Any Mapper insta
- Page 203 and 204: Java: View Technologies and Framewo
- Page 205 and 206: JavaBeans Activation Framework 201
- Page 207 and 208: javac 203 References [1] http:/ / j
- Page 209 and 210: JavaFX 205 profile includes Swing a
- Page 211 and 212: JavaFX 207 External links • Offic
- Page 213 and 214: JExamples 209 JExamples Industry Co
- Page 215 and 216: Jikes 211 Jikes Developer(s) IBM St
- Page 217 and 218: Michael Kölling 213 Microsoft Pate
- Page 219 and 220: List of Java keywords 215 case catc
- Page 221 and 222: List of Java keywords 217 long nati
- Page 223 and 224: List of Java keywords 219 Reserved
- Page 225 and 226: Name mangling 221 Name mangling In
- Page 227 and 228: Name mangling 223 } }; }; /* = _ZN9
- Page 229 and 230: Name mangling 225 if (__1cGstrcmp6F
- Page 231 and 232: Name mangling 227 ['_Test__private_
- Page 233 and 234: Name mangling 229 External links
- Page 235 and 236: Patrick Naughton 231 See also • H
- Page 237 and 238: New I/O 233 FileChannel can be used
- Page 239 and 240: New I/O 235 // Pattern used to pars
Java syntax 187<br />
Reference types<br />
Reference types include class types, interface types, and array types. When the constructor is called an object is<br />
created on the heap and a reference is assigned to the variable. When a variable of an object gets out of scope the<br />
reference is broken and when there are no references left the object gets marked as garbage. The garbage collector<br />
will then soon collect and destroy it.<br />
A reference variable is null when it does not reference any object.<br />
Arrays<br />
Arrays in Java are created at runtime, just like class instances. Array length is defined at creation and cannot be<br />
changed.<br />
int[] numbers = new int[5];<br />
numbers[0] = 2;<br />
numbers[1] = 5;<br />
int x = numbers[0];<br />
Initializers<br />
// Long syntax<br />
int[] numbers = new int[5] {20, 1, 42, 15, 34};<br />
// Short syntax<br />
int[] numbers2 = {20, 1, 42, 15, 34};<br />
Multi-dimensional arrays<br />
In Java multi-dimensional arrays are represented as arrays of arrays. Technically they are represented by arrays of<br />
references to another arrays.<br />
int[][] numbers = new int[3][3];<br />
number[1][2] = 2;<br />
int[][] numbers2 = {{2, 3, 2}, {1, 2, 6}, {2, 4, 5}};<br />
Due to the nature of the multi-dimensional arrays, sub-arrays may vary in length, so multi-dimensional arrays are not<br />
bound to be rectangular unlike C:<br />
int[][] numbers = new int[2][]; //Initialization of the first dimension<br />
only<br />
numbers[0] = new int[3];<br />
numbers[1] = new int[2];