Java Overview and Basics

Source: Internet
Author: User

key points of knowledge :

    1. What is programming
    2. What is cross-platform? What is the principle? Jvm
    3. What is the difference between JRE and JDK?
    4. Java Virtual Machine JVM
    5. Java Program operating mechanism
    6. Java Environment variables
    7. Java Basic syntax

    • What is programming?

Programming is the process of having a computer write program code in a programming language to solve a problem and ultimately get results. In order for the computer to understand human's intention, human beings must be able to solve the problem of thinking, methods and means through the computer can understand the form of telling the computer, so that the computer can be based on the instructions of the person to complete the work step-by-step, complete a specific task.

The process of communication between people and computers is programming.

    • What is cross-platform? What is the principle? Jvm

The so-called cross-platform, refers to the Java language program written, once compiled, can be run on multiple system platforms.

Implementation principle: Java program is running on the system platform through the Java Virtual machine, as long as the system can install the corresponding Java virtual machine, the system can run Java programs.

The Java program is able to run across platforms because it does not run directly on any underlying platform, but where it needs to be ready to prepare its own Java platform, and this is just the installation of a software configuration.

    • The difference between JRE and JDK

Jre:java Runtime Environment,java run environment, including the Java Virtual machine JVM and Java program required core class library, if you want to run a well-developed Java program, the computer only need to install the JRE

Jdk:java Development Kit Java, Developer Kit. The JDK is available to Java developers, which includes Java development tools and the JRE. So with the JDK installed, you don't have to install the JRE separately.

Simply put, Java programs developed with the JDK are delivered to the JRE.

    • Java Virtual Machine JVM

Java Virtual Machine, referred to as the JVM.

It is an abstract computer that runs all Java programs, is the Java language's operating environment, it is one of the most attractive features of Java, the JVM reads and processes the compiled platform-independent bytecode (class) files. The Java Editor generates a class file for the JVM and is therefore platform-independent.

Java virtual machines are not cross-platform.

    • Java Program operating mechanism

Compile: javac filename. filename suffix

Run: Java class name

Java program composition: Java source files, bytecode files.

Javac: is responsible for the compilation of the part, when the execution of Javac, will start the Java compiler program. Compiles a. java file with the specified extension. Generates bytecode files that the JVM can recognize. This is the class file, which is Java's running program.
Java: The part that is responsible for running. The JVM is started. Loads the class library that is required by the runtime and executes it. A file must have a starting point for execution, and this starting point is the main function.

    • Java Environment variables

Configure environment variables: Let the Java jdk\bin Directory tool, can be run in any directory, because the tool is located in the directory to tell the system, when using the tool, the system to help us to find the specified directory.

Configuration of environment variables:

Permanent configuration method: java_home=% Installation path%\JAVA\JDK

Path=%java_home%\bin

Temporary configuration method: Set path=%path%; C:\Program Files\java\jdk\bin

Features: The system defaults to the current path to find the program to be executed, if not, in the path to set up the paths to find.

Configuration of the classpath:

Permanent configuration mode: classpath=.; C:\;e:\

Temporary configuration mode: Set classpath=.; C:\;e:\

Note: When defining CLASSPATH environment variables, you need to be aware of the situation

If you do not define an environment variable Classpath,java starts the JVM, it looks for the class file to run under the current directory:

If Classpath is specified, the class file to be run is looked up under the specified directory.

Will I find it in the current directory? Two cases.

If there is a semicolon at the end of the value of Classpath, the running class is not found in the specific path and will be found by default in the current directory.

If the value of Classpath does not have a semicolon at the end, the running class is not found in the specific path and will not be found in the current directory.

Generally do not specify a semicolon, if not found in the specified directory run class file, the error, so you can debug.

    • Java Basic syntax

keywords: in fact, a language is given special meaning words.

reserved words: In fact, there is no special meaning to be used in future words.

marker: is actually a custom noun in the program. such as the class name, variable name, function name. Contains 0-9,a-z,a-z,$,_.

Note: Numbers may not start, and keywords cannot be used.

constants: data that is not changed in the program.

variables: In fact, memory storage space, used to store constant data.

Function: Convenient operation, because some data is uncertain, so determine the noun and storage space of the data.

Features: Variable space can be reused.

When do I define a variable? Define variables whenever you are hungry for data uncertainty.

What are the elements needed to open up variable spaces?

    1. What data does this space store? The data type.
    2. What's the name of this space? The variable name.
    3. What is the first data of this space? The initialization of the variable.

Scope and lifetime of a variable?

Scope of the variable:

The scope starts at the beginning of the definition of the variable, ending with the curly brace where the variable is located.

Life cycle:

The variable is alive in memory, starting at the defined position.

When a variable reaches its scope, it disappears in memory.

Data type:

Basic data type: byte short int long float double char Boolean

Reference data type: Array class interface

The level is from low to High: Byte char short (these three-lateral) →int→long→float→double.

Automatic type conversion: from low to high level, the system is automatically converted.

Strong type conversions: What is the use of? Assign a high-level number to a lower-level variable.

Summary: Type conversions.

Small turn big, automatic! Automatic type conversion, also known as implicit type conversion.

Big turn small, force! Coercion type conversions, also called explicit type conversions.

Operator:

Arithmetic operator.
+-*/%: Any integer modulus 2 is not 0 is 1, so as long as the change is the module can be implemented switch operation.
+: Connector.
++,--
The assignment operator.
= += -= *= /= %=
3/65
The comparison operator.
Features: This operator is characterized by the result of the operation, either True or false.
The logical operator.
& | ^ ! && | |
Logical operator except! are used to concatenate two Boolean expressions.
&: Only both sides are true and the result is true. Otherwise, it is false.
|: If both sides are false the result is false, otherwise it is true
^: xor: And or a little different.
On both sides, the result is false.
It is true that the results are different on both sides.


& and &&: difference:

&: Regardless of the left result, the right side is involved in the operation.
&&: Short circuit with, if the left is false, then the right side is not a parameter and operation.
|  and | | Difference:

|: Both sides of the operation.
|| : Short circuit or, if the left is true, then the right side does not participate in the operation

Statement:

If switch do and while and for

When do these statements work?

    1. When judging a fixed number of values, you can use if or switch.

However, it is recommended to use switch for relatively high efficiency.

Switch (variable) {

Case value: The statement to execute, break.

...

Default: The statement to execute.

}

How it works: Compare the value of the parentheses variable with the value of the case, and the statement following the case after which case is executed. If not, the statement following the default is executed.

Details:

Break can be omitted if omitted and is executed until a break is encountered.

The variables in the parentheses following the switch should be one of the byte,char,short,int, enumerations.

The default can be written anywhere in the switch statement, and if the default is placed in the first row, the program will remove the value from the default

Starts execution until the first break appears.

    2. The IF statement is required when judging the data range and getting the result of the Boolean type.

    3. When certain statements need to be executed multiple times, the loop structure is used.

While and for can be interchanged: The difference is that to control the number of loops, it is recommended to use for because the for loop is complete and the variables are freed in memory.

Break acts on a switch and a loop statement, either to jump out or to end.

Continue is used only for loop structure, to end this loop, to continue the next loop, the statement word exists, the following is not allowed to define the statement, do not execute.

Expressions and three-mesh operators:

Expression: A sequence of meaningful sorts that can be evaluated by numbers, operators, numeric grouping symbols (parentheses), and so on. For example A+b,3.14+a,boolean b= i < && (i%10! = 0)

The value of an expression: the result of an operation on an expression is the value of an expression.

Type of expression: The data type of the value of the expression is the type of the expression.

The order of operations of an expression: the precedence of the operator should be from high to low, with the same precedence in left-to-right order.

Trinocular operator: syntax format x? Y:z where x is a Boolean expression, the value of x is evaluated first, and if true, the result is Y, otherwise Z.

Java Overview 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.