Java Study Notes

Source: Internet
Author: User

1. Java Introduction
1.1 Basic Features of Java Syntax:
1) simple: it has a concise object-oriented syntax, and does not have the fuzzy concepts such as operator overloading and multi-inheritance.
2) Object-oriented: it has all the characteristics of object-oriented programming languages, such as encapsulation, inheritance, and polymorphism.
3) cross-platform: Provides bytecode instructions unrelated to the architecture. mainstream platforms provide JVM
4) Security: Java does not support pointers, avoiding pointer errors and spoofing access. It has a strict compilation and bytecode loading and verification mechanism.
5) multithreading: it has a powerful, simple, and platform-independent thread processing function.
----------------------------------------------------------------------------
1.2 Basic JVM principles
1) The JVM-Java Virtual Machine is responsible for parsing and executing Java code. The JVM can run on various operating system platforms.
2) Java cross-platform:
(Java program <-- JVM <-- Operating System <-- computer hardware)
Different platforms have different JVMs. Major Platforms provide their respective JVMs, so Java bytes can be executed on all platforms.
In this sense, Java is platform-independent, one-time writing, and runs everywhere.
Java is a cross-platform language. As long as the JVM is transplanted to a specific computer, compiled Java code can be run on the system.
3) Java program compilation and running process:
Step1. use the Java compiler to compile the Java source file into a. Class file, that is, a bytecode file.
Step2. start the Java Virtual Machine (JVM). Every Java program starts an independent JVM process.
Step3. JVM reads the. Class file and performs verification and initialization.
Verify: Check whether the. Class file meets the specifications
Initialization: allocate memory and initial values to variables.
Step 4. JVM re-compiles the. Class file into the machine code related to a specific platform,
Run and output results (Hotspot dynamic compilation and execution)
----------------------------------------------------------------------------
1.3 Basic concepts of JDK, JRE, and Java APIs
JDK-Java Development Kit (Java Development Kit)
JRE-Java runtime enviroment (Java Runtime Environment ),
JRE = JVM + javase API
JVM-Java Virtual Machine (Java Virtual Machine)
Java API-Application Programming Interface, Java System Standard class library
Development tools: JDK development tools
JDK Java Development Kit
| -- Development Tool (command: Java, javac, Jar ...)
| -- JRE Java Runtime Environment
| -- Java API (Application Programming Interface, System Library)
|
| -- JVM Java Virtual Machine
---------------------------------------
1.4 basic configuration of the Java environment
Java_home-JDK main directory
Classpath-Java class path,
Generally set to.; $ {java_home} \ Lib
Path-Add the JDK executable file path
Path =...; $ {java_home} \ bin
Start the shell terminal and type Java-version to check whether Java installation is successful.

Reference: http://linux.chinaunix.net/techdoc/beginner/2009/03/23/1104316.shtml
========================================================== ======================================
2.2 package statement
1) The package statement is used to place the class under a specific package, located in the first line of the Java source file.
Example: Package day01;
2) Functions of the package statement:
It is used to organize classes in Java to avoid naming conflicts.
3) the file must be placed in a directory that matches the package name.
Package day01; -----> helloworld2.java needs to be placed in the day01 directory
4) Compile and execute the Java program under the package:
CD./day01;
Javac helloworld2.java
CD ..
Java day01.helloworld2
(JVM searches for the day01 subdirectory in the current directory and loads helloworld2.class in the day01 directory)
5) Common JDK packages
Java. lang Package-provides the system class, string class, and integer class
(Classes in the Java. lang package do not need to be imported and are automatically imported)
Java. util package-Toolkit, which provides the date class (date), random class (random number ),
Set interfaces and classes.
Java. Io package-provides classes related to file and stream operations.
Java. SQL package-provides database-related classes.
Java.net package-Provides network programming-related classes.
Java. AWT package, javax. Swing package-provides classes related to creating graphical interfaces
---------------------------------------------------------------------------------- 2.3 Import Statement
1) the import statement is used to import classes in the package for direct use in the code.
2) Method 1: import a specific class, example: Import java. util. date;
Method 2: import all classes under the package, example: Import java. util .*;
Question: Import java. *; can I import all packages starting with Java?
(No) * only packages of the next level can be imported.
3) The Import Statement is located after the package statement, before the class definition,
There can be multiple import statements.
========================================================== ========================================================== =
3. Use of elcipse
3.1 understand Workspace-workspace, which is used to manage multiple projects and correspond to directories.
Projects are usually stored in the workspace directory.
3.2 differentiate between folder and source folder
Folder-folder, used to store any common files,
For example, notes is a folder.
Source folder-source folder, used to store Java source files,
Eclipse provides a source folder (SRC) by default ),
The. Class file after the source file is compiled is stored in the project/bin directory.
Multiple source folder can be created for one project as needed
3.3 manage multiple JRE in eclipse
Step1. window-> preferences-> JAVA
-> Installed jres
Step 2. Right-click the project and choose "build path )"
-> Configure build path-> select JRE
-> Remove-> Add libary-> system JRE Library
3.4 eclipse shortcut
Common shortcuts for Eclipse:
Alt +/: Content Assistant
-------------------------------
Main, ALT +/-> main method
Sysout, ALT +/-> system. Out. println ()
For, ALT +/-> for statement
If, ALT +/-> If statement
-------------------------------
F3: open declaration, view definition
CTRL + Shift + M: import package
CTRL + Shift + F: format the code
Alt + Shift + X, J: run Java program
Alt + up: Move the code up one line
Alt + down: Move the code down one line
CTRL +/: Set/cancel single line comment
CTRL + Shift +/: multi-line comment
CTRL + Shift + \: Cancel multi-line comment
CTRL + D: delete a row
(Set the shortcut key: window-> preferences-> gerneral-> keys)

Reference: http://www.blogjava.net/action/articles/17339.html
========================================================== ====
4. Java annotations
4.1 three types of annotations
1) single line comment: //, CTRL +/
2) multi-line comment:/*... */, CTRL + Shift +/
3) document notes :/**..*/
4.2 Use javadoc to generate relevant documents based on document comments
Eclispe right-click the menu export-> JAVA-> javadoc
========================================================== =====
5. Variables
3.1 variables are used to store changed data. Variable names can contain letters and numbers
, _, $, But cannot begin with a number.
Example: sum_100
5.2 declaration of variables: variables must be declared before they are used.
Syntax: data type variable name;
Example: int sum_100;
Double amount;
5.3 value assignment and use of Variables
Example: sum_100 = 0; // value assignment
Int I = 1;
Sum_100 = I; // use the variable I
5.4 an important rule: initial values must be assigned to local variables before use.
(Variable initialization refers to the first assignment after declaration)
5.5 variables cannot be defined repeatedly
5.6 scope of Variables
Variables can only be used within the range from the start of the variable definition to the end of the scope.
(Variables out of scope can be defined again)
========================================================== ======
4. Use integer and hexadecimal Methods
(The integer class is located in the Java. lang Package)
1) int parseint (string s, [int Radix])
-- Convert a value in string format to a decimal integer,
The radix parameter specifies the hexadecimal format, for example, 2, 16. The default value is 10.
2) string tostring (INT num, int Radix );
-- Returns the value in the specified hexadecimal string format.
========================================================== ======
5. Basic Data Types
5.1 There are 8 basic data types:
Byte short int long float double char Boolean
5.2 Integer type:
(All integers are signed integers. The highest digit is a signed digit,
0 indicates a positive number, and 1 indicates a negative number)
Byte-byte type, which occupies 1 byte in memory,
The data storage range is-128 ~ 127
The minimum value of byte is 1000 0000, and the maximum value is 0111 1111.
The corresponding Class byte provides two constants:
Min_value-minimum value of byte type
Max_value-maximum value of byte type
Short-short integer, which occupies 2 bytes (16 bits) in memory)
The data storage range is-2 ^ 15 ~ 2 ^ 15-1
The corresponding short class provides two constants:
Minimum value of min_value-Short Type
Maximum Value of max_value-Short Type
INT-integer, 4 bytes in memory (32 bits)
The data storage range is-2 ^ 31 ~ 2 ^ 31-1 (2 billion +)
The corresponding class integer provides two constants:
Min_value-minimum value of int type
Max_value-maximum value of int type
Long-long integer, which occupies 8 bytes (64) in the memory ),
The data storage range is-2 ^ 63 ~ 2 ^ 63-1
---------------------------------------
5.3 floating point type
Float-single precision, 4 bytes in memory
Double-double precision, which occupies 8 bytes in the memory,
Double type is more accurate than Float Type
5.4 character type
Char-character type, which occupies 2 bytes in memory,
Is an unsigned 16-digit integer,
The value range is 0 ~ 65535, adopts unicode encoding
Example:
Char c = 'a';-> unicode encoding 65
-> Binary format in memory:
0000 0000 0100 0001
0 ~ 9, ~ Z, ~ Z is continuously encoded.
The Unicode encoding of '0' is 48.
The Unicode encoding of 'A' is 65.
The Unicode encoding of 'A' is 97.
5.5 Boolean Type
Boolean-boolean type, indicating true and false. Values: true and false
------------------------------------------
6. Introduction to the java. util. Collections class
The accept Class is used to receive data from the console.
Steps for using the sequence:
Step 1. Create a sequence object through system. In
Pipeline SC = new pipeline (system. In );
Step2. use the next () method to obtain the input string
Obtain the input integer using the nextint () method.
The nextdouble () method is used to obtain the input floating point number.

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.