00: Java is simple to understand

On Java's Overview

Java is SUN (Stanford University Network), Stanford University Networks) introduced in 1995 a high-level programming language. Java is a programming language for the Internet. With Java technology continues to mature in terms of the web has become the language of choice for developing Web applications. Java is easy to learn, fully object-oriented, safe and reliable, platform-independent programming language.

Three techniques Java architecture


Java features and cross-platform

What is cross-platform? What is the principle?

Written in the Java language applications can run on different platforms. Just on the operating system running java applications, install a Java Virtual Machine (JVM Java Virtual Machine) can be. By the JVM is responsible for running Java programs in the system. Because of JVM, so the same Java program can be executed in three different operating systems. This realization of cross-platform Java programs. Also it has good portability to Java.

Java compared to C ++


1) C / C ++ language are compiled directly into machine code for a particular platform. If you want to cross-platform, you need to use the appropriate compiler to recompile.
2) Java source code (.java) must first be compiled into bytecode files (.class) platform-independent, and then re-interpret the bytecode into machine code file to run. Interpretation is performed by the Java Virtual Machine.
3) bytecode file does not face any specific platform, only for the virtual machine.
4) Java Virtual Machine is a virtual machine can run Java bytecode files. Virtual machines on different platforms are different, but they all offer the same interface.
5) Java language is compiled once, run everywhere characteristics. That .class compiled to run cross-platform, provided that the platform has a corresponding Java virtual machine. But the performance is lower than the C / C ++.
6) Java cross-platform principle does not determine its performance C / C ++ high

Java security


1) Java cancel a powerful but dangerous hands, and replaced by reference. Since the pointer can be moved operation, the pointer can easily point to a memory area, regardless of the area is available, this is dangerous, because it turned out that the memory address may be stored important data or other programs running occupied, and use the pointer also easy to array bounds.
2) garbage collection: the programmer does not need to directly control the memory reclamation, the garbage collector automatically reclaims unused memory in the background. Avoid forget the timely recovery program, resulting in a memory leak. Avoid program error recovery procedures core libraries of memory, causing a system crash.
3) exception handling mechanism: Java exception mechanism depends on the try, catch, finally, throw, throws five keywords.
4) cast: Only in the case of forced conversion rules in order to meet the strong turn succeed.
Underlying security can be explained from the following aspects: Java uses a public key encryption scheme (PKC) during the transfer byte code.
It offers four levels of security protection mechanisms in the operating environment: bytecode verifier - class loader - runtime memory layout - File access restrictions

Configuring the Java environment variable


0) find their jdk installation path, such as: C: \ Program Files \ the Java \ jdk1.8.0_152
1) Right-click the desktop "My Computer" and select "Properties"
2) Select "Advanced System Settings" -> Advanced -> environment variable
3) arranged following
: link
the CLASSPATH
;%% the JAVA_HOME \ lib;%% the JAVA_HOME \ lib \ Dt.jar;%% the JAVA_HOME \ lib \ the tools.jar;.

the JAVA_HOME
C: \ Program Files \ Java \ jdk1.8.0_152 the PATH % JAVA_HOME% \ bin;% JAVA_HOME% \ jre \ bin; 4) testing Java environment is configured successfully (cmd window black test: enter the command to test three: the Java -version the Java javac the Java -version = > Note [input java, javac empathy]






JVM, JDK, JRE three brothers

JVM

JVM is [Java Virtual Machine] (Java Virtual Machine) acronym, it is the core part of the whole java cross-platform, all the java program will first be compiled into .class class file, this file can be in class virtual machine the execution, that class does not directly correspond to the operating system of the machine, but indirectly through the virtual machine operating system to interact with the virtual machine will perform the procedure explained to the local system. JVM is the foundation of the Java platform, it has its own instruction set, and operating in different regions of memory at run time. Abstract JVM by the operating system and CPU architecture is provided a method of code execution of a platform-independent, i.e., independent of the specific implementation, host hardware, the host operating system. JVM main job is to explain their own set of instructions (i.e., byte code) to the CPU instruction set or system calls corresponding to protect users from being malicious harassment. JVM on top of Java source files are not concerned, it concerned only source files generated by the class files (.class files).

JDK

JDK is [Java Development Kit] (java development kit) acronym. Each person will first learn java in the machine is equipped with a JDK, then let's look at the JDK installation directory. In the following six folder directory, a source src library archive, and several other declaration file. Among them, the real work when you run java following four folders: bin, include, lib, jre. Now we can see that such a relationship, JDK includes JRE, and JRE included JVM.

JRE

JRE是[ Java Runtime Environment ](java运行环境)的缩写。光有JVM还不能让class文件执行,因为在解释class的时候JVM需要调用解释所需要的类库lib。在JDK的安装目录里你可以找到jre目录,里面有两个文件夹bin和lib,在这里可以认为bin里的就是jvm,lib中则是jvm工作所需要的类库,而jvm和lib和起来就称为jre。所以,在你写完java程序编译成.class之后,你可以把这个.class文件和jre一起打包发给朋友,这样你的朋友就可以运行你写程序了(jre里有运行.class的java.exe)。JRE是Sun公司发布的一个更大的系统,它里面就有一个JVM。JRE就与具体的CPU结构和操作系统有关,是运行Java程序必不可少的(除非用其他一些编译环境编译成.exe可执行文件……),JRE的地位就象一台PC机一样,我们写好的Win32应用程序需要操作系统帮我们运行,同样的,我们编写的Java程序也必须要JRE才能运行。
bin:最主要的是编译器(javac.exe)
include:java和JVM交互用的头文件
lib:类库 
jre:java运行环境
注意:这里的bin、lib文件夹和jre里的bin、lib是不同的
总的来说JDK是用于java程序的开发,而jre则是只能运行class而没有编译的功能。eclipse、idea等其他IDE有自己的编译器而不是用JDK bin目录中自带的,所以在安装时你会发现他们只要求你选jre路径就ok了。

Hello World



public:java 的权限修饰符,公共的,最高的权限。
class:java的关键字,用于定义类
HelloWorld:类的名字,首字符大写。
public static void main(String[] args):入口方法,main 方法。格式是固定的。程序开始执行的地方。将需要执行的代码 写到 main 方法中。
System.out.println("Hello World!"); 将双引号中的内容(字符串)原样输出到cmd 窗口。还输出了一个换行符。

Guess you like

Origin www.cnblogs.com/cao-yin/p/11456878.html