Java zero-based _day01_ class notes

Note Note: record the lesson the teacher wrote notes (equivalent to copy writing on the blackboard, to strengthen memory), with their own thinking and summary (with a block quote formatting tags), "Learning without thought is labor lost, thought without learning is lazy ", by way of summary learn to think again, to urge their own progress. Because they are zero ground up, trouble is inevitable, should be psychologically prepared to overcome difficulties and move forward. Review from time to time to reflect, and learn new things, to deepen understanding.

1. role change: from now on is a Java Software Engineer

2. What is a software engineer?

   Is the name of one of the posts, usually through "some kind of programming language" to complete the software development

3. What is software?

   You will be seeing is a notebook computer, the computer consists of two parts:

        * Hardware: mouse, keyboard, monitor. Host memory of CPU, memory, hard disk and so on ... (Note: only computer hardware is not working, require software drivers to work)

       * Software: software, including system software and application software

                System Software: Direct interaction of hardware and software, for example: windows7, winxp, win8, win10, Linux operating system

                Application Software: Application software usually runs in the system software, such as: QQ runs on windows operating system. QQ is the application software. win7 is the operating system.

           We usually refer to software development generally refers to the use of computer programming language to complete the "application software" development.

4. Develop software requires a computer programming language, a lot of computer programming languages, such as: C language, C ++, Java, .NET, C #, php. We learn that the main programming language? Java programming language, java series of technology. Complete application development by learning Java technology series.

5.Java Software Engineer: complete the development of application software through the Java programming language.

Install a handy text editor 6. Before learning, installation here is EditPlus3

    * Cancel automatic file backup after installing EditPlus

    * Set the font

    ...

7. As a programmer to master the basic requirements related to the DOS command windows

    Specific been organized into thematic blog: https://blog.csdn.net/CealWang/article/details/104145647

8. Set the file extension on windows operating system

The file extension determines the type of file

As a Java programmer, after ending .java To create a new file, it must ensure that the file extension is .java

Method: Turn on the computer -> Organization -> Folder and Search Options -> View -> Hide extensions for known file types to remove the check mark in front

 

9. Computer History Language Development

  9.1 What is a computer <programming> language?

      Advance human exchange to develop a good set of rules, and sometimes, there is a need for rote grammar, need to ask why. And as long as' observance of the rules of grammar, it can be a good communication between people and computers, communication. This is a computer programming language. There are a variety of computer programming languages, such as: C language, C ++, Java, PHP ...

  9.2 History of computer languages:

      The first-generation languages: machine language

           Written primarily binary code, such as binary 100101010101 directly write to the punch as the representative. Bulky, low fault rate

      Second-generation languages: low-level language

           Mainly in assembly language represented in low-level languages ​​we have been introduced in a number of English words, such as variable assignment using mv

      Third-generation languages: high-level language

           Almost exactly the same human language, even if there is no learning computer programming, you see this code will know what the code is mainly to complete the function. For example: C language, C ++, Java, ....

In short, the direction of development of programming languages ​​are: in the direction of human development more easily understood.

10.Java language development history:

* Java language was born in 1995. Prior to 1995 the company SUN (Sun Microsystems: The company is currently being acquired .Oracle Oracle Oracle: do database) in order to capture intelligent consumer electronics market, sent James Gosling led the team that developed a Oak (oak) language.

* In 1996: JDK1.0 birth

    - What is the JDK Java Development Kit; a tool for doing Java development package must be installed, the kit needs to be downloaded from the official website?. Currently SUN acquisition by Oracle, so Oracle need to download the official website to download. http://www.oracle.com

* Currently the highest JDK version is: Java8 / JDK1.8 / JDK8   

After-school tasks: 1 check up to 2020 version

2. their computers have not installed java

In the DOS window, use the java -version command checked, my computer has a java 1.8.0_91 version installed

* Java includes three large pieces:

     - JavaSE (Java Standard Edition)

     - JavaEE (Java Enterprise Edition)

     - JavaME (Java Micro Edition)

     Which is the foundation JavaSE

Reflection: the first time the corresponding three kinds of java version straightened, had previously been vague impression that there is no distinction too.

He specialized in the java course, to distinguish between different concepts in order to better get started.

11.Java language features [open source, free, cross-platform, object-oriented pure]

* Simplicity:

     In contrast, for example, java no longer support multiple inheritance, C ++ supports multiple inheritance, multiple inheritance is more complicated; C ++ has pointers, Java shielding concept pointer. So Java is relatively simple.

     The underlying Java language is implemented in C ++, not C language.

* Object-Oriented

      Java is a pure object-oriented, more in line with people's mindset, easier to understand.

* Portability

     What is portability? Java programs can be done once, run everywhere. Such as: Java program can run on windows operating system, without any modification, the same can be placed directly on the Linux operating system. This is called portability of Java programs, otherwise known as cross-platform.

    windows operating system and Linux operating system kernel is certainly different, these two operating systems executing instructions are not the same. Obviously, java programs and operating systems can not deal directly, because only a java program, the operating system performs principles are different.

   SUN team is very clever, I thought of a way, they let java program running in a virtual computer in the virtual computer called a Java virtual machine, referred to as the JVM. Java virtual machine and then deal with the underlying operating system.

Here self summarize: Java virtual machine, in order to solve the problem of cross-platform java, java program to achieve portability

Important to understand portability (cross-platform)

* Multithreading

* Robustness

      And automatic garbage collection mechanisms, automatic garbage collection mechanism referred to as GC mechanism. Garbage generated during the operation of the Java language is automatically recycled, programmers do not need to be concerned about. (C ++ language, the programmer allocates a block of space, we must remember that freed a space, or else time will cause a lot of memory leaks, leading to memory overflow, program crashes; Java language, the programmer is responsible only for space applications, no release , Java language will automatically garbage)     

* safety

....

12.Java loading and execution

     * Run Java program consists of two very important stage

          - compilation stage

          - operational phase

   * Compilation phase

          - The main task of compiling stage is to check whether the Java program Java syntax, grammar can be generated in line with normal Java byte code file (xxx.class); does not comply with the rules of grammar can not generate Java byte code file

         - byte code file is not a pure binary file that can not be performed directly in the operating system

        - compilation phase of the process:

              * Programmers need somewhere hard drive <random location> Create a new file with a .java extension, the file is called the source file, the source file is written in Java source code / source. The source could not write freely, must conform to the Java syntax rules <Java syntax rules need to remember>

             * Java programmers need to use JDK comes with javac.exe command to compile Java programs.

                    javac where use? how to use?

                       - Use the DOS command window.                         

                       - javac的使用规则:

                              javac java源文件的路径

                          javac是一个java编译工具/命令。

              * 一个java源文件可以编译生成一个或多个.class文件。【以后再说】

              * 字节码文件/class文件是最终要执行的文件,所以class文件生成之后,删除java源文件并不会影响java程序执行,但是一般不要删除java源程序,因为class文件最终执行效果可能不是我们想要的,这时候需要回头修改java源程序,然后将java源程序重新编译生成新的class文件,然后再运行新的class文件生成新的效果。

              * 编译结束后,可以将class文件拷贝到其他操作系统中运行。【跨平台】

   * 运行阶段 【可以在其他操作系统中运行,跨平台】

          - JDK安装之后,除了自带一个javac.exe,还有另一个工具/命令,叫做java.exe,主要负责运行阶段。

          - java.exe在哪里用?怎么用? 

               - 在DOS窗口中使用

               - java.exe使用规则:

                    java 类名

                    例如:

                           硬盘上有一个A.class,那么就这样用:  java A

                           硬盘上有一个B.class,那么就这样用:  java B

                           硬盘上有一个C.class,那么就这样用:  java C

                           千万要注意:不能写成这样:java A.class【这种方式是错误的,不要带扩展名,要记住】

             - 运行阶段的过程:

                  * 打开DOS命令窗口

                  * 输入  java A

                  * java.exe命令启动Java虚拟机(JVM),JVM会启动类加载器ClassLoader

                  * ClassLoader会去硬盘上搜索A.class文件,找到该文件则将该字节码文件装载到JVM中。

                  * JVM将A.class字节码文件解释成二进制1010101010这样的数据。

                  * 然后操作系统执行二进制和底层硬件平台进行交互。

13.开始第一个Java程序

     * 保证计算机中已经安装了文本编辑器Editplus(我的电脑安装了Notepad++,试试能不能用)

     * 安装JDK【JDK一般需要从Oracle的官网下载】,我们这里讲解的是JDK7

   13.1 JDK、JRE、JVM的关系,搞清楚

       * JDK:Java开发工具包,Java开发人员一定要安装

       * JRE:Java Runtime Environment,Java运行时环境,Java程序开发完之后,只要有一个运行环境就可以运行Java程序。

       * JVM:Java虚拟机,Java程序最终运行在JVM上的,JRE包括Java虚拟机(JVM)的。JVM没有单独的安装软件。

       * JDK和JRE都有单独的安装软件,一般JDK都会自带一个JRE。如果不在这台电脑上做Java开发,仅仅是需要运行Java程序,不需要安装JDK,只安装JRE就可以,JRE的体积比较小。比如在客户的机器上运行程序,只需安装JRE,而JRE中包含了JVM。三者的关系可以用下图表示。

  13.2 JDK目录介绍:

         JDK/bin:该目录下存放了很多命令,例如javac.exe和java.exe。javac.exe负责编译,java.exe负责运行

   13.3 开发HelloWorld.java源程序【照抄,不要问为什么,注意大小写】

   13.4 将HelloWorld.java源程序通过javac工具进行编译:

          - 首先需要解决的问题是:javac命令是否可用

          - 打开DOS命令窗口,直接输入javac,然后回车,出现报错:

                    'javac'不是内部或外部命令,也不是可运行的程序或批处理文件。             

              以上问题是因为:windows操作系统无法找到javac命令文件

          - 怎么解决以上javac不可用的问题?

              - windows操作系统是如何搜索硬盘上某个命令的呢?

                  * 首先从当前目录下搜索

                  * 当前目录搜不到的话,会从环境变量path指定的路径中搜索某个命令

                  * 如果都搜索不到,则报以上错误。

              - 配置环境变量path

                  * 注意:path环境变量和java语言没有关系,path环境变量是属于windows操作系统的一个知识点,是专门给windows操作系统指路的。

                  * java要想能随意使用,需要将javac所在的目录配置到环境变量path中,用法:path=xxxx;D:\programs\Java\jdk1.8.0_91\bin    路径之间要用分号隔开,必须是英文分号“;”。

                  * 修改环境变量后,一定要先退出DOS窗口,用exit命令退出,再重新打开一个

                        - 环境变量修改说明,如下图,环境变量有两个部分,:

                                         

        - javac命令怎么用?

               javac java源文件路径

              注意:路径包括绝对路径和相对路径两种方式

              * 绝对路径方式:1.开始-运行-cmd,打开DOS命令窗口   

                                          2.输入javac 再直接把java源文件拖拽到javac后面,会直接显示java源文件所在的绝对路径 

                                          3.回车

                          没有报错的话,会在java源文件所在目录下生成一个.class文件,编译成功了。 

    编译时,我的程序出现了一个报错,"String"的"S"没有大写。注意java是大小写敏感的,编译过程如下图:               

                               

              * 相对路径方式:

                           1.打开java源程序所在的文件,在目录栏输入cmd,打开DOS命令窗口,在源文件所在的目录操作DOS命令

                           2.输入dir,回车,查看当前目录下的文件,确定路径是对的

                           3.输入del *class,删除HelloWorld.class文件

                           4.直接输入javac HelloWorld.java

                           5.回车,生成class文件,编译成功

收获:1.步骤1打开DOS命令窗口的方式,将DOS窗口中的目录切换到源文件所在目录下,比较便捷,不用依次切换盘符;2.记得用dir检查目录是否正确;3.学到了DOS命令的删除命令del

            

                13.5运行java程序:

                      - 需要使用java.exe命令

                      - 首先测试java命令是否可用

                      - 使用方式:java 类名

                             硬盘上有HelloWorld.class,那么类名就是:HelloWorld

                             java HelloWorld

                             一定要注意:java命令后面跟的不是文件路径,是一个类的名字。

                       - 首先你需要将DOS窗口中的目录切换到HelloWorld.class文件所在目录。dir确定当前目录下真的有HelloWorld.class文件。

                       - 然后直接执行:java HelloWorld       敲回车,效果就是输出 Hello World! 运行结束。效果如下:

                

        

发布了13 篇原创文章 · 获赞 0 · 访问量 627

Guess you like

Origin blog.csdn.net/CealWang/article/details/104236919