1 What is Java, Java2, JDK? JDK's 1.3, 1.4.2 version number is what is going on? A: Java is a common, concurrency, strong type, object-oriented programming language (from Java specifications) Second Edition) JDK is the free Java development tool distributed by Sun, formally named J2SDK (Java2 Software Develop Kit). 2 What is JRE / J2RE? A: J2RE is Java2 Runtime Environment, the Java running environment, sometimes referred to as JRE. If you just need to run the Java program or Applet, download and install it. If you want to develop Java software yourself, please download JDK. It comes with J2RE in JDK. Note Because Microsoft's support for Java is not fully supported, do not use the IE's own virtual machine to run the applet, be sure to install a J2RE or JDK. 3 What tools do you use to learn Java? A: Author's recommendation first use JDK text editor, which helps you understand the following basic concepts: Path, ClassPath, Package and familiarize with basic commands: Javac and Java. And download the API help with your JDK version. If you are not sure the use of classes or functions, please check the API instead of sending help. When you are familiar with Java, you can consider for an IDE. Many people recommend jcreator, actually the function of JCREATOR is still very weak. Author recommends Eclipse, download URL http://www.eclipse.org. Because Eclispe is free. 4 What kind of reference books have been learned from Java? A: The author first recommends Thinking in Java, Chinese name "Java Programming Thoughts", there is Chinese version. The first chapter introduces many object-oriented programming ideas, and as a novice should read it carefully. In addition, the book of O'relly Press and Wrox Press is also good. The author does not like the book of mainland author. Maybe you think English is too difficult, but most of the online information is in English. In addition, you need to review the API often, and that is English. 5 Java and C which better? A: This problem is a very inappropriate question. You should ask: Which of Java and C is more suitable for my project? If you don't need cross-platform, you don't need distribution, you want to emphasize the running speed of the program, C more applicable. Converse? You should consider Java. 6 What is J2SE / J2EE / J2ME? A: J2SE is a general Java. J2ME is for embedded devices, such as Java phones, which have their own SDK. J2EE uses J2SE's SDK. The J2EE specification is more about the requirements of the J2EE server and the constraints of developers. See the "J2EE FAQ" for details. Second, the order 7 I wrote the first Java program, how should I compile / run? A: First, save the program as a xxx.java file, then use the javac xxx.java command under the DOS window, you will find the directory. There is a xxx.class file, use the java xxx command, and your Java program starts running. 8 I did what you said, but what "'Javac' is not internal or external command, nor is the running program or batch file.". A: You have encountered path problems. The operating system searches for JavaC.exe in a certain range (PATH), but it isso known. Edit your operating system environment variable, add a java_home variable, set it to your JDK installation directory, edit the PATH variable, plus a% java_home% / bin. Then turn off and open a DOS window, you can use Javac and Java commands.
9 How to set up environment variables? A: Please consult with people who will be around. 10 Javac xxx.java passed, but what "Noclassdeffounderror" is displayed when Java XXX? Br> A: You have encountered a ClassPath problem. The java command searches for the class file you want to use in a certain range (ClassPath), but it failed to find. First, please confirm that you have not missed Java XXX.CLASS, followed by checking your classpath environment variable, if you set this variable, it is not included. (Represents the current directory)? Br> Rui? Br> You will encounter this problem. Please join an item in your ClassPath environment variable. See 15. 11 I show "Exception in Thread" main "java.lang.nosuchmethoderror: main" in Java XXX. A: First, every Java file in your program can only have a public class, this class name must be exactly the same as the case case. Second, in the class you want to run, there can be only a public static void main (String [] args) method, this method is your main program. 12 package mean? How to use? A: In order to uniquely identify each class and group, Java uses the concept of package. Each class has a full name, such as the full name of String is java.lang.string, where java.lang is the name, String is a short name. This way, if you also define String, you can place it in MyPackage, distinguish between two classes by using full name mypackage.string and java.lang.swing. At the same time, the logically related class is placed in the same package, which makes the program structure more clearly. What you have to do is adding a line of "package mypackage;" on the Java file. Note that the package is not nested or contains relationships, a packet and A.b package two packages in parallel to the Java command. 13 I didn't declare any package? A: Your class is considered to be placed in the default package. At this time, full name and short name are consistent. 14 How to use other classes in a class? A: If you use the class in the java.lang package, you don't have to do anything. If you use other classes in other packages, use import package1.class1; or import package2. *; Here. * Indicates all classes introduced in this package. Then you can use a short name for other classes in the program. If the short name has a conflict, use a full name to distinguish. 15 I used Package to display "NoclassDefounderror", but I can run when all Package is removed. A: Store your Java file by package. For example, your work directory is / Work, your class is package1.class1, then store it as /work/package1/class1.java. If there is no declaration package, then put it directly under / Work. Execute Java Package1 / Class1.java under / Work, then perform Java package1.class1, you will find everything is normal. Also, you can consider starting using IDE. 16 I want to compile Java into an exe file, what should I do? A: JDK can only compile the Java source file into a Class file. The Class file is a cross-platform bytecode that must be run on the platform-related JRE. Java uses this to achieve cross-platform. Some development tools can compile Java files as an EXE file. The author against this approach because this cancels cross-platform.
If you are sure that your software is only running on the Windows platform, you can consider using C / C # to program. 17 I encountered what "Deprecated API" when I compiled, what does it mean? A: The so-called deprecated means that it is already? When it is still compatible with the way, the method is still reserved ?? Br> These methods may cancel support later . You should use a newer method. Generally speaking in the API will show what method you should use to replace it. Third, I / O article 18 How do I add the parameters to the Java program, just like DIR / P / W? A: Remember public static void main (String [] args)? ARGS here is your startup parameters. When you run, you enter java package1.class1 -arg1 -ar2, there will be two string in Args, one is Arg1, the other is Arg2. 19 How do I entered an int / double / string from the keyboard? A: Java I / O operation is more complicated than C . If you want to enter from the keyboard, the sample code is as follows: BufferedReader cin = new bufferedreader (NEW INPUTSTREADER (system.in)); string s = cin.readline (); so you get a string, if you need a number, Plus: int n = integer.parseint (s); or double d = double.parsedouble (s); 20 how do I output an int / double / string? A: In the program started: PrintWriter Cout = New PrintWriter (System " .out; need to write: cout.print (n); or cout.println ("Hello"), etc. 21 I found some books to enter and output directly with System.IN and System.out, much more simple than you. A: Java uses Unicode, is a double byte. System.in and System.out are single-byte stream. If you want to enter the output double-byte text, such as Chinese, please use the author's approach. 22 How do I enter an int / double / string from the file? A: Similar to the input from the keyboard, only replace it into bufferedreader fin = new bufferedreader (New FileReader ("MyFileName")); PrintWriter Fout = New PrintWriter (New FileWriter "MyFileName")); if you haven't downloaded the API yet, start downloading and reading the content in the java.io package. 23 I want to read and write the designated position of the file. What should I do? A: You definitely not seriously see the API. Java.io.randomaccessFile can meet your needs. 24 How to judge that the file to be read has to be at the end? A: You definitely don't care about the API. In the REAER's READ method, it is clear that the return -1 indicates the end of the stream. Fourth, keyword 25 Java how to define macro? A: Java does not support macro because the macro change cannot guarantee type security. If you need to define constants, you can define it as a STATIC Final member of a class. See 26 and 30. 26 Java can not use const. A: You can use Final keywords. For example, Final INT M = 9. Variables that are declared for Final cannot be assigned again. Final can also be used to declare methods or classes, which are declared for Final or classes cannot be inherited. Note that Const is the reserved word of Java for expansion. 27 Java can also use goto.