Although I have learned the design mode and J2EE, I started to learn Java this semester. Oh, it's a bit upside down, but I still need to start from the basics. Hoho ~~
(1) A simple Java application
Package edu. ynu. java. lession1
/*
The simplest Java program
*/
Public class firstjavaprog
{
Public static void main (string [] ARGs)
{
// System. out is the standard output stream.
System. Out. println ("Hello! ");
}
}
(2) Notes
// This is my first Java program
(3) Data Types
Byte (1 bytes,-128... 127)
Short (2 bytes,-32,768... 32,767)
INT (4 bytes,-2,147,483,648... 2,147,483,647)
Long (8 bytes)
Integer literals can be specified in several bases:
Decimal--99/32174
Octal-012 or 07
Hexadecimal-0xff or 0xabcdef01
Float
4 bytes
6.5 significant digits
± 3. 4028e + 38f
Denoted by 'f' or 'F' suffix
Double
8 bytes
15 significant digits
±1. 7977e + 308
Denoted by 'D' or 'D' suffix (or no suffix)
If (double. isnan (x) // check whether X is "not a number"
Boolean
Char
(4) variables
Assignment and initialization
Constant
Example:
Public class Constants
{
Public static void main (string [] ARGs)
{
Final double cm_per_inch= 2.54;
Double paperwidth = 8.5;
Double paperheight = 11;
System. Out. println ("paper size in centimeter :"
+ Paperwidth * cm_per_inch + ""
+ Paperheight * cm_per_inch );
}
}
(5) Operators
Arithmetic +,-, *,/, and %.
Prefix and Postfix ++ and --.
Boolean = ,! =, <, <=,>, >=, &, And |.
Bitwise &, |, ^, and ~.
Arithmetic shift <and>.
Logical shift >>>.
Java logical operators
& (Conditional and)
& (Boolean logical and)
| (Conditional or)
| (Boolean logical transaction sive or)
^ (Boolean logical exclusive or)
! (Logical not)
Mathematical functions and constants
Constants (e. g, math. Pi)
Functions (e.g., math. Sin ())
Conversion between numeric types
Forced type conversion
Double X = 9.997;
Int Nx = (INT) math. Round (X );
Brackets and operator levels
Brackets are not allowed.
Enumeration type
Enum size {small, mediue, large, extra--large };
Size S = size. Small;
Note: variables start with lowercase letters, constants and class names start with uppercase letters.