Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summarize the basic knowledge of Java

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "Summarizing Java Basic Knowledge". In daily operation, I believe many people have doubts about summarizing Java Basic Knowledge. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts of "Summarizing Java Basic Knowledge"! Next, please follow the small series to learn together!

Configuration of environment variables:

1)Permanent configuration mode: JAVA_HOME=% installation path %\Java\jdk

path=%JAVA_HOME%\bin

2)Temporary configuration mode: set path=%path%;C:\Program Files\Java\jdk\bin

Features: By default, the system first goes to the current path to find the program to be executed, if not, then goes to the path set in the path.

Configuration of classpath:

1)Permanent configuration mode: classpath=.; c:\;e:\

2)Temporary configuration mode: set classpath=.; c:\;e:\

Note: Situations to be aware of when defining classpath environment variables

If the environment variable classpath is not defined, java will look for the class file to run in the current directory after starting jvm;

If classpath is specified, the specified directory is searched for the class file to run.

Will you still look in the current directory? Two situations:

What is CLASSPATH? What does it do?

It is an environment variable of the javac compiler. Its role is related to import and package keywords. When you write improt java.util.* When faced with the import keyword, the compiler knows that you want to introduce a class from the java.util package; but how does the compiler know where you put the package? So you first have to tell the compiler where the package is; how do you tell it? If java.util is in the c:/jdk/directory, you have to set the path c:/jdk/to CLASSPATH! When the compiler faces import java.util.* This statement, it will first look for CLASSPATH specified directory, and check if the subdirectory java/util exists, and then find the name matches the compiled file (.class file). If you don't find it, you'll report it wrong! CLASSPATH is a bit like the INCLUDE path setting in the c/c++ compiler, isn't it? When the c/c++ compiler encounters statements like include, how does it work? Oh, it's all the same! Search INCLUDE path, view files! When you develop a package yourself and want to use the classes in that package, naturally you have to set the directory where the package is located to CLASSPATH! CLASSPATH setting, Java for beginners is a tricky thing. So Sun makes Java2 JDK smarter. You'll find that after you install, you can compile basic Java programs and execute them even if CLASSPATH is not set at all.

PATH environment variable

PATH environment variable. The function is to specify the command search path. When a java program is compiled by executing a command such as javac below the command line, it will look in the path specified by the PATH variable to see if it can find the corresponding command program. We need to add the bin directory under the jdk installation directory to the existing PATH variable. The bin directory contains executable files that are often used, such as javac/java/javadoc. After setting the PATH variable, you can execute javac/java and other tools in any directory.

What do javac and java commands do?

Java is divided into two parts: one is compiled and the other is run.

Javac: responsible for the compilation part. When javac is executed, it starts java compiler programs. Compiles a.java file with the specified extension. Bytecode files that jvm can recognize are generated. That is, the class file, that is, java running program.

Java: The part responsible for running. JVM. loads the class libraries required for runtime and executes the class files.

For a file to be executed, there must be a starting point for execution, and that starting point is the main function.

Identifier:

1)Numbers cannot begin.

2)Keywords cannot be used.

Scope and lifetime of variables:

1. Scope of a variable: Scope begins at the location where the variable is defined and ends with the pair of braces in which the variable is located;

Life cycle: variables live in memory from the location they are defined;

A variable disappears from memory when it reaches its scope;

Data Type:

1): Basic data types: byte, short, int, long, float, double, char, boolean

Operator:

4)logical operators.

& | ^ ! && ||

Logical operators except! Both are used to join two boolean type expressions.

&: Only true on both sides results in true. Otherwise it is false.

|: If both are false, the result is false, otherwise it is true

^: Different or: A little different from or.

If both results are the same, it is false.

If the result is different, it is true.

The difference between & and &&:&: Whatever the result on the left is, the right is involved in the operation.

&&: Short AND, if false on the left, then no parameter AND operation on the right.

| and|| Difference:| : Both sides operate.

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

5), bit operator: An operator used to manipulate binary bits.

& | ^

> >>>(unsigned right shift)

EXERCISE: Swap data for two variables. No third-party variables are required.

int a = 3,b = 5;-->b = 3,a = 5;

Method 1:

a = a + b; a = 8;

b = a - b; b = 3;

a = a - b; a = 5;

Method 2:

a = a ^ b;//

b = a ^ b;//b = a ^ b ^ b = a

a = a ^ b;//a = a ^ b ^ a = b;

Exercise: Effectively calculate 2*8 = 2

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report