Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compile and run Java jdk correctly

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the relevant knowledge of "how to compile and run Java jdk correctly". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to compile and run Java jdk correctly" can help you solve the problem.

Generally speaking, after installing jdk, you must follow one step to configure before you can compile and run correctly.

(assuming jdk version 1.4.0)

1. Install jdk1.4.0- in the root directory of a drive letter on your machine, for example, you can install it under C:jdk.

* (the following c:jdk is changed to the directory where you installed JDK) *

two。 If your running environment is win98, add the following two statements to the autoexec.bat file in the root directory of the C disk:

Set Path=%PATH%;c:jdkbin

Set CLASSPATH=.;c:jdklibdt.jar;c:jdklibtools.jar

After saving, restart the machine, and the installation of jdk1.4 is complete.

3. If your operating environment is win2000, you need to add two user variables to the "Environment variables" of the "Advanced" option under "system" in the Control Panel.

One of the user variables has the name "path" and the value ".; d:j2sdk1.4.0_01bin"

The name of the other user variable is "CLASSPATH" and the value is ".; d" j2sdk1.4.0room01libdt.jar; d "j2sdk1.4.01libtools.jar", click OK. The installation of jdk1.4.0 is complete.

As for the significance of this, I think it should be to make the Java system need something to support when compiling bytecode (.java). If you don't tell it where it is, it will be stupid!

It means a lot to me to see that Hello world is finally displayed on the screen. This is the first program I have written in nearly a year! Once again embark on the road of the program, almost feel like a lifetime ago, almost can not find my position. Fortunately, I didn't forget all the things I learned about C++ and object-oriented, so after getting familiar with the environment of JDK, the following things are much easier and more secure in my heart.

Using the String class to define string variables directly feels much better than the pesky pointers in C, and I, who is used to using object Pascal, will go crazy if I go back to count *.

The definition of the array seems to be slightly different from the definition of the array. I can't remember it clearly. Write it down before you talk about it.

Int [] number=new int [5]

String [] message=new String [5]

That's all I have to say about the variable part. Although I am a rookie, I also know that people who are always stingy in grammar like Tan Haoqiang are idiots: in most cases, beautiful programs do not need unnecessary embellishment, neatness and clear thinking at all.

However, for the framework of Java programs, I would like to remember that a simple java program seems to be such a framework.

Class ProgramName

{

Public static void main (String [] args)

{

The body of the file:// program

}

Public static int othermethod ()

{

Other methods of file://

}

}

The whole program is in a large class, and the concept of this class should be similar to the unit in pascal. Like pascal, the file name is the same as the unit name-in this case, the class name. Java is very strict about case, and that's why I made several grammatical mistakes.

Java programs are made up of one or more or more methods in such a large class.

In the code above, the meaning of the parameter that defines the method is:

Public indicates that this member function is public and can be called directly by other classes

Static indicates that the main member function is unique among all objects of the ProgramName class, and Java will allocate permanent storage space for it

With regard to Static, I would like to extend it a little bit. Sometimes we create a class and want all instances of the class to share a variable, that is, all objects of the class have only one Copy of the instance variable. Then the memory of such a static instance variable cannot be allocated when creating an instance of the class, because everyone uses this one and does not need to be reallocated. So Java allocates permanent storage space for it.

For example:

Class Block {

Static int number=50

}

After this definition, all instances of the Block class, whether Block1 or Block2, access the same number. This number is called a class variable, not an instance variable. In fact, static variables are also called class variables.

(January 17) continue to go deep. Static member functions or static variables defined by Static can be called directly by the name of the class to which they belong. Why is this possible? Because since all objects in this class use this variable, of course I don't need to reference it from any of these objects, just through the class name. Isn't it convenient to implement some global functions and global variables? Define all global functions or global variables in a static class, and when called, you can easily access all global variables and global functions directly through this class name.

(January 20) to define global variables that all programs access, you need to use the

Public final static

In addition, there is a problem that beginners often encounter

Non-static variable mainframe cannot be referenced from a static context

That is, non-static variables cannot be referenced in static methods.

Why?

Because we know that static methods can be used when no instance is created, and member variables declared as non-static are object properties that are referenced only when the object exists, it is naturally illegal for us to call non-static member methods in static methods when the object does not create an instance, so the compiler will give errors at this time.

To put it simply, static methods can be called without creating an object, and non-static methods can only be called with an instance of the object. So it is impossible to reference a non-static method in a static method, because which object's non-static method does it refer to? It is impossible for the compiler to give an answer, because there is no object, so you have to report an error.

Finally, let's take a look at the incisive exposition in Think in Java. I think this question is very clear.

2.6.3 static keyword

Usually, when we create a class, we indicate the appearance and behavior of the objects of that class. You don't actually get anything unless you create an object of that class with new. Only after the new is executed will the data storage space be formally generated and the appropriate methods can be used.

However, in two special cases, the above method is not useful. One situation is that you only want to use one storage area to hold a particular data-- no matter how many objects you want to create, or even no objects at all. Another situation is that we need a special method that is not associated with any objects of this class. That is, even if you don't create an object, you need a method that can be called. To meet these two requirements, the static keyword can be used. Once something is set to static, the data or method will not be associated with any object instance of that class. So even though you've never created an object of that class, you can still call a static method, or access some static data. Before that, for non-static data and methods, we must create an object and use that object to access the data or methods. This is because non-static data and methods must know the specific objects they operate on. Of course, since static methods do not need to create any objects before formal use, they cannot simply call those other members without referring to a named object, thus directly accessing non-static members or methods (because non-static members and methods must be associated with a particular object).

Whoops! It's time to get back to the backbone.

Void indicates that the type of the value returned by the method is empty. If a specific type is returned, the method is actually a function, otherwise it is just a process.

This is the end of the introduction to "how to compile and run Java jdk correctly". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report