Java café - the first cup of coffee

xiaoxiao2021-03-05  20

Preface

Preface

On April 2, 2004, Microsoft and SUN suddenly announced that Microsoft with $ 19.5 billion in the cost with sunhrano, with SUN's anti-Torres litigation and patent claims. At the same time, it also reached an agreement with Sun for 10 years, sharing patented technology in each other, and commitment to each other's negotiating with each other.

At the press conference, Sun CEO Scott McNile (SCOTT MCNEAL) also gives Microsoft CEO Steve Ballmer, a Scenery, a peace mark. Although they put out elegant posture, it seems to still inhibit complex mood. Two complaints have been able to sit down and friendly. The reason is very simple: more dangerous joint threats have occurred on the skyline. "Linux and IBM.

Sun is the inventor of Java, but IBM is the biggest beneficiary of Java. It is IBM to seize the head of the application server market; it is the most popular chair of IBM's WebSphere development tools; it is IBM to make their own development tools for Eclipse (eclipse meaningful, sun is not angry Blame); it is the most influential and best developer community in Java technology. Sun has already sits unstable and old seats. In addition, with the excellent lawsuit with the SCO, IBM re-displays the leading throne of the open source movement. The Linux of open source code is gradually stronger, making Sun unable to prevent users from moving from Solaris's copyright UNIX operating system to open source Linux operating systems. Microsoft is also depressed by IBM and Linux. The enemy's enemy is my friend, and simple logic has prompted these two companies that are used to each other. Although the world three points are deployed, for Java technology, it is not an opportunity. According to the contract, Sun has agreed to extend the authorization of the Microsoft Java virtual machine, and the final deadline will be delayed until December 31, 2007. At present, the installation rate of the end user's Java virtual machine is 70% to 80%. It is much lower than the 98% installation rate of the Flash technology of Macromedia. This and Microsoft has repeatedly repeatedly replenished policy on the Java virtual machine. There is no relationship. This cooperation finally made the user and Java developers ated a deputy pill (the individual believes that as long as Java has a stylish, Flash wants to be a standard of enriching client technology.). Second, Microsoft's .NET technology and Java technology have become friendliness, better interactivity, making both parties benefit from this alliance. Finally, Sun and IBM are the strong support of Java technology, follow the blue giants, yes.

How do you sing this Western "Three Kingdoms"? let us wait and see.

Building a Java development environment (1)

In order to taste the first cup of Java coffee, just need:

J2SE SDK, Java 2 Platform Standard Software Development Pack (Java 2 Platform Standard Edition SDK). A text editor, such as the "Notepad" inside the Windows "Attachment".

1.J2se 1.4 SDK

J2SE is the cornerstone of Java technology, just like electricity needs to be used. Write the Java program and require J2SE's SDK. SDK is the abbreviation of Software Development Kit, that is, software development package. You can download J2SE 1.4.2 SDK from http://java.sun.com/j2se/1.4.2/download.html. Note that "J2SE V 1.4.2_04 SDK" should be downloaded (where "1.4.2_04" is the version number, which may change due to changes in time), not "J2SE V 1.4.2_04 JRE" or other. JRE is an abbreviation of Java Runtime Environment, an runtime environment, and installed JRE to run Java programs on Windows, Linux, and Solaris systems, but JRE cannot develop Java. In fact, the SDK contains JRE, so just download SDK. In the Java Cafe, we will talk about Java development technology on Windows, so after accepting the agreement, download about 49.36MB of "Windows Offline Installation, Multi-Language". After downloading, double-click the installer, the process is not different from the installation of the normal application.

Yellow sugar story

J2SE SDK's origin

At the time of installation, we can see that the J2SE installer marks the "1.4.2" version of the version, obviously java 1, why is it called Java 2? Sun has launched Java technology as early as 1995. The earliest development bag is called JDK. JDK 1.0 in 1996 was released in 1997, JDK 1.2 was released in 1998. Considering marketing and self-confidence of yourself, Sun is renamed Java in Java 2, JDK is used to identify Java 2 technology, and the version number is used to identify Java 2 technology, not the SDK version. We use mature J2SE 1.4 technology here, so we use J2SE 1.4 SDK. Other J2EE SDK and J2ME SDK, etc., which are based on enterprise applications and embedded systems, which are based on J2se SDK. This summer, Sun will also launch J2SE 1.5 SDK, which is "Tiger", adding many key features, highlighting and expectation.

After the installer is over, we need to update the environment variable. Although this step can be saved, it is also recommended to avoid the long path prefix when using the Java command. The method is as follows: In Windows, press the WIN BREAK key button to open the System Properties dialog box, select the "Advanced" page, modify the path variable in the system variable, plus the path to the J2SE SDK / BIN directory, the default should be "C: /J2SDK1.4.2_04/bin", pay attention to multiple paths to separate (see Figure 1).

Save and exit after completion. Now open the "Command Prompt" window, just enter a directory, enter the "java -version" command, if you see the result as shown in Figure 2, the description has been set correctly.

Building a Java development environment (2)

2. Notepad

Taste the first cup of coffee and use "Notepad".

Create the first Java application

Confirmation, let us create a "Hello World!" Program.

Yellow sugar story

Why is the programming start from "Hello World!"

The "Hello World!" Program is a computer program that only prints "Hello World!" ("Hello, World!") On the computer screen. The program is usually the first program written by beginners of computer programming languages. It can also be used to determine the language compiler, program development environment, and running environments have been installed. The "Hello World!" Program is the first programming program, which has now become a precious tradition. The program appeared in the "C programming language" book written by Brian Kernighan and Dennis Ritchie. "C Programming Language" is the most authoritative C language textbook, the two authors are the famous C language inventors, nickname "K & R".

Of course, there are many "rebels" in the developers, like "Hello". In any case, "Hello World!" As the first program, never there will be a deferion of the defense.

To create such a program, the specific process is as follows:

(1) Creating a Java source program

Java Source Program generally uses Java as an extension, a text file, written in Java language, can create and edit with any text editor.

(2) Compile the source program into a Java bytecode (Bytecode) file

Java Compiler, "Javac", read your Java source program and translated into a Java virtual machine to understand the collection collection, and save it in the form of a field code. Typically, bytecode files are used as the extension in Class.

(3) Run the bytecode file

The Java interpreter will act as the role of the Java virtual machine. The Java interpreter reads the bytecode, takes out the instruction and translates into the code that the computer can perform, and complete the running process.

It is easy to see why the byte size is cool from Figure 3. You must have heard the slogan of Java technology "once written, run everywhere"? Different in the command set of VC, Delphi and other languages ​​into a specific platform, the Java compiler compiles the Java source program into the target code that is independent of the platform, running, translated by the Java interpreter into different platforms. Post. This is better than the national leader in the international conference, and is translated into different foreign languages ​​by several simultaneous translations, so that "only says it once, everyone understand." Similarly, whether your system is Windows, UNIX, MacOS or use IE browser, as long as Java virtual machine is installed, you can run.

1. Create a Java source program

Open "Notepad" and enter the 6-line source program as shown in Figure 4.

Tip: This program defines an object called HelloWorldApp, and the object has a method called Main, used to print "Hello World!". It is used to it, the Java program takes indentation, that is, according to the module using long short spaces. In this way, it is easy to see that the second line to the fifth line of code is the same thing, describing the main method. Among them, the third and fourth lines have indent, they are the specific implementation of the MAIN method. Use indentation and read it.

Enter "Resource Manager", build a folder named "Javabar" under the C-drive directory (we have used this folder to explain), because this is the second, then establish a name again "CHA 02" subdirectory.

Now return to the "Notepad" program, press the "Save" item of the File menu, enter "HelloWorldapp.java" in the File Name Editing box, and must pay attention to the case .

2. Compile the source program

Open the Command Prompt window, enter "C: / Javabar / Cha 02", enter the "DIR" command, you will see "HelloWorldapp.java".

Compile the Java source program, use the "javac" command:

Javac HelloWorldapp.java If you have not received any prompt, it means that the compilation is correct. Now check out the current directory, you will see two files of HelloWorldapp.java and HelloWorldapp.class. Among them, helloworldapp.class is that cool bytecode file, can be executed on Linux or MacOS.

If you have encountered an error, please check the source code to check the spelling and upperclicity, re-save and compile, I believe soon can I solve it.

3. Run the program

Enter "Java HelloWorldApp" in the Command Board Prompt window, if you run success, then congratulations, you have already hit the first greeting to the Java world!

Just do it

Java can perfect support for multi-language. How to print a Chinese string "Hello, computer enthusiast!" I want to think about it and try it.

Next, let's use the advanced development tools from IBM for Java development, experience what is the Java development of the earth!

转载请注明原文地址:https://www.9cbs.com/read-38476.html

New Post(0)