Java language Programming (i)-2

Source: Internet
Author: User

(i) JDK installation and environment variable configuration

1. JDK Download

http://www.oracle.com/technetwork/java/javase/downloads/ index.html, download the SE Standard Enterprise version, has been updated to 1.8.X version, but the latest version does not support XP system, has been verified (unable to install on the XP system), so select version 1.7.

2. Environment variable Configuration

Configure path and classpath, My Computer, properties---Advanced environment variables, add the Java installation path to the user variable, add the bin path in path, and add the Lib path in the classpath. After configuration, you can enter the DOS test is configured intact. The commands are as follows: Java-version and Javac-version

(ii) Java programs

1, use Notepad to build a Test.java file, the contents are as follows:

Class example1_1{
public static void Main (String [] args) {
int A, B;
a=100;
System.out.println (a);
System.out.println ("hello,java!");
}
}

2, compile, command as follows: Javac Test.java

After executing this command, a Example1_1.class file is generated in the current directory.

3, run, command as follows: Java example1_1

Note: The Java +[class name], if entered into Java Example1_1.class, will prompt the error "error: Cannot find or Load main class Example1_1.class"

(iii) Java applets

1, the preparation of Example1_2.java file, the contents are as follows:

Import Java.awt.*;import java.applet.*;
public class Example1_2 extends applet{
public void Paint (Graphics g) {
G.setcolor (Color.Blue);
g.DrawString ("Welcome You", 30,20);
G.setcolor (color.red);
g.DrawString ("No thing", 30,50);
}
}

2, the preparation of example1_2.html file, the contents are as follows:

<title> First applet</title>

<body>
<applet code= "Example1_2.class" width= "height=" >
</applet>
</body>

3. Compile Java file, javac Example1_2.java generate file Example1_2.class

4. Running Java applet: Appletviewer example1_2.html

In the beginning of Java, the Web is suggested to write with Notepad, and I still feel that with a good code editor is better, at least can be highlighted and aligned. More irritable often need to use DOS command to enter the working directory, can: run->cmd directly into the directory where the code is, in fact, it is OK: My Computer--right---management--Local Users and groups, user--- Adminstrator-> Double-click Profile, add working directory to local path.

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.