Java beginners need to pay attention to the problem

Source: Internet
Author: User

1. Why can Java run across platforms?

Programs written in the Java language are both compiled and interpreted. The program code is compiled into an intermediate language of Java bytecode, and the Java Virtual machine, the JVM, interprets and runs the bytecode. Compilation occurs only once, and interpretation occurs every time the program is run.

Java programs run on virtual machines, each platform has a JVM, so Java can "compile once, run everywhere."

2. Please try to install and configure JDK, and give the steps to install and configure the jdk .

The JDK can be downloaded from the Oracle official website, downloaded and installed directly, the installation of a fool click Next, but remember that the installation directory does not have Chinese.

Special note: JDK and Eclipse saved paths cannot have Chinese characters

1. Open My Computer--Properties--advanced--environment variables

2. New system Variable Java_home

Variable name: java_home
Variable value: The directory of the JDK, such as F:\jdk\jdk1.8.0_91_x64

3. Select the environment variable named "Path" in "System variables"

Double-click the variable to add the absolute path of the bin directory in the JDK installation path to the value of the path variable, separating it with the semicolon of the half-width and the existing path.

Variable name: Path
Added variable value:%java_home%\bin;%java_home%\jre\bin;

When the configuration is complete, entering Java in CMD appears as shown, indicating that the environment variable is configured successfully.

This is the Java environment configuration, the configuration is completed directly after the eclipse, it will automatically complete the configuration of the Java environment

3. What is the role of environment variable path and java_home when configuring JDK ?

Java_home environment variables. It points to the JDK's installation directory, and software such as Eclipse/netbeans/tomcat finds and uses the installed JDK by searching for java_home variables.

4. Use the text editor to enter the Hello.java in the classroom and compile and runit in the JDK environment.

 Public class hello{    publicstaticvoid  main (string[] args) {        System.out.println ( "Hello world!" );    }}

5. If you enter in a DOS command:java Hello appears with the following result:bad command or What could be the reason for the file name?

(Bad command or file name) The command entered does not exist or is not in the specified path. Make sure that you have typed the correct command, left a space in the correct location, and used the correct path name.

Cause: The command or file name is wrong and the path is faulted.

This is when I started to learn Java is a mistake, Java Helloworld.class, and then the error. Later only to understand, it should be Java HelloWorld.

6. If you enter in the DOS commandin question 4:java Hello appears with the following result:Exception in thread "main "Java.lang.NoClassDefFoundError:Hello

1), is your file name right? Java requires that your files correspond strictly to your class name.

such as public class helloworld{.....

Then the file name must be Helloworld.java, look carefully!

2), do you have the main method in your program? Parameters or something, right?

The declaration of the main method should look like this:

public static void Main (string[] args)

7, in the first 4 hello.class the path, Enter the command:java hello.class , what will happen, why?

It should be Java Hello Java hello is already a load class, can not add another class.

8. Please describe the difference between the basic data type and the reference data type.

Main differences: Memory usage: The value of the base data type is stored directly in the stack, whereas the reference data type stores the value in heap memory, stores the first address in the stack memory, saves memory, uses the reference data to find the corresponding address from the stack, and finds the value by address.

Assignment of a variable: the base data type assigns the value to the new variable because it is the actual value stored in the stack, and the reference data type has the first address in the stack, so it assigns the first address to the new variable.

9. What kinds of file types are there in Java? What are the respective roles?

1), source code:. java files, writing source codes

2), byte code:. class file, compiled generated file

3), JAR package: The relevant bytecode file after compression formed, easy to use and transfer

Two small programs:

java program, calculate radius is 3.0

 Public class test02circle {    publicstaticvoid  main (string[] args) {          Double  R,zhouchang, Mianji;        R=3.0;        Zhouchang=2*math.pi*R;        Mianji=math.pi*math.pow (R, 2);        System.out.println ("perimeter is:" +Zhouchang);        System.out.println ("area is:" +Mianji);}    }

2. Write a Java Project, define a package, define a class containing the main method under the package, declare variables of 8 basic data types in the main method , and assign values, Practice data type conversions.

 Public classtest03_shujuleixing {//Create Class     Public Static voidMain (string[] args) {//Main Method        byteMyByte = 127;//declaring a byte variable and assigning a value         ShortMyShort = 32564;//declaring a short variable and assigning a value        intMyint = 45784612;//declaring an int type variable and assigning a value        LongMyLong = 456789451;//declaring a long variable and assigning a value        Longresult = Mybyte+myshort+myint+mylong;//Obtain the sum of the numbers for the implicit conversionSystem.out.println (Result); floatMyfloat =1.234f;//declaring a float type variable and assigning a value        DoubleMyDouble = 1.23445;//declaring a double type variable and assigning a value        DoubleRESULT2 = result + Myfloat + mydouble;//get each number for additive implicit conversionSystem.out.println (RESULT2); CharMyChar = ' a ';//declaring a char type variable and assigning a value//Character Set Unicode table A is sorted in Unicode tableSystem.out.println ("A in the Unicode table is" + (int) mychar+ "Bit"); intp = 23456; CharX= (Char) p;//cast int to char typeSystem.out.println ("No. 23456 bit in the Unicode table is:" +x); BooleanBoolean1 =true;//declares a Boolean and assigns only a value of true or false        BooleanBoolean2 =false;    System.out.println (BOOLEAN1); }}

Ps:java Beginners in the new Java will be to these common problems, to understand these issues, Java will have a basic understanding of Java in the future to learn a lot of help.

  

Java beginners need to pay attention to the problem

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.