Java is a successful new generation of programming languages by Sun, its biggest feature is: the use of it can be in a variety of different machines, different operating platforms of the network environment software development, with portability, high security, simple, and architecture-independent, dynamic implementation, such as a series of characteristics, Java is gradually becoming the primary development language for Internet applications.
Today we're going to talk about the concept of objects in the Java language
Everything is the object of everything:
Java in the programming language design, thoroughly assume that the user only in object-oriented mode for programming, in Java, there is a very important concept: Everything is object, even if the Java program itself, is an object.
1. Reference of Manipulated objects:
The relationship between reference and objects, like TV and remote, you can have a referenc, but not necessarily connect to an object if you want to produce a string reference:
Example: string s;
That way you have a reference, but not a real object, at which point you mostly want to connect it to a new object, and you can do it by doing it.
Example: string s = new String ("Asdf")
2.class:
In fact, what you need to do in Java is to define class, generate objects, and send messages to objects. If everything is an object, in order to solve the characteristics of a class of objects, we need to define it, this is class.
Example: Class Atypename{/*class body*/}
Atypename a = new Atypename ();
To specify the value of its data idiom, you can specify with a period, and then the name of the member:
For example:
class dateonly
{
int i;
float f;
boolean b;
}
dateonly d = new dateonly ( ) ;
d.i = 47;
d.f = 1.1f;
d.b = false;
What is different from C + + is that in Java, when a variable is a basic type within class (primitive type), Java guarantees that it has a missing value of 100%, but if the variable is only a local variable in a function definition area, the variable will not be initialized, you need to give him an appropriate value, If you forget, the Java compiler will identify it as an error at compile time, and the C + + compiler will only warn you of uninitialized variables.
3. Referencing components (import):
For example: Import java.until.arraylist says you want to use ArrayList class, you can also use * to replace ArrayList, to avoid one declaration (although convenient, but affect compile time)
4. The "Shepherd" function is static:
In Java, in general, you need to produce an object, and then use the object to fetch its data and
function, but if you declare a function or data as static. It will not be limited to the required class object, even if there is no object, the outside world can call its static function.
For example:
class statictest { static int i = 47; }
statictest st = new statictest ( );
这里st.i和statictest.i作用相同,他们共同指向一块内存。
class staticfun
{
static void incr( ) { stitictest.i++ }
}
staticfun sf = new staticfun ( );
Either through the object----SF.INCR () or directly through the class---STATICFUN,INCR () calls are the same.