Java After class study questions

Source: Internet
Author: User
Tags object serialization wrapper ftp protocol

1, briefly describe the difference between path and classpath.

The PATH:PATH environment variable is one of the system environment variables that holds the path to a series of executable files, separated by semicolons. When running an executable file in a command-line window, the operating system will first look in the current directory for the existence of the file, and if it does not exist, it will continue to look for it in a path defined in the PATH environment variable, and if it is not found, an error is made.

The CLASSPATH:CLASSPATH environment variable is also one of the system environment variables that holds the path to a series of class (. Class) files. When a Java virtual machine needs to run a class, it first looks for the desired class file in the path defined in the CLASSPATH environment variable. If the path of the classpath has a semicolon at the end, it is not found in the classpath, then the current path is searched, and if there is no semicolon at the end, it is only found in the path of the Classpath setting.

2. Please tell me about your understanding of the JVM.

The JVM is the abbreviation for Java Virtual machine, the full name of the Java VM. One of the most important features of the Java language is cross-platform, and the Java virtual machine is the key to achieving this feature. Different operating systems require different versions of virtual machines, which allows the Java language to "write once, run everywhere". The Java language compiler simply generates the target code (bytecode) that runs on the Java Virtual machine and can run unmodified on multiple platforms. When a Java virtual machine executes a bytecode, it interprets the bytecode as a machine instruction execution on a specific platform.

3. Can I store a Chinese character in char type variable? Please tell me the reason.

Char-type variables are used to store Unicode encoded characters, and the Unicode encoding character set contains Chinese characters, so the char type can of course store Chinese characters. However, if a particular Chinese character is not included in the Unicode encoding character set, then this char variable cannot store this particular character. Supplemental Note: Unicode encoding consumes two bytes, so variables of type char are also two bytes.

4. Briefly describe the difference between break, continue, and return statements.

Break statement: You can use the break statement in both the switch condition statement and the loop statement. When it appears in a switch condition statement, the function is to terminate a case and jump out of the switch structure. When it appears in the Loop statement, the function is to jump out of the loop statement and execute the following code.

Continue statement: The Continue statement is used in the loop statement, which is the function of terminating the loop and performing the next loop.

Return statement: The return statement can be used to exit from the current method, return to the statement of the method of the call, and continue execution. Return returns a value to the statement that invokes the method, and the data type of the return value must match the type of the return value in the declaration of the method.

5, please briefly describe the advantages and principles of garbage collection.

A notable feature of the Java language is the introduction of a garbage collection mechanism, which allows Java programmers to write programs without having to consider memory management. Garbage collection can effectively prevent memory leaks and effectively utilize the memory that can be used. The garbage collector is typically run as a separate low-level thread, unpredictable and clear and recyclable for objects that have died in the heap or that have not been used for a long time, and the programmer cannot call the garbage collector in real time for garbage collection of an object or all objects.

6. Please say what you know in Java code block.

There are four blocks of code in Java, which are static blocks of code, building blocks of code, ordinary blocks of code, and synchronized blocks of code.

Static code blocks: In a Java class, several lines of code surrounded by a pair of curly braces are called a block of code, and blocks of code decorated with the static keyword are called static blocks of code. When the class is loaded, the static code block executes, because the class is loaded only once, so the static code block executes only once. In a program, static code blocks are typically used to initialize member variables of a class.

Building blocks of code: Blocks of code that are defined directly in the class without the static keyword are called construction blocks of code. The construction code block executes every time the object is created.

Ordinary blocks of code: blocks of code that appear in a method or statement are called ordinary blocks of code. Ordinary blocks of code and general execution order of statements are determined by the order in which they appear in the code, that is, first execution occurs.

Synchronizing code blocks: Java provides a professional solution for multithreading security issues, which is to synchronize code blocks.

Synchronized (object)//This object can be an arbitrary object

{

Code that needs to be synchronized

}

An object is like a lock, a thread that holds a lock can execute in sync, and a thread that does not hold a lock does not get in even if it gets the execution of the CPU.

7. Please describe the difference between method overrides and method overloads.

Method overrides (overriding) and method overloads (overloading) are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class.

If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). When an object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked".

If more than one method with the same name is defined in the same class, they either have a different number of arguments or have different parameter types, which is called a method overload (overloading).

8. What is the difference between error and exception?

Error means that recovery is not an impossible but difficult situation of a serious problem, such as memory overflow, only by modifying the program itself can not handle such a situation.

Exception represents an error that the program itself can handle, and exception handling in developing Java programs is for the Excption class and its subclasses. There is a special RuntimeException class in many subclasses of the exception class that is used to represent run-time exceptions, except for this class, where all other subclasses of the exception class are used to represent compile-time exceptions.

9, please briefly describe the similarities and differences between synchronized and Java.util.concurrent.locks.Lock.

The same point: lock completes all the functions that the synchronized implements.

The difference: In general, lock is more flexible. Lock has more precise threading than synchronized and better performance. The synchronized will automatically release the lock, but lock must require the programmer to release it manually and must be released in the finally clause. Synchronized modifies a method to indicate that the same object behaves as a synchronization queue in a different thread. If you instantiate a different object then synchronized will not have synchronization effect.

10. What is the difference between a process and a thread?

In an operating system, each independently executed program can be called a process, which is a "running program". And in the process can have more than one execution unit at the same time, these execution units can be seen as a program of clues, called threads. The Java Runtime environment is a single process that contains different classes and programs. Threads can be called lightweight processes. Threads require fewer resources to create and reside in a process, and can share resources in a process.

11. Please describe the difference between int and integer.

int is the basic data type in Java, and integer is the wrapper class provided by Java for Int. The initial value of the int type is 0, and the initial value of the integer is null. Java provides a wrapper class for each base type, and the wrapper class belongs to the reference type.

12. Please outline the concept of packing and unpacking.

Wrapper and basic data types introduce the concept of boxing and unboxing when converting, where boxing refers to converting the value of a base data type to a reference data type, whereas unpacking refers to converting an object of the reference data type to a basic data type.

13, please briefly describe the difference between Hashtable and HashMap.

Hashtable inherits from the Dictionary class, And HashMap is an implementation of the map interface introduced by Java1.2 HASHMAP allows NULL as a entry key or value, and Hashtable does not allow the HashMap Hashtable method removed, changed to contains Insvalue and ContainsKey. The biggest difference is that the Hashtable approach is thread-safe, and HashMap is not, when multiple threads access Hashtable, they do not need to synchronize their methods, and HashMap must provide them with external synchronization.

14, please briefly describe the advantages of using generics.

(1) Improve the type security of Java programs, resolve errors during compile time, and avoid errors in the program during runtime. (2) Eliminate forced type conversions. (3) Generics can replace the use of parameters and variables of type object, resulting in a significant increase in performance and readability of the code.

15. What is object serialization and how is serialization implemented?

When the program runs, it creates multiple objects in memory, but when the program finishes, the objects are garbage collected. If you want to persist these objects, you can write the object to byte data to the hard disk, a process known as Object serialization.

Serialization implementation: Implement the Serializable interface for the class that needs to be serialized, there is no method to implement it, implements serializable just to annotate that the object is serializable, and then use an output stream ( such as: FileOutputStream) to construct a ObjectOutputStream object, followed by the WriteObject (object obj) of the ObjectOutputStream object method to write out (that is, to save its state) an object with the parameter of obj.

16, briefly describe character encoding and decoding.

Converting a string into a computer-recognized byte sequence is called encoding, whereas converting a sequence of bytes into a plain-text string that the average person can read is called decoding.

In a computer program, if you want to convert a byte array to a string, you can decode the byte array into a string by using the String class constructor string (byte[] bytes,string charsetname), if you do not specify a character code table, The default character code table for the operating system, such as Chinese, is used by default for the GBK of the character code table, and conversely, the string can be encoded into a byte array according to the specified code table by using the GetBytes (String CharsetName) method in the String class.

17. Briefly describe which layout managers are available in the java.awt package.

Five layout managers are available in the java.awt package, namely FlowLayout (Flow Layout manager), BorderLayout (Boundary layout manager), GridLayout (Grid layout manager), GridBagLayout (Grid package layout manager) and CardLayout (Card layout manager).

18. Briefly describe the concepts involved in the event handling mechanism.

The event handling mechanism is specifically designed to respond to user actions, such as using the AWT event-handling mechanism to respond to user clicks, keystrokes, and so on. Before learning how to use the AWT event handling mechanism, let's first introduce several more important concepts, as follows:

Event object: Encapsulates a specific event that occurs on a GUI component (usually a user's one operation).

Event Source (component): The place where an event occurs, usually the component that generates the event.

Listener (Listener): An object that is responsible for listening for events that occur on the event source and responding to various events (the object contains the event handler).

Event handler: The method by which the listener object handles the received event object accordingly.

19, briefly describes the TCP/IP protocol hierarchy.

The hierarchy of TCP/IP protocol is simple, it is divided into four layers, namely application layer, Transport layer, network layer and link layer. The link layer is used to define a physical transport channel, typically a drive protocol for certain network-connected devices, such as a driver for fiber optics and twisted-pair cables. The network layer is the core of the whole TCP/IP protocol, which is mainly used to group the transmitted data and send packet data to the target computer or network. Transport layer mainly makes the network program communicate, in the network communication, can adopt the TCP protocol, also can adopt the UDP protocol. The application layer is responsible for the protocol of the application, such as HTTP protocol, FTP protocol, etc.

20. Describe your understanding of IP address.

To enable computers in your network to communicate, you must specify an identification number for each computer that specifies the computer that accepts the data or the computer that is sending the data. In the TCP/IP protocol, this identification number is the IP address, it can uniquely identify a computer, currently, the IP address widely used version is IPv4, it is represented by a 4 byte size binary number, because the binary form of the IP address is very inconvenient memory and processing, As a result, the IP address is usually written in decimal form, with each byte represented by a decimal number (0-255), with the symbol "." Between the numbers. Separate, such as "10.0.0.1".

Java After class study questions

Related Article

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.