Java Basic question-1

Source: Internet
Author: User

Three technical architectures for 1.java?

A.ee(Java 2 Platform Enterprise Edition) Enterprise Edition

is a set of solutions for developing applications in an enterprise environment.

The technology system includes servlet JSP, etc., mainly for Web application development.

B.j2se(Java 2 Platform standard Edition) Standard Edition

is a solution for developing common desktop and business applications.

The technology system is the basis of the other two, can be completed some desktop application development.

c.j2me(Java 2 Platform Micro Edition) Small version

It is a solution for the development of electronic consumer products and embedded devices.

The technology system is mainly used in small electronic consumer products, such as mobile phone applications.

2. What is the difference between JDK and JRE?

         JDK (Java Development Kit) is the development toolset for Java.

                 JRE (Java Runtime Environment) is the operating environment for Java programs.

so the difference between JDK and JRE is one for development, one for running, and the other is that they are a must for Java developers.

3. What do Java and Java commands do?

You know that Java is divided into two parts: one is compile , one is run .

Javac: is responsible for the compilation of the part, when the execution of Javac, will start the Java compiler program. Compiles a. java file with the specified extension. Generates bytecode files that the JVM can recognize. That is, the class file, and the Java running program.

Java: The part that is responsible for running. The JVM is started. Loads the class library that is required by the runtime and executes it. The file must have a starting point for execution, and this starting point is the main function.

4. The data type of java.

There are two types of data in Java:

(1) Basic data type (eight basic data types)

Integral type

A. Byte byte type 1 byte 8bit maximum storage data volume is 255, the data range stored is between -128~127

B. Short 2- byte 16bit maximum data storage is 65536, data range is -32768~32767

c. int integer 4 bytes 32bit Maximum data storage capacity is 2 of 32 minus 1, data range is negative 2 of 31 to positive 2 square minus 31

d. Long length integer 8 bytes 64bit maximum data storage capacity is 2 of 64 reduction 1, data range is negative 2 of 63 to positive 2 square minus 63

Floating point Type

E. Float single precision 4 byte 32bit data range in 3.4e-45~1.4e38, direct assignment must be preceded by a number F or f

F. Double dual precision 8 byte 64bit data range in 4.9e-324~1.8e308, can be added D or D can also not be added

Character type

G. Char character type with single quotation mark

Boolean type

H. Boolean Boolean True/false (only true two results)

(2) Reference data type

In Java, types that are not simple data types are reference data types.

5. What is the difference between & and &&?

& and && are logical operators, both of which are judged to be true at the same time, otherwise false; && when the first condition fails, the subsequent conditions are not executed, and & continues execution until the entire conditional statement is executed.

6. | and | | The difference?

|| and | are all expressions "or", the difference is | | As long as the first condition is met, the following conditions are no longer judged, and | All conditions are judged.

7. Stacks and heaps.

The memory of the Java JVM can be divided into 3 extents: heap (heap), stack (stack), and method area heap: 1. All objects are stored, each containing a class-corresponding information. (The purpose of class is to get the operation instructions). 2.JVM only one heap area (heap) is shared by all threads, and the heap does not hold base types and object references, only the object itself. Stack area: 1. Each thread contains a stack that holds only objects of the underlying data type and references to custom objects (not objects), and objects are stored in the heap area. 2. The data in each stack (original type and object reference) is private and other stacks are inaccessible. 3. The stack is divided into 3 parts: the basic type variable area, the execution environment context, the operation instruction area (holds the operation instruction). Method Area: 1. Also called the static zone, like the heap, is shared by all threads. The method area contains all class and static variables. 2. The method area contains elements that are always unique throughout the program, such as the class,static variable.

The difference between heap and stack (stack) in the Java language:

1. Stacks and heaps (heap) are places that Java uses to store data in RAM. Unlike C + +, Java automatically manages stacks and heaps, and programmers cannot directly set up stacks or heaps.

2. The stack holds local variables (basic types of variables) and reference of objects. The advantage of the stack is that the access speed is faster than the heap, after the register, the stack data can be shared. However, the disadvantage is that the size and lifetime of the data in the stack must be deterministic and inflexible. The stack is followed by threads, and there is a stack on the wire thread.

3. The heap holds objects, including object variables and Object methods. The advantage of the heap is that the memory size can be allocated dynamically, and the lifetime does not have to tell the compiler beforehand that the Java garbage collector automatically collects the data that is no longer in use. However, the disadvantage is that the access speed is slower due to the dynamic allocation of memory at run time. The heap follows the JVM, and there is a heap of memory on the JVM.

8. Object-oriented.

Object-oriented Key features:

Encapsulation: Encapsulation is an information masking technique that is embodied in the description of the class to make the data more secure. Is an important feature of an object. Encapsulation makes the data and the method (function) of processing the data encapsulated as a whole, in order to achieve a very independent module, so that the user can only see the external characteristics of the object (the object can accept which messages, with those processing power), and the object's internal characteristics (the preservation of the internal state of private data and the implementation of processing capacity algorithm) is The purpose of encapsulation is to separate the use of the object's designer from the object, and the user does not have to know the details of the implementation of the behavior, but only accesses the object with the information provided by the designer.

Inheritance: Inheritance is the mechanism by which subclasses automatically share data and methods between parent classes. It is represented by the derivation function of the class. A class inherits all the descriptions of other classes directly, and can be modified and expanded.

Inheritance has transitivity and uniqueness. If Class B inherits Class A, and Class C inherits Class B, it can be said that Class C inherits the Class B while inheriting the Class A and Class C, and can implement the methods in Class A. A class that can inherit only one class at a time, but not multiple classes at the same time. Often referred to as multiple inheritance refers to a class that inherits its parent class while implementing other interfaces. The objects of the class are closed, and if there is no inheritance mechanism, the data and methods in the class object are duplicated. Inheritance supports the reusability of the system, which can reduce the amount of code, and also promote the expansibility of the system.

Polymorphism: objects are acting according to the messages they receive. When the same message is accepted for different objects, it can produce completely different actions, known as polymorphism. The use of polymorphic users can send a common message, and all implementation details are left to the object receiving the message, so the same message can invoke different methods. For example, the printing method that is called when the print message is sent to a graph or table is completely different from the printing method that is called when the same print message is sent to a body file. The implementation of polymorphism is supported by inheritance, with the hierarchical relationship of class inheritance, the protocol with common function is stored at the highest level of class, and the different methods of implementing this function are placed at a lower level, so that the objects generated at these low levels can respond differently to generic messages. Polymorphism can be achieved in OOPL by redefining a base class function (defined as an overloaded function or virtual function) in a derived class.

In this paper, it is shown that in OO methods, objects and transitive messages represent the concept of the relation between things and things respectively. Classes and inheritance are descriptive paradigms that are adapted to the way people think in general. The method is to allow various actions on the class object. The basic point of this programming paradigm for objects, classes, messages, and methods lies in the encapsulation of objects and the inheritance of classes. By encapsulating the object's definition and the realization of the object, the inheritance can embody the relationship between class and class, and the dynamic link and entity polymorphism, thus constituting the basic characteristic of object-oriented.

Object-oriented features

(1) abstract.

Abstract refers to the emphasis on the nature and intrinsic properties of the entity. In system development, abstraction refers to the meaning and behavior of an object before deciding how to implement it. Use abstraction to avoid thinking about details as early as possible.

The class implements the abstraction of the object's data (that is, state) and behavior.

(2) Encapsulation (information hiding).

Encapsulation is the basis of ensuring the good modularity of the software components.

An object-oriented class is a well-encapsulated module in which the class definition explicitly separates its description (the user-visible external interface) from the implementation (an internal implementation that is not visible to the user), and its internal implementation provides protection according to the scope it specifically defines.

The object is the most basic unit of encapsulation. Encapsulation prevents the change effect of program interdependencies. Object-oriented encapsulation is clearer and more powerful than traditional language encapsulation.

(3) Sharing

Object-oriented technology facilitates sharing at different levels

Share in the same class. objects in the same class have the same data structure. These objects are shared relationships between structures and behavior characteristics.

Shared in the same app. In the class hierarchy of the same application, there exists the inheritance of data structure and behavior in each similar subclass of the inheritance relationship, so that the similar subclasses share the common structure and behavior. Using inheritance to implement code sharing is one of the main advantages of object-oriented.

Shared in different apps. Object-oriented not only allows sharing of information in the same application, but also prepares conditions for reusable designs for future goals. Through the mechanism and structure of class library, information sharing in different applications is realized.

9. What is the difference between a member variable and a local variable?

Member variable: a private variable defined in this class that belongs to this class.

Local variables: Created in the method body, access to this variable is not available outside the method body. Creation and use of local variables (local variables must be assigned, member variables may not be assigned values)

Difference:

A local variable describes a property in the body of the method, and the member variable describes the attribute in the object.

Member variables can be decorated with public, protected, default, private, static, final modifiers and local variables can only be decorated with the final modifier.

Member variables are created in the heap, and local variables are created in the stack.

Local variables are system defaults, local variables have no system defaults and must be manually assigned

10. What is the difference between a constructor and a general function?

A: Two function definition formats are different.

B: The constructor is called when the object is created, used for initialization, and the initialization action is performed only once.

The general function is that after the object is created, it needs to be called to execute and can be called multiple times.

11. What is the difference between constructing a code block and a constructor function?

Constructing blocks of code: Initializes all objects, that is, all objects call a block of code. As soon as Object one is established. This code block is called.

Constructor: Initializes the object to which it corresponds. It is targeted.

This article is from the "month Singer" blog, make sure to keep this source http://727229447.blog.51cto.com/10866573/1711612

Java Basic question-1

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.