Java basics-002 and java-002

Source: Internet
Author: User

Java basics-002 and java-002
1. Java Virtual Machine and "platform-independent language"

Java virtual machine is a virtual machine process that can execute bytecode. The Java source file is compiled into a bytecode file executed by the Java Virtual Machine.

Java is designed to allow applications to run on any platform without the need for programmers to rewrite or re-compile each platform. The Java virtual machine makes this possible because it knows the command length and other features of the underlying hardware platform.

2. Differences between JDK and JRE  The Java Runtime Environment (JRE) is the virtual machine that will execute the Java program. It also contains the browser plug-in required for executing the applet. The Java Development Kit (JDK) is a complete software development kit that includes JRE, compilers, and other tools (such as JavaDoc and Java debugger). It allows developers to develop, compile, and execute Java programs. 3. "static" keyword

The "static" keyword indicates that a member variable or member method is accessed without the instance variable of the class.

In Java, the static method cannot be overwritten, because the overwriting is based on dynamic binding during runtime, while the static method is statically bound during compilation. The static method is irrelevant to any instance of the class.

Static variables belong to Classes in Java, and their values in all instances are the same. When a class is loaded by a Java virtual machine, static variables are initialized. If your code tries not to use instances to access non-static variables, the compiler reports an error because these variables have not been created and are not associated with any instances.

4. Data Types supported by Java

The eight basic data types supported by Java are: byte, short, int, long, float, doble, boolean, and char.

The Java language also supports reference data types.

During automatic packing, the Java compiler converts the basic data type to the corresponding object packaging type, for example, converting int to Integer or double to Double. Otherwise, it is automatically split.

5. Overriding and Overloading in Java)

During method overloading in Java, two or more methods in a class have the same method name but different parameters.

In contrast, method override means that child classes redefine the methods of the parent class. Method override must have the same method name, parameter list, and return value type.

6. constructor in Java, reload constructor, and copy constructor

When a new object is created, the constructor is called. Each class has a constructor. When a programmer does not provide constructors to a class, the Java compiler creates a default constructor for the class.

Java constructor Overloading is similar to normal method overloading. You can create multiple constructors for a class. Each constructor must have its own unique parameter list.

Java does not support copying constructor like that in C ++. The difference is that if you do not write constructor yourself, Java will not create a default replication constructor.

7. Multi-Inheritance

Java does not support multi-inheritance. Only single inheritance is supported (that is, a class has only one parent class ). However, interfaces in Java support multi-inheritance, that is, a sub-interface can have multiple parent interfaces.

An interface is used to extend the functions of objects. a sub-interface inherits multiple parent interfaces, indicating that the sub-interface extends multiple functions when the class implements interfaces. Class extends the corresponding functions.

8. interfaces and abstract classes

Java provides and supports creating abstract classes and interfaces. Their implementations are in common. The difference is:

I> all methods in the interface are implicitly abstract, while abstract classes can simultaneously contain abstract and non-abstract methods.

II> class can implement multiple interfaces, but can inherit only one abstract class.

III> classes do not implement all methods declared by abstract classes and interfaces. Of course, in this case, classes must also be declared abstract.

IV> abstract classes can implement interfaces without interface methods.

V> the variables declared in the Java interface are final by default. abstract classes can contain non-final variables.

VI> the member functions in the Java interface are public by default. The member functions of the abstract class can be private, protected, or public.

VII> the interface is absolutely abstract and cannot be instantiated. Abstract classes cannot be instantiated, but can be called if they contain the main () method.

9. Value Transfer and reference Transfer

The object is passed by the value, which means that a copy of the object is passed. Therefore, even if the object copy is changed, the object value will not be affected.

When an object is referenced and passed, it is not an instance object but a reference of the object. Therefore, changes made by the external to the referenced object are reflected on all objects.

Note: in Java, only values are passed, but not references.

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.