Java version Hello World Raiders

zhaozj2021-02-08  223

Java version of Hello World full Raise Hou Guangmin

Seeing the BBS of many technologies flooding the Java beginners about the help information of run the first Java program, I think it is necessary to write this article as a "coming", because they are all very low. The problem, but let these problems occupy so many valuable space on the BBS. To make a clear basic concept Java is a cross-platform network language, in order to be able to run on different platforms, it uses virtual machines. The file with the suffix Java is the source code file, which is generated after compiling is the class file. The virtual machine executes these Class files, which transform them into commands that can run different platforms. This is why Java is less efficient. This is also because of this reason, the concept of user familiar with the user who is not familiar with other languages ​​in Java. Method to perform Hello World remember: Enter the Java Source file name. Java (compiled) Java source file name (execution, no suffix) is here to say is Java Application, including the main function. If hello world is an Applet version, enter the AppletViewer source file name in the command line (have been compiled) If the Class file is embedded in the HTML page, you will use IE to open it.

Application often errors

The system prompts Exception in Thread "Main" java.lang.noclassdeffounderror. The reasons for this tips may be: 1 You put the file names, Java is sensitive to case. Of course, I can't find a file. 2 The virtual machine did not find a must-have class library. You may not set ClassPath in the autoexec.bat file. Go to Windows run, enter SYSEDIT, then add such a line in the autoexec.bat file: set classpath = your JDK installation directory / lib; such as set classpath = c: /jdk1.3.0_02/lib; save exit, you To perform an autoexec.bat file in a DOS window's Calid, it is guaranteed, of course, if you are willing to restart the machine.

System prompt helloworld.java: 1: public class helloworld Must Be defined in a file called "HelloWorld.java". Public class helloworld {^ One Java source can define multiple classes, however, classes with public attributes can only have One, and it is consistent with the file name. Also, the main method must put this class in this public class so that you can run this class.

The system prompts Exception in thread "main" java.lang.nosuchmethoderror: main appears this exception is because you have a mistake when you have code on the copy. The main function must be written like this: public static void main (string args []) one word can not be wrong, remember! ! !

Applet often occurs errors

IE shows a gray area, but there is no Hello World, the status bar is displayed on the status bar: Calss your class file name no found. This problem occurs because IE did not find Applet (a little nonsense), you should put the class file in the same directory as the HTML file. If the Class file is written in the subdirectory of the folder, then write this code = "sub-directory name. File name .class". IE Displays the applet already started, but only one piece of gray is displayed. This problem is the most prone to integrated development tools using JBuilder, and there is no problem with appletViewer. This is because you use the Java version that IE doesn't support in Applet. JBuilder is making Applets using Swing components by default, but IE only supports JDK1.1, so this is caused. Just remove the introduced Swing statement, follow the prompts to modify the code, do not use the Swing component. If you think the Swing component is very beautiful, you have to use it, then you will install a Java's Plug-in this thing is automatically installed when you install JDK high. See if there is a small thing in the red nose in your control. But remember, if you want to use it, then your HTML's file is not the same, you can't specify classes with Code. As for how to write, it is not within the discussion of this article (you have to write a Hello World to use Plug-in.). There are many articles on the Internet to say how to write. How to implement the else file that is used to clicking on the executable Exe file is naturally not used to opening the DOS window to enter the command line, you can make it a JAR file, but it is a bit trouble for Hello World, there is a simple stupid. Method: Do a batch file yourself. For example: Write a run.txt file with Notepad, the content is: Java your main file name, then change the suffix to BAT save to the same directory as the main file. Oh, I'm running, I am stupid enough. If you don't have to run with an Exe file, the JET and other tools can make the class file into the exe file. But this also lost Java's cross-platform sex.

The above is the Raiders of Hello World, if you can't see "Hello World", I fell! You still don't learn Java. Hou Guangmin Wearebug@etang.com

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

New Post(0)