Tips for learning the Java language

Source: Internet
Author: User

The initial exposure to the computer programming language is the C language, and then with the C language, the introduction of Java has become much simpler. Java is actually a place name, rich in coffee, so icons like coffee, but slowly contact, you can experience the sweetness of Java.

Java runtime in the virtual machine above, that is, Java compared to the C language direct contact hardware operation Security, Java with virtual memory access to data, I compiled Java with eclipse This software, this software is completely free, beginners can go to the official website to download. When you install eclipse, it is not available, because of the lack of a running environment, you also need to download a JDK, that is, the environment to run Java. Interestingly, the software that compiles Java programs is written in the Java language, a bit of philosophical taste.

I studied Java under the guidance of Li Xinghua teacher. Just touch Java is not strange, because there is a certain basis for programming. In my feeling, Java is more convenient than C language, C language always want to worry about allocating memory, and Java is not so rhythmic, when you need, when to use the new + constructor (Constructor), open space, the JVM can automatically allocate memory. And one thing that makes me feel convenient is that in C, the variables need to be defined before they are used. And the Java humanization is that you can follow the definition, so there are many advantages, if the variable is only involved in the process, then there is no need to worry about wasting memory space, because the GC directly to help you get rid of.

Java is an object-oriented language, in which there is the concept of classes (Class), in my understanding of Java, the program to clustering, class to object, meaning that the object can implement the function of the class, do not know that the description is not accurate. Classes and objects, objects are governed by classes, and classes have a uniform definition of objects. For example, my family's black cat, Lao Zhang's white cat, these specific individuals are objects, each object has its own unique characteristics, and cats, is to include these characteristics of the collection, regardless of the black Cat White cat, belong to the Cat class, so no matter the Black Cat White cat kitten, can instantiate good object is good.

Running a Java program requires a main method in a class that needs to be defined, just like a C program that executes from the main function, so that it can run, otherwise there is only one class without the Main method, which can only be defined for the object of the class and not run. Java uses the Class keyword to define a class, and the name of the class can be taken by itself, but it should be noted that the name of the public class defined must be consistent with the name of the file.

Variables, functions we are very familiar with the use of them, when you define a static keyword added to define a variable, adding the keyword modifier has become a class variable, this class variable belongs to the class you declared. When you create the object, you can access the class variable through the object, but actually the object itself is no class variable, the reason is accessible, because the object knows that it belongs to the class, and this class variable belongs to the class, so it is logical to be able to access. Class functions have the same principle.

        Then we talk about overloading, overloading means that you can define multiple functions that can have the same name, and the functionality can be different. The parameters of these functions are different, there are probably the number or type of arguments, or they are different, sounds great, but in fact it is not that difficult. Java convenience lies in its object-oriented concept, can also be seen from the overload, if you want to calculate the number of integers in the C and, floating-point numbers and, then you need to create two different functions, and in Java, you can create a method, and then pass the different parameters in the method, so it is not much easier?

        Exposure to abstraction you're close to Java's deeper knowledge. First of all, we begin with the literal understanding that abstraction means concrete and insufficient detail. If you have this idea, then you have mastered the abstract only way. The so-called abstract function, is to express the concept and can not specifically implement the code of the function, abstract class is to express the concept and can not create the entity's class, we can not be difficult to find that the abstract is a concept, only exist in the theory, then you will be as I just touched the time as full of doubts, since the abstract what is not Don't worry, I'll talk to you slowly. This abstraction is intended to better classify things with the same characteristics, to overwrite the parent class's methods through subclasses, and then to implement the corresponding functions. The specific application of abstraction is the interface (Interface). Interface is a completely abstract class, to really implement the function, or need to use the class to inherit, in Java this is called implementation (implements), when you this class to implement this interface, is actually the interface gives you a guide direction, by the class to implement the function, So you need to overwrite all the methods of the parent class, which is the interface, and think, if you don't write the method, then the class you set up is still an abstract class that can only remain conceptually and not be put into action. Java classes are single-inheritance, that is, a subclass can inherit from only one parent class, and a parent class may have multiple subclasses. Take the example of life is very good understanding, a father can have more than one son, but every son in normal circumstances can only look for a biological father. The appearance of the interface has broken this situation, a class does not allow the inheritance of multiple classes, but an interface can inherit multiple interfaces at the same time.

Let's talk about multithreading, and believe that users of windows are not unfamiliar with the process, although the process and thread routine are related to concurrent processing, but multi-threading, multi-process usage environments are different. Multithreading shares memory and data, and shares the running environment. Multi-process Each environment has independent access to memory and its own environment, depending on the requirements. Multithreading makes the program more efficient, think, if you need your left hand to draw a circle, the right hand to draw a square, two hands at the same time, then how do you do? I am afraid that two hand draw out of can not be satisfied, because our thinking determines that we can only focus on doing one thing, then if you do so, the left to draw an arc, the right to draw a straight line, then the left to draw an arc, the right to draw, so alternately, you find the completion of the last stroke, you did! If you look at the picture from a macro point of view, it looks like the same-handed at the same time, it is like the principle of multi-threading, painting this thing is the process, the right hand to do things is the thread to do things, at the same time we have two threads simultaneously. In Java, we only care about the program, but not how the program specifically interacts with the underlying, so we simply understand the thread is good.

When the thread sleeps, it's not hard to imagine, not running, or blocking.

Java does not have the same address as the C language, which in fact makes Java more secure, it can only be referenced by reference variables, Hashcode stores the address of the object referenced by the current variable, but this is not the real memory address, just a related value.

I want to be organized and explain the Java object-oriented three features-encapsulation, inheritance, polymorphism. Class encapsulation, using the Private keyword to implement the encapsulation of the class, that is, to let this class into the private property. The inheritance of the class is used to extend the functionality of the class, inheriting from the parent class, owning everything from the parent class, and constructing its own method. Polymorphism (polymorphism), as the name implies, implies a variety of states, and different objects call the same method to produce different results.

This is my small understanding of the Java language, because of the lack of code performance, I may write some holes, there are some loopholes, but I have already expressed themselves in words, learning a programming language far more than these, only through a lot of practice, in the practice of understanding. I will keep my passion for Java and continue to learn.


Tips for learning the Java language

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.