Java basic programming structure (1)

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.