Java 的介绍

来源:互联网 发布:外汇行情数据接口 编辑:程序博客网 时间:2024/06/05 17:53

小编是刚开始学Java, 就将所学到知识点,post出来,这篇文章大部分打算采用英文来写,如果哪里有瑕疵或者对英文理解有点困难的小伙伴们,别怪小编,欢迎指正!

Java也像C++一样,都是一门高级语言,which means the syntax is not strictly limited to OOP constructs, although it is assumed that you want to do OOP using Java (e.g., exception handling is not an OOP feature). 也就是说语法并没有仅限制于OOP结构。

优点: The initial programming effort should be simpler to learn and use than many other OOP languages.

One of Java’s primary goals is to make programming less error prone; for example, Java meets this goal:
1. By performing bounds checking. (这个主要应用在array)
2. By not having explicit pointers
3. By providing automatic garbage collection (这样就不用考虑内存泄漏问题)

Much of the foundation of C and C++ has been taken as a foundation in Java, with modifications. This is good news for us! However, unlike C++, Java does not maintain compatibility with the other languages, so you will find larger variations when moving from other languages to Java.

下面一部分很重要,因为要讲到如何声明一个变量。
In Java, we treat everything as an object.
1. We can have objects of primitive types (like int, float, char ….) or objects of class types. 意思就是我们可以在Java中可以对不管是primitive types (这里小编忘记中文名叫什么了) 或者是类的类型,都可以声明一个objects给它们
2. Objects of primitive types can be created in the same way that we do in C++ (e.g., int object;) 对于primitive types,我们可以像C++那样子声明一个object
3. Objects of class types cannot be created this way. First, we must create identifiers for objects that we desire these are actually references to objects. Then we must allocate memory on the HEAP for instances. 对于是class 类型的,要声明它的object, 那么就得给这个object一个空间,否则要调用class的member function就会出错
4. So, when we say: List obj; we have created only a reference not an object. If you want to send a message to obj (i.e., call a member function), you will get an error because obj isn’t actually pointing to anything: List obj = new List( );
5. So for a string object we could say:
String s = “Hello Java!”; or
String s = new String(“Hello Java!”);

String s = new String(“Hello Java!”); or List obj = new List(); //default constructor
1. We do this with the new keyword
2. This allocates memory for a new string and provides an initial value for the character string
3. And, like in C++ this cause the constructor for the class type to be implicitly invoked
4. New places the objects on the heap (which is not as flexible as allowing objects to be allocated on the stack)
5. It is not possible to request local objects of a class or to pass objects of a class by value to a function (or as the return value). This is because we are always working with a REFERENCE to the object - which is what gets passed (by value).

介绍Java的一点点知识,后续还会继续写关于Java的知识点!希望这个总结的会对大家的学习有所帮助!

原创粉丝点击