Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Installing Java 
 
The Oracle Technology Network (OTN) web site is probably the best source of 
information for Java: 
 
http://www.oracle.com/technetwork/java/index.html 
 
• Download Java from OTN. 
• Java is installed in Linux and Windows in the Computer Science classroom and lab. 
• The JDK, Java Development Kit, includes the JRE, Java Runtime Environment. 
 
http://www.oracle.com/technetwork/java/javase/downloads/index.html 
 
Windows: (*) jre-8u51-windows-i586.exe   //  32-bit  ~35 MB 
   jre-8u51-windows-x64.exe   //  64-bit  ~41 MB 
jdk-8u51-windows-x64.exe   //  64-bit  ~180 MB 
OS X:  Yosemite, Mavericks, Mountain Lion, Lion 
   http://support.apple.com/downloads/  //  Java 6 App Support 
   jre-8u51-macosx-x64.dmg 
   jdk-8u51-macosx-x64.dmg   //  64-bit  ~222 MB 
Linux:  install OpenJDK packages 
   java-1.8.0-openjdk* 
 
(*) Any standard edition jdk 1.8 update version should work – update 51 current install. 
 
OTN has installation documentation on their web site: 
 
http://www.oracle.com/technetwork/java/javase/index-137561.html 
 
Other useful links: 
 
Java SE Documentation at a Glance 
http://www.oracle.com/technetwork/java/javase/documentation/index.html 
 
The Java Tutorials 
http://docs.oracle.com/javase/tutorial/ 
 
  
Windows Install 
 
The installation instructions described here are for Windows 8.1 Enterprise 64-bit. There 
may be some minor adjustments needed for other versions of Windows. 
 
New system variables must be added in order to use the Java JDK. If the new System 
variable is not added before installation the JRE might not install properly. 
 
• Start 
• Right-click on Computer 
• Select Properties 
• Select “Advanced system settings” 
• Click on “Environment Variables…” 
• Add the following “New…” System variable information: 
o Variable name:  CLASSPATH 
o Variable value:  . 
o Variable name:  JAVA_HOME 
o Variable value:  C:\Program Files\Java\jdk1.8.0_51 (*) 
• “Edit…” the following existing System variable information: 
o Variable name:  Path 
o Variable value:  %JAVA_HOME%\bin;%SystemRoot%\... (*) 
• Click OK three times to accept the path addition and close the dialog boxes. 
 
  
 
(*) It is recommended that the modifications shown (bolded) are used. 
Double-click on the downloaded file:  jre-8u51-windows-i586.exe 
 
Double-click on the downloaded file:  jre-8u51-windows-x64.exe 
 
Double-click on the downloaded file: jdk-8u51-windows-x64.exe 
 
Accept all of the default installation options in both cases. 
 
 
 
(*) This is only needed if installing the 64-bit version of the Java JDK 
• Provides 32-bit support for 32-bit web browsers. 
 
When installation is done the Control Panel will indicate that three new programs have 
been installed: Java 8 Update 51 
   Java 8 Update 51 (64-bit) 
   Java SE Development Kit 8 Update 51 (64-bit) 
 
• Start 
• Control Panel 
• Programs and Features 
 
 
 Confirming the Java Install 
 
Type “java –version” from the command prompt to see the currently installed java 
version. Check the system paths and/or system environment variables if incorrect. 
 
Mac OS X 10.9.5: 
 
 
 
Windows 8.1: 
 
 
 
CentOS 6.6 Linux: 
 
 
Compiling Java Programs 
 
Your Java program source file will have the following naming convention: 
 
 . java 
 
Each Java file has at least one class in it. The name of the primary class is also the name 
of the program file. 
 
Ex: Java program source filename:  MyFirstJavaProgram.java 
 
public class MyFirstJavaProgram  { 
 public static void main ( String [ ] args )  { 
  System.out.println ( “My First Java Program” ); 
 } 
} 
 
Both Java and Linux are case sensitive so make sure that the source program filename 
and the class name are spelled exactly the same. 
  
Java’s portability is achieved by using bytecode and an interpreter. Bytecode is produced 
when a Java program is compiled. 
 
Java Source Program     Java Bytecode 
javac  MyFirstJavaProgram.java   MyFirstJavaProgram.class 
 
Java bytecode then executes under the control of an interpreter designed specifically for 
each type of computing platform. This interpreter is called the Java Virtual Machine 
(JVM). The combination of the bytecode and a JVM means that you can write a Java 
program without knowing what type of computing platform it will be used on. 
 
To run the Java bytecode from the command prompt type 
 
java  MyFirstJavaProgram  //  the .class extension is not needed 
 
Even though Windows is not case sensitive, the JVM will generate an error if you do not 
spell the .class filename with the proper case. 
 
java  myfirstjavaprogram   //  JVM will not execute the program