Although the former sometimes also read some books, but many are nowhere near, not seats, never dare to say they understand Java. Contact with a new technology and first love like, is the first time, but the difference is that the latter generally began to be very sweet, the outcome is very painful, and the former often began very painful, more to later but the more interesting, I can't stop. Now I am in this very painful phase, even a simplest helloworld can not run out, always prompt excepion in thread "main" java.lan.NoClassDefFoundError. Had to go online to check, to search. Memory is not good, so search out quickly save, standing without suffering.
In general, after installing the JDK, be sure to follow the steps to configure it to run correctly (assuming the JDK version is 1.4.0).
1. Install the jdk1.4.0-in the root of one of its own machines, such as: can be installed under C:\JDK.
(The following C:\JDK changed to the directory where you installed your own JDK) * * *
2. If your operating environment is Win98, then in the C-packing directory, Autoexec.bat file, add the following two statements:
Set Path=%path%;c:\jdk\bin
Set classpath=.; After the C:\jdk\lib\dt.jar;c:\jdk\lib\tools.jar is saved, reboot the machine and complete the jdk1.4 installation.
3. If your operating environment is Win2000, you need to add two user variables in the environment variable of the advanced option under System in Control Panel.
The name of one of the user variables is "path" and the value is ".; D:\j2sdk1.4.0_01\bin ", the name of another user variable is" CLASSPATH "and the value is".; D "\j2sdk1.4.0_01\lib\dt.jar;d:\j2sdk1.4.0_01\lib\tools.jar", click "OK". That completes the installation of the jdk1.4.0.
And what's the point of doing this, I think, is to let the Java system need a bit of support when compiling the byte code (. java), and if you don't tell it where it is, it's stupid?!
It really means a lot to me to see Hello World on the screen. This is the first program I've written in nearly a year! Once again on the path of the program, there is Huangrugeshi feeling, has been quick to find my position. Fortunately, some of the original learning about C + + and object-oriented fur did not forget the light, so the trouble familiar with the JDK environment, the next thing to do a lot more, in the mind also more practical.
To define a string variable directly with the string class is much better than the nasty pointers in C, I'm used to the object Pascal, if I go back to count *, I'll be crazy.
The definition of the array and the c,c++ seem slightly different, don't remember clearly, write it down first.
This part of the variable is so much to be accounted for. Although it is a rookie, but I also know, always like Tan Haoqiang in the grammar above the death of people are simply idiots: most of the time, beautiful procedures do not need unnecessary embellishment, gonggongzhengzheng, clear ideas on it.
But 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 ()
{
file&://Other methods
}
}
The entire program in a large class, the concept of this class should be similar to the unit inside Pascal. Like Pascal, the file name also needs to be the same as the cell name--here is the class name. Java is very strict with the case, I have the syntax wrong several times because of this.
A Java program is composed of one or more or many methods in such a large class.
In the code as above, the definition of the method's parameters means, respectively:
Public means that this member function is publicly owned and can be directly invoked by other classes to indicate that the main member function is unique in all objects of the ProgramName class, and that Java will allocate permanent storage space for it
I'd like to extend the static. Sometimes we create a class, and we want all instances of this class to have a common variable, that is to say, All objects of this class have only one copy of the instance variable. Then the memory of such a static instance variable cannot be allocated when the instance of the class is created, because everyone is using one and does not need to be reassigned. Therefore, Java allocates permanent storage space for it.
Like what:
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.
Continue to drill down: static member functions or static variables defined with static can be invoked directly by the name of the class to which it belongs. Why is that so? Since all objects of this class are used as this variable, then of course I don't need to refer to it from any of these objects, It's just a reference to a class name. Isn't it easy to implement some global functions and global variables? All global functions or global variables are defined in a static class, and it is easy to access all global variables and global functions directly through the class name when invoked.
Global variables that define all programs to access need to use
Public final static
In addition to encounter a beginner often encounter problems
Non-static variable mainframe cannot be referenced to a static context
That is, non-static variables cannot be referenced in static methods
Why?
Because we know that a static method can be used without creating an instance. A member variable declared to be Non-static is an object property that is referenced only when an object exists, so it is illegal to call Non-static member methods in a static method when an object is not created, so the compiler will give each error at this time.
In short, a static method can be invoked without creating an object, and a non-static method must have an instance of the object in order to be invoked. So it is impossible to refer to a non-static method in a static method because it refers to which object's Non-static method? The compiler could not give an answer, because there is no object ah, so to error.
Finally, let's take a look at the incisive elaboration in the thought in Java, which I think is very, very clear.
Static keyword
Typically, when we create a class, we point out the appearance and behavior of the object of that class. You don't actually get anything unless you create an object of that class with new. Only when new is executed will the data storage space be formally generated, and the appropriate method can be used.
But in two special situations, the above methods are not available. One scenario is to use only one storage area to hold a particular data--no matter how many objects are created, or even the object is not created at all. Another scenario is that we need a special method that is not associated with any object of this class. That is, even if you do not create an object, you need a method that can be invoked. To meet both of these requirements, you can use the static (static) keyword. Once something is set to static, the data or method is not associated with any object instance of that class. So even though you never create an object of that class, you can still invoke a static method, or access some static data. Before that, for non static data and methods, we had to 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, before formal use, because the static method does not need to create any objects, they cannot simply invoke the other members without referencing a named object. Direct access to a non-static member or method (because a non-static member and method must be associated with a particular object).
whoops! We should get back to the trunk now.
void represents a null type for the value returned by the method. If a particular type is returned, the method is actually a function, otherwise it is a process.
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