Java self-study note (first day) install Java8 --- configure the runtime environment --- write & quot; hello world & quot; program --- Note, java8 --- hello

Source: Internet
Author: User

Java self-study note (first day) install Java8 --- configure the runtime environment --- compile the "hello world" program --- Note, java8 --- hello

(1) What are jvm, jre, and jdk:

Jvm: Java Virtual Machine (Java Virtual Machine)

Jre: java runtime environment, which is the runtime environment of java programs.

Jdk: JDK (Java Development Kit) is a Java software Development Kit.

Jdk contains jre, and jre contains jvm

(2) download and install JDK 8:

Run the javac.exe file in the bincatalog under the JDK directory with a command prompt.

No javac.exe file exists in the BINLOG under the jredirectory.

During windows XP installation, Java 8 reports the [cannot locate the program Input Point RegDeleteKeyExA on the Dynamic Link Library ADVAPI32.dll. ] Error.

Solution: unzip the extracted tools.zip package to the current directory through 7-zip again to obtain the jdk file. Open the lib directory and you will find the previous tools. jar is changed to tools. pack and rt in jre/lib. jar is changed to rt. pack, so we need to return it back to our familiar form. bin/unpack200.exe under jdk is the conversion tool. We only need to call the tool in the command line to execute the conversion. d: \ jdk8> FOR/R % f IN (*. pack) DO "d: \ jdk8 \ bin \ unpack200.exe"-r-v "% f" % ~ Pf % ~ Nf. jar "and the conversion is complete. (Solution from Baidu)

(3) configure the environment for running java in the operating system:

My computer-properties-advanced-environment variables-Add the Java installation directory (D: \ jdk \ bin) to the system variable path, or create a java_home system variable, set the value to the java installation directory D: \ jdk. In the path system variable, dynamically obtain the value (% java_home % \ bin) in java_home)

Configure temporary environment variables: Use the set command in the cmd command line, set java_home = d: \ jdk

Temporary environment variables are only useful in the current window using set cmd and the new window opened in this window (using the start command). % xxx % dynamically obtains the value in system variable xxx

 

(4) *. java file (Java code) (Human Programming Language) -----> Use bin \ javac.exe to compile --------> *. class file (File running on java VM) (machine language)

Bin \ java.exe run the *. class file. Check the file directory and file name carefully if any errors occur.

(5) error: the package system does not exist ----> java classes start with uppercase letters.

(6) class: it is a keyword in Java. It is used to define classes. Java program code must be defined in the class.

Keywords: words with special meanings granted by Java

(7) configure the classpath system variable: the purpose of setting the Classpath is to tell the Java execution environment in which directories the classes or packages required for the Java program to be executed can be found (. class files).The priority is higher than the directory where *. class files are located.

Set classpath = d: \ and set classpath = d: \; the difference is that the last semicolon (;) indicates that the current directory is searched for first by looking for the specified directory, and the current directory is not searched for only the specified directory.

Specify multi-directory set classpath =.; d: \; c :\

(88.0 system variable pathpattern refers to the .exe File

Specify the. class file in the classpath path of the system variable.

After you configure system variables, You can execute them in any directory in cmd.

(9) command line can execute all. EXE files ------ (desktop shortcut parameter value setting)

(10) when defining a class name, the first letter of each word must be capitalized,

(11) public static void main (String [] args) {} When javac.exe is used to compile the error code (for example, mian), no error is reported, but an error is returned when java.exe is executed again.

(12) Tools -- Folder Options -- View -- hide extensions of known file types

(13) javac compilation is case insensitive to. java file names

Differentiate the case sensitivity of. class file names during java Runtime

(14) // single line comment

/**/Multi-line comment cannot be applied

/***/Document comment

 

Annotation format 1. requirement 2. Train of Thought 3. Step

(15) editplus blue is keyword red is Class


How to Write hello world?

The following shows how to run java configuration for the first time on my computer:
Set C: \ software \ j2sdk1.4.2 in the environment variable JAVA_HOME;
Add C: \ software \ j2sdk1.4.2 \ bin to the environment variable PATH;
Create the java file HelloWorld in the C: \ exercise folder. java (note: the file extension must be changed. java, in the folder tool-Folder Options-hide the file extension before the check box to see the complete file name), in HelloWorld. enter the following code in java:

Public class HelloWorld {
Public static void main (String [] args ){
System. out. println ("Hello World! ");
}
}

Click Start-run-CMD
Enter c: Press ENTER cd exercise and press ENTER
Javac HelloWorld. java press ENTER
Java HelloWorld press ENTER
OK! In the window, HelloWorld is displayed.

Who writes a JAVA program and each step has at least 10 lines of comments?

There will be no pulling in ten rows ..
I don't know what you want to ask ..
Let's show you a helloworld ..
Appendix: HelloWorld. java

// HelloWorld. java
Public class HelloWorld {
Public static void main (String args []) {
System. out. println ("Hello World! ")
}

* Error 1:

'Javac' is not an internal or external command, or a program or batch file that can be run.
(Javac: Command not found)

The cause is that the environment variable path is not set. In Win98. in bat, add path = % path %; c: \ jdk1.2 \ bin. in Win2000, choose Control Panel> system> advanced> environment variable> system variable... see? Double-click Path and add c: \ jdk1.2 \ bin to it. Of course, let's assume that JDK is installed in the c: \ jdk1.2 directory (a little monk ?)... It seems that you have to restart the system to make it work... (// you know! // Tomato) Good, try again! Javac HelloWorld.

* Error 2:

HelloWorld is an invalid option or argument.

Please give us some professionalism. The java source program must be saved as a. java file, and must be fully written during compilation. java.
OK, javac HelloWorld. java (should this always happen ?)

* Error 3:

HelloWorld. java: 1: Public class helloworld must be defined in a file called
"HelloWorld. java ".
Public class helloworld {
^
This is because the name of your class is different from that of the file. (Who said it, it clearly shows that people have such () OK. To be precise, a Java source program can define multiple classes. However, only one class with the public attribute can be created and must be consistent with the file name. Also, the main method must be placed in this public class so that java (run) can be used. In addition, the Java language is case-sensitive and must be noted for beginners. As in the above example, helloworld and HelloWorld are considered different, so... oh... okay, you have changed it... javac HelloWorld. java... (Sorry, why is there nothing ?) // Faint. This is the compilation passed! Check if there is another HelloWorld. class? (Hehe .. according to the instructions in the book :) java HelloWorld (!! I know this, not java HelloWorld. class yo)

* Error 4:

Exception in thread "main" java. lang. NoClassDefFoundError: HelloWorld

Well, this is the famous classpath problem. In fact, the class path is a concept in Java involved in the compilation process. Classpath is the class used to specify where to find it, which is so simple. Because our HelloWorld does not use other (non-java. lang Package) classes, this problem is not encountered during compilation. During running, you must specify where your class is. To solve this problem, you can use the following command... the remaining full text>

Related Article

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.