📄 00000000.htm
字号:
Java syntax for C programmers: <BR> <BR>3.1: Data Types <BR> <BR>Java's primitive data types are very similar to those of C. Strings, booleans, and true arrays have <BR>been added. However the implementation of the data types has been substantially cleaned up in <BR>several ways. <BR> <BR> 1.Where C and C++ leave a number of issues to be machine and compiler dependent (for <BR> instance the size of an int) Java specifies everything. <BR> <BR> 2.Java prevents casting between arbitrary variables. Only casts between numeric variables and <BR> between sub and superclasses of the same object are allowed. <BR> <BR> 3.All numeric variables in Java are signed. <BR> <BR>Here are the detailed data types: <BR> <BR>boolean <BR> 1-bit. May take on the values true and false only. <BR> <BR> true and false are defined constants of the language and are not the same as True and <BR> False, TRUE and FALSE, zero and nonzero, 1 and 0 or any other numeric value. Booleans <BR> may not be cast into any other type of variable nor may any other variable be cast into a <BR> boolean. <BR> <BR>byte <BR> 1 signed byte (two's complement). Covers values from -128 to 127. <BR> <BR>short <BR> 2 bytes signed (two's complement), -32,768 to 32,767 <BR> <BR>int <BR> 4 bytes, signed (two's complement). -2,147,483,648 to 2,147,483,647. Like all numeric types <BR> ints may be cast into other numeric types (byte, short, long, float, double). When lossy casts <BR> are done (e.g. int to byte) the conversion is done modulo the length of the smaller type. <BR> <BR>long <BR> 8 bytes signed (two's complement). Ranges from -9,223,372,036,854,775,808 to <BR> +9,223,372,036,854,775,807. <BR> <BR>float <BR> 4 bytes, IEEE 754. Covers a range from 1.40129846432481707e-45 to <BR> 3.40282346638528860e+38 (positive or negative). <BR> <BR> Like all numeric types floats may be cast into other numeric types (byte, short, long, <BR> int, double). When lossy casts to integer types are done (e.g. float to short) the <BR> fractional part is truncated and the conversion is done modulo the length of the smaller type. <BR> <BR>double <BR> 8 bytes IEEE 754. Covers a range from 4.94065645841246544e-324d to <BR> 1.79769313486231570e+308d (positive or negative). <BR> <BR>char <BR> 2 unsigned bytes, Unicode. <BR> <BR> Chars are not the same as bytes, ints, shorts or Strings. <BR> <BR>Strings <BR> Strings are a special object defined in java.lang.String. They are not null terminated and are <BR> not the same as an array of chars. <BR> <BR>array <BR> Arrays are objects. Multidimensional arrays are created via arrays of arrays. <BR> <BR>sizeof isn't necessary in Java because all sizes are precisely defined. i.e. an int is always 4 bytes. <BR>This may not seem to be adequate when dealing with objects that aren't base data types. However <BR>even if you did know the size of a particular object, you couldn't do anything with it anyway. You <BR>cannot convert an arbitrary object into bytes and back again. <BR> <BR>3.2: Control Statements <BR> <BR>Java contains if, else, for, while, do while and switch statements. The syntax is identical <BR>to C's. However all condition tests must return boolean values. Since non-boolean assignment <BR>statements and arithmetic statements do not return a boolean value, some of the more obfuscated <BR>condition tests in C are prohibited. <BR> <BR>3.3: Command Line Arguments <BR> <BR>Command line arguments are like C's except that argv has become a string array commonly <BR>called args and args[0] is the first command line argument, not the name of the program. The <BR>other arguments are all shifted one to the left from where they'd be in C or C++. <BR> <BR>3.4: Comments <BR> <BR>Java supports both the /* This is a comment */ comment from C and the <BR>// This is a C++ comment <BR>comment from C++. <BR> <BR>However comments that begin with a /** are special. These comments should only be used before <BR>a method or class declaration. They indicate that the comment should be included in automatically <BR>generated documentation for that declaration. <BR> <BR>3.5: Classes <BR> <BR>Java does not support multiple inheritance. <BR> <BR>Superclasses of a class are indicated with the extends keyword rather than with a :. <BR> <BR>Methods must be defined inside the class to which they belong. They may not be declared inside <BR>the class and defined outside the class as is common in C++. <BR> <BR>3.6: How is Java unlike C++? <BR> <BR>Two classes of language features have been removed from C++ to make it Java. These are those <BR>language features which make C++ unsafe and those which make it hard to read. <BR> <BR>Features removed that make Java easier to read and understand than C++ include #define, <BR>typedef, operator overloading, enum, unions and structs. <BR> <BR>The main feature removed to make Java safer and more robust than C++ is pointer arithmetic. <BR> <BR>Other features removed include global variables, standalone functions (everything is a method), <BR>friend functions (Everything in a package is a friend of everything else in the package.) and <BR>non-virtual functions. <BR> <BR>A number of features have been added to Java to make it safer including true arrays with bounds <BR>checking, garbage collection, concurrency, interfaces (from Objective C) and packages. There is no <BR>need to explicitly allocate or free memory in Java. <B
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -