Java Applet based on the data entry type
Java language is similar to the C language and the data-processing capability that its data types and different kinds of computing a more complete definition, Java internal data types can be divided into four categories: integer, float, character, Boolean type. Integer and floating-point one two categories according to the different length and accuracy, can be further divided into byte, int, short, long, float, double, and a few specific types. Concrete can be found in the table below:
The basic data types Java
Data type keyword occupied bit numerical range default Boolean boolean 8 true, false false character byte 8 -128 - 127 0 integer type char 16 0 - 65535 '\ u0' short integer short 16 -32768 — 32767 0 integer int 32 -2147483648 - 2147483647 0-long 64-9.22E18 cosmetic - 9.22E18 0 floating-point-type float 32 1.4013E-45 - 3.4028E +38 0.0F-double and double-precision 64 2.22551 E-208 - 1.7977E +308 0.0D
1. Boolean
Boolean there can be only two true and false values, representing Boolean logic of the "true" and "false."
2. Integer and character
Integer is the integer mathematics, and character is the characters'0 'and' a ', are all characters. We should pay attention to two points:
1) the use of integer variables when attention should be paid to its maximum and minimum ranges, if the actual value exceeds the scope, there will be overflow error. Especially in the time to do factorial attention. If the machinery is not very good, but also save resources machines, the only type int, not long-use.
2) the value of character variables can be used character constants (in single quotes from the width of the individual characters), it is also possible integer constant. For example, the following two sentences identical to the role:
Char char_A = 'A';
Char char_A = 65;
This is a mechanism for the computer problem, as it rounded characters of the preserve. Because it more convenient.
3. Floating-point type
Float and double data types are floating-point, the process of using them to represent the minority. The computer used to calculate decimal floating-point, called floating-point data types. Because of this reason, the computer calculated the decimal point after the n-bit (depending on the specific case may be), and the actual numerical there will always be some error. It will only to try to close it, the more the median about precision. Float is 32, it should be enough, and if not, it will only use double, but also conserve resources.
Procedures in the scientific notation that is. For example: 3.14 E3 said that 3140, and 3.14 E-2 said that 0.0314. If there is a constant behind the 'd' or 'D', then that is double-. Pay site, should be written like this:
Float f1 = 3.14f;
Double f2 = 3.14d;
4. Type conversion
Java programs, constant or variable data type conversion from one to another data type, called type conversion. It has two, one is from the low to high as the default type conversion. For example, from the char to int type of conversion from the conversion to long-int type, are machines can be directly implemented. For example:
Int i = 5;
Long j = i;
If high into low, there will be a problem. Understand this truth, how do? When necessary, for example, to float into int type, it is only through the mandatory conversion type. For example:
Float f = 3.14f;
Int i = (int) f;
Long j = 5;
Int i2 = (int) j;
Of course we should pay attention to is high time into position, the scope of data to the status of, for example, can not be a major transformation of char type integer 30000 because it exceeded the scope. Results will mistake!
Well, look at one example:
Import java.awt .*;
Import java.applet.Applet;
Public class Leixing extends Applet
(
Boolean b1 = true;
Int x = 10;
Char c = 65;
Float f = 3.14f;
Public void paint (Graphics g)
(
G.drawString ( "Boolean:" + b1, 2,20);
G.drawString ( "integer:" + x, 2,40);
G.drawString ( "character" + c, 2,60);
G.drawString ( "floating-point data types:" + f, 2,80);
)
)
Tags: applet






