Java after class simple answer

Source: Internet
Author: User

1, briefly describe the characteristics of Java.

Object-oriented, cross-platform, robustness, security, portability, multithreading, dynamic and so on.

2. Briefly describe the difference between JRE and JDK.

The JRE (Java Runtime Environment,java Runtime Environment), which is equivalent to the operating system section, provides the basic conditions that Java programs need to run and many Java base classes, such as IO classes, GUI control classes, network classes, and so on. The JRE is available to ordinary users, and if you only want to run Java programs that others have developed, then you must install the JRE on your computer.

The JDK (Java Development Kit,java SDK), which contains a variety of development-related tools for compiling tools, interpreting tools, document authoring tools, and packaging tools, is available to Java developers. When beginners learn and use the Java language, they must first download and install the JDK. The JRE section is already included in the JDK, and it is not necessary to download and install the JRE after beginners install the JDK.

3. Please list the eight basic data types in the Java language and describe the amount of space occupied by each data type.

The eight basic data types of the Java language are: Byte Byte, which takes one byte. Short shorter integer, which accounts for two bytes. int integer, accounting for 4 bytes. A long integer that occupies 8 bytes. Float single-precision floating-point type, accounting for 4 bytes. Doubles double-precision floating-point type, accounting for 8 bytes. char character type, accounting for two bytes. A Boolean that represents a logical value with a true and false value of two, one byte, respectively.

4. Briefly describe the difference between && and & and illustrate.

If you use & to connect between expressions, the expressions on both sides of & will participate in the calculation, regardless of the circumstances. If you use && to connect, the expression to the right of && will not be executed when the expression on the left side of the "=" is false. For example, define int x = 2,y = 0; The Boolean b = x < Y & x/y > 0 expression is the exception that will occur by 0, because the expression for x/y is executed. This exception does not occur for Boolean B = x < y && x/y > 0, because x < Y is false, and the expression x/y is not executed.

5. What is method overloading?

Method overloading refers to the ability to declare multiple methods with the same name in a class, and the number of parameters in a method or the data type are inconsistent. When you call these methods with the same name, the JVM binds to different methods depending on the actual parameters.

6. What is the difference between a construction method and an ordinary member method?

A constructor method is a special member of a class that is called automatically when a class instantiates an object. The normal method is called only when it is used . When you define a construction method, you require that the method name is the same as the class name, that there is no sound of the return value type before the method name , and that the return statement cannot be used in the method.

7. What are the characteristics of the single case design mode?

Singleton mode guarantees that only one instance object exists for the class during the entire program run.

8. What is method rewriting?

In an inheritance relationship, a method of a subclass has the same method name, return type, and argument list as a method of the parent class, which is called the method of the subclass that overrides (Overrides) the parent class.

9, what is polymorphic?

Polymorphism means that an object has many forms and can behave differently in certain situations, thus corresponding to different properties and methods. In a nutshell, polymorphism is referencing a subclass object using a variable of the parent class type, and the program gets a different effect depending on the nature of the referenced subclass object.

10. What are the differences between abstract classes and interfaces?

In Java, classes that are decorated with the abstract keyword are called abstract classes. Abstract classes cannot be instantiated, and typically require writing a subclass to inherit an abstract class, while instantiating a subclass to get the object of that class. Abstract classes are often used to represent an abstract concept.

An interface can be said to be a special abstract class, and only constants and abstract methods can be defined in an interface. Because of the particularity of the interface, it is necessary to use the interface keyword when defining.

11. There are several ways to implement a thread in Java? Please illustrate.

One is to inherit the thread class under the Java.lang package, overwrite the run () method of the thread class, and implement the Code on the thread in the run () method.

New Thread () {

public void Run () {}

}.start ();

The other is to implement the Java.lang.Runnable interface, which is also the code that runs on the thread in the run () method.

New Thread (New Runnable () {

public void Run () {}

}). Start ()

12. What is the difference between sleep () and wait ()?

Call the Sleep () method, the executing thread actively yields the CPU to execute other threads, and after the time specified by the sleep () method, the CPU will go back to the thread to continue execution, and if the current thread enters a sync lock, the sleep () method does not release the lock. Even if the current thread uses the sleep () method to give up the CPU, other threads that are blocked by the sync lock cannot be executed.

Wait () is called within a thread that has entered a synchronization lock, allowing the current thread to temporarily let out the synchronization lock so that other threads waiting for the lock can get a synchronous lock and run. When another thread calls the Notify () method, the thread that calls the wait () method will dismiss the wait state, and when the synchronization lock is acquired again, the program can continue to execute down.

13. What is the difference between string and StringBuffer?

The string class is an immutable class that cannot be changed once the string value has been initialized. StringBuffer is a mutable string class, string-like buffer that can modify the value of a string.

14. What is the difference between the date and the Calender class?

The date class is used to denote a specific moment, which can be accurate to milliseconds. In practical applications, it is often necessary to return information such as the year, month, and day of a date separately for display or processing, and most of the methods in this class have been marked obsolete. The Calender class essentially supersedes the date class, which defines a series of methods for completing date and Time field operations.

The calendar GetTime () method, GetTime () returns a Date object that represents the calendar time value, and the calendar has a settime (date date) method, and the SetTime () method receives a Date object. The time value represented by the Date object is set to the Calendar object, and the conversion between date and calendar objects can be accomplished by both methods.

15, what is a collection, please list the common classes and interfaces in the collection?

to make the program easy to store and manipulate a set of data that is not fixed, the JDK provides a set of class libraries that are bit In the java.util package, collectively referred to as the collection. The collection frame contains 3 interfaces, list, Set, and Map, respectively.

16. What is the difference between list, set, and map in a collection?

The list is characterized by an orderly element and repeatable elements. The main implementation classes of the list interface are ArrayList and LinkedList. Set is characterized by the disorder of elements and the non-repetition of elements. The main implementation classes of the set interface are HashSet and TreeSet. The feature of map is that the stored element is a key (key), value mapping relationship, and the elements are paired. The main implementation classes of the map interface are HashMap and TreeMap.

17, please talk about collection and collections What is the difference?

Collection is a single-instance collection interface. It provides a common way to perform basic operations on a collection object. Collections is a tool class. It contains a variety of methods for collection operations.

18, briefly describe the concept of flow.

The Java program completes the input and output through the stream, which is an abstraction of the input or output information. The stream communicates with the peripheral connection via the Java input/output system. The stream is an abstract object that implements the code in the Java.io package.

19, Java stream is divided into the word stream, character stream two streams, what is the difference between them?

The two base classes of the byte stream are InputStream and OutputStream, and the two base classes of the character stream are reader and writer, both of which are direct subclasses of the object class, and the byte stream is a byte stream class that handles 8-bit bytes as the basic unit Reader and writer classes are character stream classes that specialize in 16-bit bytes.

20. Brief description of pipeline flow.

Pipeline flow is divided into pipeline input stream (PipedInputStream) and pipeline output flow (PipedOutputStream), Typically a PipedInputStream instance object and a PipedOutputStream instance object are connected to each other for pipeline communication, and PipedOutputStream writes data to the pipe. PipedInputStream reads the data written by PipedOutputStream from the pipeline, and the pipeline flow is primarily used to complete communication between threads.

21. Please describe the steps to implement event monitoring in GUI.

Implement an Event listener class by implementing the Xxxlistener interface or inheriting the Xxxadapter class, and override the method that handles the listening action

Creating event source objects and event listener objects

Invoke the Addxxxlisntener () method of the event source to register the event listener object for the event source

22. The difference between AWT and swing

AWT is an abbreviation for the abstract window ToolKit (Abstraction Windows Toolkit), which provides a set of interfaces for interacting with the local graphical interface. The graphical functions in AWT have a one by one correspondence with the graphical functions provided by the operating system, and when we use AWT to construct graphical user interfaces, we are actually using the graphics library provided by the operating system. Features that exist on one platform may not exist on another because of the different functionality that is provided by the graphics library of the operating system. In order to implement the concept of "once compiled, run everywhere" in the Java language, AWT has to implement its platform independence by sacrificing functionality, that is to say, the graphical capabilities provided by AWT are the intersection of the graphical functions provided by various general-purpose operating systems. Since AWT relies on local methods to implement its functionality, we often refer to AWT controls as heavyweight controls.

Swing is a new graphical interface system built on AWT that provides all the functionality that AWT can provide, and dramatically expands the functionality of AWT with pure Java code. Since there is no local method to implement graphics functionality in swing, we often refer to swing controls as lightweight controls.

The basic difference between AWT and swing: AWT is a local method-based C/s + + program that runs faster, and swing is an AWT-based Java program that runs slower. For an embedded application, the hardware resources of the target platform are often very limited, and the running speed of the application is an important factor in the project. In this case, the simple and efficient AWT is, of course, the first choice for embedded Java. In standard Java applications based on PCs or workstations, the limitations of hardware resources on applications are often not critical in the project, so swing is advocated in the standard version of Java, that is, by sacrificing speed to implement the functionality of the application.

23. What is network communication protocol?

Transferring data across the Internet is subject to certain rules, which are often referred to as network communication protocols. The network communication protocol unifies the data transmission format, the transmission rate, the transmission step, and so on, the communication both parties must abide by this stipulation, can complete the information interaction. So far, there are many kinds of network communication protocols, among which the TCP/UDP protocol is the most widely used worldwide.

24. What is the difference between TCP protocol and UDP protocol?

The UDP protocol is a non-connected communication protocol, so-called no connection means that the sending and receiving end of the data does not establish a logical connection. Because the UDP protocol consumes less resources and has high communication efficiency, it is usually used for the transmission of audio, video and normal data. The UDP protocol does not guarantee data integrity when transmitting data, so it is not recommended to use the UDP protocol when transmitting important data.

The TCP protocol is a connection-oriented communication protocol that establishes a logical connection between the sending and receiving ends before transmitting data, and then transmits the data, which provides reliable and error-free data transfer between the two computers. In a TCP connection, it must be clear that the client and server side, the client sends the connection request to the service side, each connection creation will need to go through "three handshake".

25. What are the functions of socket class and ServerSocket class?

The ServerSocket class is used to create a server-side program that receives requests from clients by invoking the Accept () method of the ServerSocket object.

The socket class is used to create client programs, and when a leased line connection is established between the client and the server's two sockets, one end of the connection can write bytes continuously to the other end or from the other end. The getInputStream () method is defined in the socket class to return the input stream object of the socket, and the Getoutputstream () method is defined to return the output stream object of the socket. As long as one end of the connection writes data to the output stream object, the other end of the connection can be read from its input stream object.

Java after class simple answer

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.