Memorandum of Rookie Java Java (1)

zhaozj2021-02-16  44

Tuesday, January 14, 2003

Today, I first contacted Java.

Although I have seen some books in the past, but most of them are itchy, I can't get it, I will never say I understand Java. When you get in contact with a new technique, it is the first time, but the different is that the latter will generally begin very sweet, but the ending is very painful, and the former is often very painful, but it is, but it is, but it is simply. It is still to stop. Now I am in this very painful stage, even a simplest HelloWorld can't run, always prompts ExcePion in thread "main" java.lan.noclassdeffounderror. I have to go online to check, go search. Remember Not good, so search quickly and save it, often have no problems.

Generally, after installing JDK, you must press the step configuration to compile the run correctly (assuming the JDK version is 1.4.0) 1. Put JDK1.4.0- Installed in the root directory of a one of your machine, Such as: can be installed under C: / JDK. *** (C: / JDK below) *** 2. If your running environment is Win98, in the root directory of the C drive, add the following two in the autoexec.bat file Statement: SET PATH =% PATH%; C: / JDK / BINSET CLASSPATH = .; c: /jdk/lib/dt.jar; C: /JDK/LIB/Tools.jar Save, restart the machine, The installation of JDK1.4. 3. If your running environment is Win2000, you need to add two user variables to the Environment Variables of the "Advanced" option under "System" of the Control Panel. One of the user variables is "path", the value is ".; D: /J2SDK1.4.0_01/bin", the name of another user variable is "classpath", value ".; D" /j2sdk1.4.0_01 /LIB/dt.jar;d:/J2SDK1.4.0_01/lib/tools.jar ", click OK. That is to complete the installation of JDK1.4.0.

As for this, what is the meaning of this, I want to let the Java system need a stupid support when compiling byte code (.java), if you don't tell it which place in Dongdong is put, it is stupid What ?!

Seeing that Hello World is finally displayed on me. This is the first program I have written in the past year! I will set foot on the path of the program. It is like the feeling of separation, I have already found it. It is good. It is also good to learn some of the C and object-oriented fur, so that the timebook is familiar with the JDK environment, the next thing is better, and the heart is also very much.

The string variables are directly defined by the String class, which feels much better than the pointer typed in c, I feel very good, I am used to Object Pascal, if I go back to * *, I really want to be crazy.

The definitions and C, C of the array seem to be slightly different, and you can't remember, let's write down.

int [] Number = new int [5] string [] message = new string [5]

This part of the variable thinks so much. Although it is a rookie, I also know that people who are always dead in the grammatism of the grammar: In most cases, the beautiful procedures do not need unnecessary embellishments, the work is complete, and the ideas can be clear. In the frame of the Java program, I want to make a note, a simple Java program seems to be such a framework.

Class ProgramName {public static void main (string [] args) {file: // program main body}

Public static int othermethod () {file: // other method}}

The entire program is in a big class, the concept of this class should be almost almost the same as the unit in Pascal. Like Pascal, the file name is also to be named in the name - here is a class name - the same. Java is very strict, I am wrong for the case, I am wrong, because this .java program is made by one or more or a lot A method is composed of such a large class. In the above code, the parameter representation of the definition method represents: public indicates that this member function is public, can be directly called by other classes.

Static means that the MAIN member function is unique in all objects of the ProgramName class, Java will assign permanent storage spaces.

(January 17) About static, I want to extend again. Sometimes we create a class, I hope all instances of this class use a variable, that is, all such class objects have a copy of the instance variable. Then such a static instance variable is not available to the instance of the creation. When you assign it, because everyone used it, it does not need to be reassigned again. Therefore, Java assigns permanently stored space. For example, Class Block {static int number = 50} After this definition, all Block-class instances, whether it is block1, or block2, they all access the same number. This Number called a variable, not instance variables. Actually static Variables are also called class variables.

(January 17) continues to deepen. Use static member functions or static variables defined by Static, you can call them directly through the class name. Why can you do this? Because since all objects of this class are used, then I don't need to go to any object from it to reference it, but it is just a reference to the class name. Isn't it convenient to implement some full-class functions and global variables? All global functions or global variables Define in a static class, you can easily access all global variables and global functions when calling this class name.

(January 20) Define all programs to access global variables to use public final static

In addition, it is often incomplete non-static variable why it is often encountered by beginners. Because we know that the static method can be used when not created an instance, and the state of the non-static member variable is an object property, which is only referenced when the object exists, so we call it in the static method if it is not created in the object. Non-static member methods are naturally illegal, so the compiler will give errors in this time.

Simply, the static method can call it without creating an object. The non-static method must have an object's instance to be called. Therefore, it is impossible to reference the non-static method in the static method, because it is a reference to which object is not What about static methods? The compiler is impossible to give an answer, because there is no object, so it is necessary to report.

Finally, we look at the brilliance in Think in Java, I think it is very very clear about this problem.

2.6.3 Static Keywords typically, we will indicate the appearance and behavior of the object of the class when we create classes. Unless I created one object of that class with NEW, I actually didn't get anything. Data storage is formally generated after NEW, and the corresponding method can be used. However, in two special circumstances, the above method is not available. One situation is just to use a storage area to save a specific data - no matter how many objects to create, even simply do not create objects. Another situation is that we need a special method that does not associate any objects of this class. That is to say, even if the object is not created, a method of calling can be called. To meet these two requirements, STATIC keywords can be used. Once there is something set to static, data or methods, it will not be contacted with any object instances of the class. So although an object that has never created that class, you can still call a static method or access some STITIC data. Before this, for non-Static data and methods, we must create an object and use that object to access data or methods. This is because non-Static data and methods must know the specific objects they operate. Of course, before formal use, because the Static method does not need to create any object, they cannot simply call other members, and do not reference a named object, thereby directly accessing non-Static members or methods (because non-Static members and methods You must associate together with a specific object). WHOOPS! I should go back to the backwards now.

Void represents the type of value returned to empty. If a specific type is returned, the method is actually a function, otherwise it is a process.

I don't know if these things have fallen to teeth. If you want to smash it. And I ask a question, why is the JDK compilation speed so slow?

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

New Post(0)