First knowledge of Java and basics

Source: Internet
Author: User

Java is not just a programming language, he is a complete platform, with a huge code base. First of all you have to do, may need to download JDK package, download and install, self-Baidu.

After downloading the JDK, the JDK directory tree is as follows:

  directory structure description
bin compiler and tools
d Emo demo
docs HTML format Class Library document (after extracting 2sdkversion-doc.zip j)
include file for compiling local methods
jre Java Run environment
lib class library file
src class Library source file

Fundamentals of Basic program Design in Java: data types , variables , operators , strings , annotations , input and output , control Flow , large values , arrays . And of course there are many other things. This article mainly introduces the content mentioned earlier.

1. Note : Annotations are an integral part of any language and can improve the readability of your program. There are mainly the following three kinds:

Single-line comment.

/* * * Multiple lines of comments. Note: This comment cannot be nested. Cannot be included with each other.

/** */Documentation comments. This comment can generate the corresponding document from some Java commands. Please see my initial notes for specific explanations.

2. Data type : Java is a strongly typed language, meaning that each variable must be declared as a type. Then there are 8 basic data types in Java, as follows:

  2.1 Four integer types : No decimal point

Type Storage requirements Range of values
Int 4 bytes -2 147 483 648 ~ 2 147 483 648
Short 2 bytes -32 768 ~ 32 7677
Long 8 bytes -9 223 372 036 854 775 808 ~ 9 223 372 036 854 775 808
Byte 1 bytes -128 ~ 127

  

  

  

  2.2 Two floating-point types : including decimal points

Type Storage requirements Range of values
Float 2 bytes Approx. ±3.402 823 47E + 38F (6 to 7 digits of effective digits)
Double 8 bytes Approx. ±1.797 693 134 862 315 70E + 308 (15 bits of effective digits)

Floating-point number, three special floating-point values representing overflow and error conditions: Positive infinity (double.positive_infinity), negative infinity (double.negative_infinity), NaN (not a number)

  2.3 A character type used to represent a Unicode-encoded character cell Char

This type is generally not recommended for use in programs.

  2.4 A Boolean type that represents the truth value Boolean

There are two types of this type: false and True

3. Variables

Note:1) Each variable belongs to a type, that is, a strong type.

2) consisting of numbers, letters, ' _ ', ' $ '

3) to make sense, improve readability

4) Case Sensitive

5) cannot start with a number

  3.1 Initialization

  A variable must be initialized before it is used.

    Definition and declaration of specific differences

The so-called definition is (the compiler) creates an object, allocates a piece of memory for the object, and gives it a name, which is what we often call variable names or object names.

The declaration has a 2-heavy meaning:

(1) Tell the compiler that the name has been matched to a piece of memory, and the following code uses the variable or object defined elsewhere. A declaration can occur more than once.

(2) Tell the compiler that the name has been reserved, and that it can no longer be used as a variable name or object name elsewhere.

Defining and declaring the most important differences

Defines the creation object and allocates memory for this object, declaring no memory allocated.

3.2 Constants

In Java, use the final keyword to indicate constants. Once a constant has been assigned, it can no longer be changed. The customary constant name uses all uppercase.

4. Operators

4.1 Basic operators, subtraction.

4.2 Self-addition and self-reduction

4.3 Ternary operator (? :)

4.4-bit operators

4.5 Operator Precedence

Priority level Operator Binding nature
1 () [] . From left to right
2 ! + (positive)-(negative) ~ + +-- From right to left
3 * / % From left to right
4 + (plus)-(minus) From left to right
5 << >> >>> From left to right
6 < <= > >= instanceof From left to right
7 ==   != From left to right
8 & (Bitwise AND) From left to right
9 ^ From left to right
10 | From left to right
11 && From left to right
12 || From left to right
13 ?: From right to left
14 = + = = *=/=%= &= |= ^= ~= <<= >>= >>>= From right to left

5. Mathematical Functions and constants

Query the usage of the Math class for details

6. Type conversion

6.1 Legality

    

6.2 Casts

    For example: int number = 2;

string s = (string) number; convert int type to String

  

First knowledge of Java and basics

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.