Many students often feel very confused when they first contact Java. Here we collect and sort out some basic problems that students encounter, hoping to help you on your way to Learn Java.

First article:

1, what is Java, Java2, JDK? What about the 1.3 and 1.4.2 versions behind the JDK?

A: Java is a general-purpose, concurrent, strongly typed, object-oriented programming language (taken from Java Specification Version 2). The JDK is a free Java development tool distributed by Sun corporation, formally known as J2SDK(Java2 Softw are Develop Kit).

2. What is JRE/J2RE?

A: J2RE is the Java Runtime Environment, sometimes abbreviated as JRE.

If all you need to do is run a Java program or Applet, download and install it.

If you want to develop Java software yourself, download the JDK. J2RE is shipped with the JDK.

Note Because Microsoft does not fully support Java, do not use the VIRTUAL machine delivered with Internet Explorer to run applets. You must install a J2RE or JDK

3. What is the best tool for learning Java?

A: It is recommended to start with the JDK+ text editor, which will help you understand the following basic concepts: PATH, CLASspath, package and familiarize yourself with the basic commands: javac and Java. And download API help that matches your JDK version. If you are not sure how to use a class or function, consult the API first instead of Posting help.

Once you are familiar with Java, you can consider switching to an IDE. Many people recommend JCreator, which is actually quite weak. The author recommends Eclipse, download url: O Web links because Eclispe is free.

Also PS: Eclipse for new programmers, use these shortcuts to improve the grid can help you better use Eclipse.

4. What are some good reference books for learning Java?

A: First of all, I recommend Thinking in Java. The Chinese name of Thinking in Java Programming is available in Chinese.

The first chapter of the book introduces many object-oriented programming ideas, which should be read carefully as a beginner.

O ‘Relly and Wrox are also good books. The author himself dislikes books by mainland authors.

Maybe you think English is too difficult, but most of the materials on the Internet are in English. Also, you need to check the API frequently, which is also in English.

Command post.

1. I wrote my first Java program, how should I compile/run it?

A: First of all, please save the program as xxx. Java file, and then use the javac xxx. Java command in DOS window, you will find an xxx.class file in this directory, and then use the Java XXX command, your Java program starts to run.

2. I did what you asked, but what appeared as a “javac” was not an internal or external command, nor was it a runnable program or batch file.

A: You have a path problem. The operating system searches for javac.exe within a certain range (path), but cannot find it.

Please edit your operating system environment variable and add a JAVA_HOME variable as your JDK installation directory.

Edit the Path variable and add an item %JAVA_HOME% /bin.

Then close and open a new DOS window and you can use Javac and Java commands.

3, Javac xxx. Java passed successfully, but what “NoClassDefFoundError” displays when Java XXX?

A: You have a classpath problem. The Java command searches the classpath for the class file you want to use, but fails to find it.

First, make sure you didn’t type Java xxx.class by mistake, and second, check your CLASSPATH environment variable, which you will run into if you set it and don’t contain. Please add an entry to your CLASSPATH environment variable.

See also 8.

4, when I was in the Java XXX according to “the Exception in the thread” main “Java. Lang. NoSuchMethodError: main”.

A: First, there should be only one public class per Java file in your program, and the class name must have exactly the same case as the file name.

Second, there is only one public static void main(String[] args) method in the class you want to run. This method is your main program.

I/O

1. How do I add startup parameters to Java programs like dir /p/w?

Public static void main(String[] args) The args here is your startup parameter.

At runtime you type Java package1.class1 – arg1-arg2 and args will have two strings, one arg1 and the other arg2.

2. How do I enter an int/double/ string from the keyboard?

A: Java I/O is a bit more complicated than C++. To type from the keyboard, the sample code looks like this:

BufferedReader cin = new BufferedReader( new InputStreamReader( System.in));

String s = cin.readLine();

That gives you a string, plus if you need a number:

int n = Integer.parseInt( s ) ; Or double d = double. ParseDouble (s);

How do I output an int/double/ string?

A: At the beginning of the program write:

PrintWriter cout = new PrintWriter( System.out ) ;

Write as needed:

cout.print(n); Or cout. Println (” hello “); And so on.

4. I find it much easier than you to use system. in and system. out input and output in some books.

A: Java uses Unicode, which is double-byte. System.in and system. out are single-byte streams.



Welcome to study and exchange group 569772982, let’s study and exchange together.