java study notes day1

java study notes day1

2019/5/30 officially opened the road java learning, today introduced the installation configuration of java, java development history, entry-java case, press the Start teacher let us use Notepad to edit java code, with command-line compiler, run the code, I think this is just fine for beginners java, and if the direct use some nice editor, we'll make a little java compilation process here refers to the cpu .java to .class bytecode files. In short, I think learned a lot.

1. What is the JDK, which includes what

JDK is an acronym for Java Development Kit (Java Development Kit) is. It is released for building applications on the Java platform, applet and component development environment. Including the Java compiler, JVM, a large number of Java tools and Java API which is the basis of Java class libraries and Java language specification.

JDK mainly includes:
A) Java Virtual Machine: Java program responsible for parsing and executing
the Java virtual machine can run on various platforms
b) JDK class library: to provide the most basic of Java classes and a variety of practical classes.
These classes in the JAVA_HOME $ / JRE / lib / rt.jar
the java.lang, the java.io, Classes in java.util,
in javax.swing, the java.sql package JDK classes are in the class library.
c) development tools: These tools are executable programs.
including: located JAVA_HOME $ / bin
javac.exe compiler tools;
    java.exe running tool;
javadoc.exe generate JavaDoc documentation tool
jar.exe packaging tools.

2. and java related environmental variables that have a few, they have what effect

The JAVA_HOME: action: the other variables are simplified content of the input setting process. There are at variable setting process may be used more than once to the JDK installation path, how to simplify multiple input process? Can first be installed JDK path is defined as a variable, who later use the JDK installation path where both use the variable replace.

path: the role: to find the corresponding executable file path specified range of an external command;

classpath: Role: represents the root of the Java class path. java command to find the required Java classes from the classpath, when the Java compiler compiles Java classes, will find the necessary Java classes from the classpath. The default value is the current path classpath.

Summary: So you need to configure jdk bin directory in your PATH, meaning through the commands found in the bin directory of exe files.

llinux configuration in the home directory .bashrc configuration Path = $ PATH: jdk bin directory. java javac command to verify,

现在在家目录创建sre(用来存放.java代码)、bin(用来存放.class代码),进入home目录
第一步:vi src/demo.java
第二部编写代码:
public class demo{
public static void main(String[] args){
    System.out.println("hello demo");
}
}
第三步 将src下的.java代码编译至bin中
    javac -d bin src/demo.java
第四步:运行编译后的.class文件
    java -cp bin demo    (-cp bin 等价于 -classpath 意义是指定编译的class路径,效果和在环境变量中设置classpath的效果一样,java命令只能编译-cp后的路径中的class文件,默认不设置是相对于当前路径。

3.java advantage

(1) simplicity compared to C, C ++ terms, Java no header, pointer arithmetic, like virtual base class

(2) Object-Oriented

(3) networking skills: Java networking capabilities powerful and easy to use

(4) Robustness: Java compiler can detect many problems to be able to be detected in other languages ​​only at run time

(5) Safety: From the beginning, java was designed to be able to guard against all kinds of attacks languages

(6) neutral architecture: java virtual machine to be the most frequent byte code sequence is translated into machine code, this process becomes time compilation

(7) Portability: Java an int is always 32-bit integers, but in C / C ++ in, int type integer might be 32, it could be 16-bit integer.

(8) Explanatory: Java interpreter can be executed on any Java bytecode interpreter transplanted machine.

(9) High performance: bytecode can (at run time) quickly translated into a particular cpu bytecode to run the application.

4. bytecode verifier to verify what

Code and consistent specification jvm

Codes can not compromise the integrity of the system

No stack overflow and underflow

Parameter type is correct

Type conversion right

5.java program editing, compiling, running process

Run a Java program must write, compile, run three steps.

Writing refers to the input of the program code in a Java development environment, eventually forming suffix .java Java source files are named.

Compile refers to bytecode file using the Java compiler source files for error investigation process, the compiler will generate .class suffix, which is not as ultimately generate executable C language.

Operation is the use of Java bytecode interpreter to translate into machine code files, execute and display the results.

Role in the packet 6.java

A) similar functional classes in the same package can be easy to find and use.

2) Since the class with the same name may exist in a different package, the package used to avoid naming conflicts to some extent.

3) In Java, the package is based on a particular access units.

7.GC (garbage collection)

The concept of garbage collection;
what garbage collection:
1) Garbage: useless objects occupy memory space;
2) garbage collection: the process will be useless objects occupy memory space for recycling;
3) Why do garbage collection?
Object creation, take up memory space, in the course of running a program
you want to create an unlimited number of objects, if the object permanently occupy memory, the memory
will soon consume light, leading to subsequent objects can not be created or out of memory
errors. Therefore, measures must be taken timely recovery of those useless objects of
memory, thus ensuring that the memory can be reused.

C ++ and other procedures by the programmer display memory is released, so that it is possible to:
C: the malloc () Free ()
C ++: new new Delete
. 1) forget the release of memory, the inverted induced endless memory footprint;
2) release core library memory for, inverted causes the system to crash;

Java garbage collection process:
1) completed by the JVM virtual machine by a system-level garbage collector thread automatically,
will not forget and will not release wrong, the system more stable;

Features in Java garbage collection process:
1) is done automatically by the virtual machine by the garbage collector thread;
a relatively low priority thread. No way to
control the thread running.
Process: the smallest unit of resource allocation
thread: is the smallest unit running
2) working under what circumstances GC:
A) memory when idle
b) when a serious shortage of memory
3) only when the object is no longer being used, it's only memory It may be recycled;
if the virtual machine believe the system does not require additional memory, even if the object is no longer using the memory
4) program does not explicitly force the garbage collector to perform immediately garbage collection,
by java.lang.System.gc () / java. lang.Runtime.gc ()
recommended that the virtual machine to be recovered;
5) java.lang.System.gc () or java.lang.Runtime.gc ()
are only used to notify the system should handle garbage

java garbage collection algorithm process:
1) mark the cleaning method: clean all the garbage with marker.
Not finishing memory.
Does not move the data, the efficiency of fast
2) Memory lift-off method: non-spam memory a move to another area.
Memory will be finishing
move will be data, slow efficiency

8.Java platform code security implementation strategy

Java Virtual Machine for Java provides a runtime environment,
which is an important task management class,
management class loading, connectivity and initialization;
1) Load: find and load the class of binary files (class file), placing memory.
2) connection:

. a validation: to ensure the correctness of the loaded class (there are proper internal structure, and coordinated with other classes);
why should verify: Java virtual machine does not know that a particular .class file
in the end is a normal Java compiler generation, or hacker special.
Validation class can improve the robustness of the program, to ensure that programs are safely executed.

Class verify the contents:
Code jvm specifications and consistent: grammar and version is compatible
code can not destroy the integrity of the system.
No stack overflow and underflow.
Parameter type is correct.
Type conversion right.

. B Preparation: allocate memory for static class variables and initializes it to the default value;

. c Analysis: the class is converted into a direct reference symbol references (method called a memory location pointer pointing area method);
3) Initialization: static class variables to impart the correct initial value;
time compiler ( JIT compiler, just-in-time compiler)
is the Java bytecodes (including the need to be interpreted program instruction)
is converted into a program instruction can be sent directly to the processor.
8020 rule: 80% of the common functions with only 20% of the common code is frequently used,
Inter companies. This is a specialized area of human completion, after the completion of the installation will be
in the JVM, we use it.

9. The definition of classes, packages and applications

1) Java works:

Source: Write Java source code files
|
Compiler: The compiler source code. The compiler will check for errors, if necessary to correct the wrong in order to produce the correct output.
|
Output: compiler generates bytecode. Any device that supports Java can it translate into executable content. Compiled byte code and platform-independent.
|
The Java Virtual Machine: I can read and execute bytecode. Load the specified class, started its main method, and has been run until the end of all the main program code.

2) Java program structure:

file contains the Java code (written by java syntax rules content);: A source file
characteristics: 1) as a suffix to java;
2) may comprise a plurality of classes / interfaces;
B packet declaration statements (optional. if only one row, and is located in the front);
naming packages: the company's domain name to write down the set of functions
the role of the package:
1) use the file to class level management of
2) can not be in the same package appear the same class name, to avoid naming conflicts.
3) Once in the package name, class name would change.
Package name. ==== class name> Permissions class name
c.import statement (optional, may have multiple rows, followed by the declaration package) ;
declaration d.public class class
1) class: organizational units of the Java code, Java code is organized in a form of a class.
In fact, that is written in the Java programming language one class; a class of language
sentence content with braces, a class with multiple methods to zero.
2) a Java file can have only one public class, you can have multiple class
3) public class modified class name and file name must be the same as
the contents of the statement 4) class, enclosed in curly brackets: properties and methods
e.public void main static (String [] args)
. 1) method: similar to other languages function or procedure.
Methods in with zero up-line statement.
Structure 2) Method:
modifier method return type name (parameter list) {
Method body (business logic code)
}
3) constructs, with braces
4) main methods: Java virtual machine to execute a Java program, the first implementation of the method call.
The method of starting an inlet main method or methods known procedures. No matter how big your program,
no matter how many programs you like, we will have a main () method as a starting point for the program.

f.System.out.println (): Java in the output statement
System is java.lang.System class
out of the internal class System
println () method is
the top three elements of g.Java:
Package Penalty for
Import
class

3) 剖析类:
public class FirstJavaProgram{
public static void main(String[] args) {
System.out.println("Hello Java, I am your fans!");
}
}

    public:             公开给其它类存取;
class:              类声明的关键字;
FirstJavaProgram:       类的名称;
void:               方法的返回值;
main:               方法的名称;
String[]:           数组类型;
args:               参数名称;
System.out.println:     打印到标准输出上(默认为命令行)
"Hello Java, I am your fans!":  要输出的字符串内容;
;               每一行语句必须用分号结尾;

Ten coding, compilation, and the use of Java applications;
1) write: vi class name .java
use Notepad to open the class name .java
2) compile:
javac -d src / class name .java.
-D: Specifies compiled after class file storage path.
Compile-time compiler along with packge
3) run:
. The name of the Java class package name

com is ch01jar cheng jiang da_bao ch01jar com is cvf jar
jar xvf ch01jar

Lastly, I hope to be able to write code proficient in linux! ! !

Guess you like

Origin www.cnblogs.com/sm1128/p/10951442.html