Learn about Java

Source: Internet
Author: User
Tags arithmetic operators stringbuffer

After studying Java for two weeks, I thought it was time to summarize my experience of learning java. I think it's important to start learning any class (including Java). Always feel that they are learning computer programming language, learning is not very good, but each language has its different essence, and has its own grammar, because the foundation is the most important, so the foundation is only possible to the back of the study has a deeper understanding, so to muster confidence, began a long Java journey.

Java's programming structure

Java is case sensitive and the program may not work if there is a case spelling error (such as: Main is written in main).

Comments

Three types of annotations

① single-line comment//comment content from//to Bank last

② all characters between a multiline comment/*///* * are ignored by the compiler

③ Document Comment/** * * All characters between/** * * are ignored by the compiler, Java Special (for generating documents);

Multiline comments and document comments cannot be nested.

Data Type

Java data types are divided into basic data types and reference data types. There are 8 basic data types, 4 integer, 2 floating-point, 1 Boolean, and one character type. Integral type includes four kinds, from small to large are byte, short, int, long. They represent numbers that do not have a decimal part and are allowed to be negative numbers.

A decimal integer, such as 123,-123,11.

An octal integer that begins with 0, such as 023, which represents the decimal number 19,-0111 represents the decimal number-81.

A hexadecimal integer that begins with 0x or 0X, such as 0x123, which represents the decimal number 291,-0x12 represents the decimal number-18.

Floating point Type

Floating-point types are used to represent numbers that have no decimal parts. Two float types: float (single-precision float) and double (double-precision floating-point).

Float:4 bytes, 32 bits. The float type requires a suffix F or f, which runs faster than double and takes up less memory, but becomes imprecise when the value is very large or very small. The float type can be used when the accuracy requirement is not high.

Double:8 bytes, 64 bits. A floating-point type with no suffix f or f is the default double type, and a double can also have a suffix of D or D. It is twice times more accurate than the float type, and most applications use a double type.

Char type: 2 bytes, used to represent a single character. Typically used to denote character constants. For example, ' A ' is a character constant encoded as 65, and "A" is a string of content.

A Boolean (Boolean) type has two values: false and True, which are used to determine the logical condition. cannot be converted to an integer value.

Variable

Java is a strongly typed language, so at the time of the life variable, the data type of the variable must be declared before

Constant

Constants: In the re-program, the variable that the value of the variable cannot change after the assignment is normally lit.

How to declare constants:

Final data type variable fame = variable value;

It is important to note that constant assignment is required while declaring the constant.

Operator

Subtraction the use of these operators, similar to other syntaxes

1. Self-increment, decrement operator

+=

-=

*=

2. Conversion of some data types

Some data type conversions (e.g. from low to high conversions) can be automatically converted, but some data types are subject to forced data type conversions, which may cause data loss

String

The string class is not the original base data type, and in Java, strings are an object.

The StringBuffer class is a thread-safe variable character sequence. A string-like buffer, but cannot be modified. Although it contains a specific sequence of characters at any point in time, some method calls can change the length and content of the sequence.

The StringBuilder class is a variable sequence of characters. This class provides an API that is compatible with StringBuffer, but does not guarantee synchronization. This class is designed to be used as a simple replacement for stringbuffer, which is common when a string buffer is used by a single thread. If possible, it is recommended that this class be preferred because, in most implementations, it is faster than StringBuffer.

Input and output

Read input

Formatted output

File input and output

Control Process1. Block scope
    • 1) block (that is, compound statement) refers to a number of simple Java statements enclosed in curly braces.
    • 2) block determines the scope of the variable
    • 3) one block can be nested within another block, but you cannot declare a variable of the same name in two nested blocks.

2. Conditional statements

if (condition) {statement; }

3. Cycle

1) While loop
while (condition) statement; The contents of the loop body may not be executed at once 2) do:  While loop do statement while (condition); The contents of the loop body are executed at least once 3) for loop

5. Multiple options: switch statement

1) Case Tag type support: Char, BYTE, short or int or corresponding wrapper class (Character, Byte, short, and Integer) 2) enumeration constants

Interrupt Control Flow Statement

1) The break statement is used to exit the switch statement, while statement, do: While statement, for statement 2) A tagged break statement that jumps out of multiple nested loop statements.                     You can only jump out of a statement block without jumping into a statement block. 3) The Continue statement crosses the remainder of the current loop body and jumps immediately to the loop header.         After the counter has been incremented, the loop body continues to execute. 4) The tagged continue statement jumps to the loop header that matches the label. Large Value
    • Java. Two useful classes in the math package: BigInteger and BigDecimal
    • These two classes implement the ability to handle numeric values that contain a sequence of arbitrary lengths
    • BigInteger a= biginteger.valueof (100); Use the static ValueOf method to convert a normal value to a large value
    • You cannot use normal arithmetic operators +-*/To handle large values, but you need to use the Add and Multipy methods in a large numeric class.
Array
    • An array is a data structure used to store a collection of values of the same type.
    • Each value in the array can be accessed through an integer decimal mark. A[i] represents an integer array, element I.
    • Declare data variables.

Although I study Java time is not long, but for now I still a beginner, but I am still very much looking forward to Java. In this period somewhat confused, also puzzled, more is to go a lot of detours, although the teacher assignment every time will not do, every time is to ask classmates, but oneself also try to understand it, slowly I also learned some knowledge.


Learn about Java

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.