Basic knowledge: Simple principle and application of exception handling mechanism in C or Java. When the Java program violates the semantic rules of Java, the Java virtual machine will represent an error as an exception. Violation of semantic rules include 2 cases. One is a semantic check in the Java class library. For example, the array subscript can trigger indexoutofboundsexception; nullpointerException will be triggered when accessing null objects. Another situation is that Java allows programmers to extend this semantic check, and programmers can create their own exceptions and freely choose to trigger exceptions with throw keywords. All exceptions are subclasses of java.lang.thowable. 2. The same and different sages of Java interfaces and C virtual classes. Since Java does not support multi-inheritance, it is possible to use a class or object to use a method or attribute in several classes or objects, and existing single inheritance mechanisms cannot meet the requirements. Compared to inheritance, the interface has higher flexibility because there is no implementation code in the interface. When a class implements an interface, this class is to implement all methods and properties in the interface, and the properties in the interface are all public static below, all methods are public. Public. A class can implement multiple interfaces. 3. Advantages and principles of garbage collection. And consider 2 recycling mechanisms. A significant feature in the Java language is to introduce the garbage collection mechanism, which makes the problem of the most headache of C programmers, making the Java programmers no longer need to consider memory management when writing programs. Since there is a garbage collection mechanism, the object in Java no longer has the concept of "scope", and only the reference to the object has a "scope". Garbage recycling can effectively prevent memory leaks, effective use of memory that can be used. The garbage collector is usually operated as a separate low-level thread. In the case of unpredictable objects that have been died or have not used for a long time for a long time for a long time, the programmer cannot call the garbage collector in real time. Object or all objects are garbage collection. The recycling mechanism has a replica collection of garbage collection and marking garbage recovery, incremental garbage recovery. 4. Please tell the thread synchronization you know. Wait (): Make a thread in the waiting state and release the LOCK of the object held. Sleep (): Make a running thread in sleep state, is a static method, call this method to capture InterruptedException exceptions. NOTIFY (): Wake up a thread in a waiting state, note that when this method is called, it is not exactly the thread that is awakened, but is determined by the JVM which thread is awake, and is not pressed. AllNotity (): Wake all threads in the waiting state, not to give all the locks of all awakening threads, but let them compete. 5. Please talk about the usage and function of the system and virtual functions. 6. What is the difference between ERROR and EXCEPTION? Error indicates that the system-level error and the exception do not have to be processed, and Exception represents an exception to capture or require a program. 7. A class in Java is declared as a final type, what does it mean? It is said that the class cannot be inherited, it is a top class. 8. Describe your most common programming style. 9. What is the difference between HEAP and STACK. The stack is a linear set, and the operation of adding and deleting elements should be completed in the same paragraph. The stack is processed in the way in which it is advanced. Piles are a set element 10. If the system wants to use a large integer (more than the long range), you design a data structure to store such a super-large number and design a algorithm to achieve a large integer addition.
Public class bigint () {int [] arrone = new arrone [1000]; string = ""; public int [] arr (string s) {IntString = s; for (int i = 0; I Both of the MAP interface, implement the unique key to a specific value. The HashMap class is not classified or sorted. It allows a NULL key and multiple NULL values. Hashtable is similar to HashMap, but NULL keys and NULL values are not allowed. It is also slower than HashMap because it is synchronized. 16, the difference between Collection and Collectes. Collections is a class under java.util that contains a variety of static methods related to the collection. Collection is an interface under java.util, which is a parent interface of a variety of collections. 17. When did you use Assert. As an assertion, a statement containing Boolean expression, assuming that the expression is TRUE when this statement is executed. If the expression is calculated as false, then the system will report an AssertionError. It is used to debug purposes: assert (a> 0); // throws an assertionError if a <= 0 assertion can have two forms: assert expression1; assert expression1: expness2; Expression1 should always generate a Boolean value. Expression2 can be any expression that draws a value. This value is used to generate a String message displaying more debugging information. As default, it is disabled by default. To enable assertions while compiling, you need to use Source 1.4 tag: Javac -Source 1.4 Test.java To enable assertion at runtime, you can use the -enableassertions or -ea tag. To disable assertion at runtime, you can use the -DA or the -disableAssertions tag. To enable assertion in the system class, you can use the -esa or -dsa tag. You can also enable or disable assertions on the basis of the package. An assertion can be placed at any position that is not reached in normal conditions. As an assertation can be used to verify the parameters passing to the private method. However, assertions should not be used to verify parameters passing to the public method, as there is no matter whether it is enabled, the public method must check its parameters. However, it can be used in public methods or in a non-public method to use asserts to test the post condition. In addition, the assertion should not change the status of the program in any way. 18. What is GC? Why do you have a GC? (Foundation). GC is a garbage collector. Java programmers don't have to worry about memory management because the garbage collector will automatically manage. To request garbage collection, one of the following methods can be called: system.gc () runtime.Gcuntime (). GC () 19, string s = new string ("XYZ"); create a few String Object? Two objects One is "XYX", one is a reference object S with "XYX". 20, Math.Round (11.5) Is Math.Round (-11.5) equal to? Math.Round (11.5) Return (long) 12, Math.Round (-11.5) Return (long) -11; 21, Short S1 = 1; S1 = S1 1; What is wrong? SHORT S1 = 1; S1 = 1; What is wrong? SHORT S1 = 1; S1 = S1 1; wrong, S1 is SHORT type, S1 1 It is int type and cannot be explicitly converted to a Short type. Can be modified to S1 = (Short) (S1 1). Short S1 = 1; S1 = 1 is correct. 22, SLEEP () and WAIT () What is the difference? The favorite SLEEP () method of making thread is to stop the thread to stop a period of time. After the SLEEP time interval is full, the thread does not necessarily resume it immediately. This is because at that moment, other threads may be running and are not scheduled to give up execution, unless (a) "wake up" thread has higher priority (b) that is running because of other reasons. Wait () is a thread interaction if the thread issues a wait () call, the thread is suspended, the object is adjusted to the waiting state until it is awake or waiting time. 23. Is there a reserved word in Goto? Goto? Java in Java, not used in Java. 24. Is there a length () method for arrays? String has a length () method? The array does not have Length () method, with the properties of the length. String has a length () method. 25, the difference between overload and Override. OverLoaded method can change the type of return value? Override Overriding and overload overloading is a different manifestation of Java polymorphism. Overriding Overriding is a manifestation of polymorphism between parent class and subclasses, and overloading overloading is a manifestation in a class. If a method is defined in the subclass with the same name and parameters as its parent class, we say that this method is overriddled. When the subject of subclass uses this method, the definition of the subclass will be called. For it, the definition in the parent class is like "shielded". If a plurality of the same names are defined in a class, they or have different parameters or different parameter types, called overloading. The way OVERLOADED is to change the type of return value. 26, the elements in Set cannot be repeated, then what method is used to distinguish whether it is repeated? Is it == or equals ()? What is the difference? The element in Set is not repeated, then use iterator () The method is distinguished from whether it is repeated. Equals () is the judgment of whether two SETs are equal. Equals () and == Method Decide whether the reference value points to the same object Equals () override in the class, which is the true value of the content and type of two separate objects. 27, give me a Runtime Exception you most often. ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFORMatException, SecurityException, What is the difference between systemException, undeclaredthrowableexception, unmodifiableteextException, unsupportedOperationException 28, error and exception? Error indicates a serious problem that recovery is not impossible but very difficult. For example, memory is overflow. It is impossible to expect the program to handle this situation. Exception represents a design or implementation problem. That is, it means that if the program runs normally, it will never occur. 29, List, SET, MAP inherits from the Collection interface? List, SET is MAP is not 30, what is the difference between Abstract Class and Interface? The presence of a declaration method does not implement its class called an abstract class (Abstract Class), it Used to create a class that reflects certain basic behavior and declares the class for this class, but cannot implement this class in this class. An instance of the Abstract class cannot be created. However, you can create a variable, which is an abstract class and let it point to an instance of the specific subclass. There is no abstract constructor or abstract static method. Subclasses of the Abstract class provide implementation for all abstraction methods in their parent class, otherwise they are also abstract classes. Instead, this method is implemented in the subclass. Other classes that know their behavior can be implemented in the class. Interface is a variant of an abstract class. In the interface, all methods are abstract. Multiple inheritance can be obtained by achieving such an interface. All methods in the interface are abstract, no probabilities. The interface can only define the Static Final member variable. The implementation of the interface is similar to the subclass, except that the implementation class cannot inherit behavior from the interface definition. When the class implements a special interface, it defines the method of all such an interface (that is, the program body is given). Then, it can call the interface to call the interface on any object of the class of the interface. Because there is an abstract class, it allows the interface name as the type of reference variable. The usual dynamic cable will take effect. The reference can be converted to an interface type or a slave interface type, and the InstanceOf operator can be used to determine whether an object is implemented. 31. Is Abstract to Method to be static, whether it is Native to Native, can you be synchronized? (Concrete Class)? Interface can inherit the interface. Abstract classes can be implemented, whether abstract classes can inherit physical classes, but provided that the entity class must have a clear constructor. 33. Starting a thread is RUN () or start ()? Starting a thread is to call the start () method so that the virtual processor represented by the thread is running, which means it can be scheduled and executed by the JVM. This doesn't mean that the thread will run immediately. The Run () method can generate a flag that must be exited to stop a thread. 34. Is the constructor can be inherited by the Override® constructor constructor, so Overriding cannot be overridden, but Overloading can be overloaded. 35, can you inherit the String class? The String class is not inherited by the final class. 36. After a thread enters a synchronized method of an object, other methods of other threads can enter this object? No, one Synchronized method of an object can only be accessed by one thread. 37, Try {} has a Return statement, then the Code keeping in the finally {} after this try, will not be executed, when is executed, before returnome or after it will be executed, execute before return. 38. Program: 2 multiplied by 8 equals with 8 equals? Programmers with C background particularly like to ask this question. 2 << 3 39, the two object values are the same (x.equals (y) == true), but there is a different Hash code, this sentence is wrong? No pair, there is the same haveh code. 40. After an object is passed as a parameter to a method, this method can change the properties of this object and return the resulting result, then here is the value delivery or reference delivery? It is a value transfer. The Java programming language is only passed by the value. When an object instance is transmitted to the method as a parameter, the value of the parameter is a reference to the object. The content of the object can be changed in the called method, but the reference to the object will never change. 41. If SWTICH can act on Byte, whether it can act on long, whether it can act on String? Switch (expr1), EXPR1 is an integer expression. Therefore, the parameters passing to the Switch and the CASE statement should be int, short, char or byte. Long, String can not work on SWTICH. 42. Program: Write a Singleton. The main role of the Singleton mode is to ensure that only one example exists in a Java application. General Singleton mode usually has several forms: the first form: Define a class, its constructor is private, it has a state of static private, instantoneation, and GetInstance through a public Method Get a reference to it, then calls it. Public class singleton {private singleton ()} // define one instance in itself, is it very strange? / Note This is private only for internal calling private static singleton instance = new singleton (); // here provides a static method for external access to this Class, you can directly access public static singleton getInstance () {return instance;}} The second form: public class singleleton {private static singleleton instance = null; public static synchronized singleton getInstance () {// This method is improved above, do not have to generate an object each time, only the first time // Generate an instance and improve efficiency! IF (instance == null) instance = new start;}} Other forms: Define a class, its constructor is private, all methods are static. It is generally considered that the first form should be more secure Some HashTable and HashMap HashTable inherited from the Dictionary class, and HashMap is a real-time Map Interface of the Java 1.2 introduced HashMap allows NULL as a key or value of the entry, and HashTable is not allowed. That is, Hashmap removes the Hashtable's Contains method, changed to ContainSvalue and Containskey. Because the Contains method is easy to cause misunderstandings. The biggest difference is that the HashTable method is Synchronize, and HashMap is not, when accessed HashTable, does not need to be synchronized for its method, and HashMap must provide external synchronization. Hash / rehash algorithms used by HashTable and Hashmap are probably, so performance will not have a big difference. 43. Describe the principle mechanism of the JVM load Class file? 44. Example illustrates a typical garbage collection algorithm? 45. Use the Java to write the binary algorithm to implement the addition of data to form a binary tree function, and print it in a preface. 46. Please write a Java program to implement the thread connection pool function? 47. Given a C language function, require implementation to call in the Java class. 48, a piece of code is implemented after the console inputs a set of numbers, after being sorted in the console output; 49, list all files under a folder; 50, call the system command to delete the file operation; 51, achieve A character is read in a file; 52, list some of the control flows; 53, what states? 54. Writing a server-side program implementation is displayed on the client input character and displayed on the console until "end" is input, let you write the client's program; 55, scope public, private, protected, and do not write Difference A: The difference is the following: Scope Current class Package children's grandson class other package public √ √ √ √ protected √ √ × × Friendly √ √ × × private √ × × × Non-write time defaults to Friendly 56, ArrayList and Vector Difference ARRAYLIST and Vector mainly from the second aspect. I. Synchronization: Vector is a thread safe, that is, ArrayList is unsafe, not synchronous Data growth: When you need to grow, Vector default growth is the original training, and ArrayList is half a half of Hashmap and HashTable mainly from three aspects. I. Historical reasons: HashTable is an implementation of the old Dictionary class. Hashmap is an implementation of the MAP interface introduced by Java 1.2. Synchronism: HashTable is the thread security, that is, HashMap is not safe. , Not synchronized three. Value: Only HashMap allows you to use null values as a key or value 57 of a table, can CHAR type variables Can CHAR type variables? Why? A: It is possible to define a Chinese Because Java is encoded in Unicode, a char accounts for 16 bytes, so a Chinese is no problem 58. There are several implementation methods for multi-threading. What is it? Synchronize several implementation methods, what? A: Multi-thread has two implementation methods, which are two kinds inherited the THREAD class and implementation of the implementation of Runnable interface synchronization. Synchronized, WAIT and Notify59, garbage collection mechanism, how to optimize the program? I hope everyone will make up, thank you 60 Float Float f = 3.4 is it correct? A: incorrect. The accuracy is inaccurate, should be converted with mandatory type, as shown below: float f = (float) 3.4 61, introduce the Collection Framework in Java (including how to write your own data structure)? A: Collection Framework as follows: Collection ├List │├ LinkedList │ ├ARRAYLIST │ ├Stack └SET MAP HashTable ├Shmap └weakhashmap Collection is the most basic set interface, a Collection represents a group of objects, Elements Map provides key to value map 62, Abnormal handling mechanism, event mechanism in Java? 11. Proffles and inheritance in Java? I hope everyone will make up, thank you 63, abstract class and interface? A: Abstract class and interface are used for abstraction, but the abstract class (Java) can have its own partial implementation, and the interface is completely an identifier (both multiple inheritance functions). Program: 1. Now enter N numbers, separately, separate; then select liter or descending order; click on the submit button to display what is sorted by another page, the result is, providing a reset answer (1) public static string [] splitstringBycomma (String "splitstringbycomma (STRING" Source) {if (source == null || Source.trim (). Equals (")) Return Null; StringTokenizer Commatoker = New StringTokenizer (Source,", "); String [] Result = new string [commatoker.countTokens (); Int i = 0; while (commatoker.hasmoretoKens ()) {result [i] = commatoker.nextToken (); i ;} return result;} loop traversing string array integer.parseint (String s) becomes int Type constorgented int array arrays.sort (int [] a), an array ascending order can start output from the tail 2. The amount converted, the amount of the Arab figures converted into Chinese traditional forms such as (¥ 1011) -> (1 thousand and one yuan) output. 3, the execution order of the class is generally a choice question, ask you how to print it? A: Parent class: package test; public class fatherclass {public fatherclass () {system.out.println ("FatherClass Create ");}} subclasses: package test; import test.FatherClass; public class ChildClass extends FatherClass {public ChildClass () {System.out.println (" ChildClass Create ");} public static void main (String [] args) {FatherClass fc = new FatherClass (); ChildClass cc = new ChildClass ();}} the output:? C:> java test.ChildClass FatherClass Create FatherClass Create ChildClass Create4, the internal implementation class a: the following sample code: package test ; public class OuterClass {private class InterClass {public InterClass () {System.out.println ( "InterClass Create");}} public OuterClass () {InterClass ic = new InterClass (); System.out.println ( "OuterClass Create ");} public static void main (String [] args) {OuterClass oc = new OuterClass ();}} The output: C:> java test / OuterClass InterClass Create OuterClass Create a further example: public class OuterClass {private double d1 = 1.0; // INSERT CODE Here} you need to inser T An Inner Class Declaration At Line 3. Which Two Inner Class Declarations Are Valid? (Choose Two.) A. Class Innerne {Public Static Double Methoda () {Return D1;}} B. Public Class Innerone {static double methoda () {Return D1;}} C. private class innerone {Double Methoda ( ) {RETURN D1;}} D. Static class innerone {RetURN DouBLETHODA () {RETURN D1;}} E. Abstract Class Innerone} E. Abstract Class Innerone};} The description is as follows: 1. Static internal class can have a static member However, non-statically internal classes cannot have static members. Therefore, A, B is wrong. The non-static member of the static internal class can access the external class static variables, and the non-static variables of the external class are not accessible; RETURN D1 error. Therefore, D is not three. Non-static members of non-static internal classes can access unstatic variables of external classes. Therefore, C is correct. The answer is C, E 5, Java communication program, programming questions (or question and answer), programming, read servers, and write to local display with Java Socket A: Server side program: package test; import java.net *; import java.io. *; public class Server {private ServerSocket ss; private Socket socket; private BufferedReader in; private PrintWriter out; public Server () {try {. SS = New ServerSocket (1000); while (True) {socket = ss.accept (); string remoteip = socket.getinetaddress (). gethostaddress (); string remoteport = ":" socket.getlocalport (); system.out .println ("A Client Come In! IP:" Remoteip Remoteport); IN = New BufferedReader (New InputStreamReader (Socket.GetinputStream ()); string line = in.readline (); system.out.println ("Cleint Send IS: line); OUT = New PrintWriter (socket.getputstream (); OUT .println ("Your Message Received!"); out.close (); in .close (); socket.close ();}}} catch (ooException e) {Out.println ("WRONG");}} public static Void Main (String [] args) {new server ();}}; client endpress: package test; import java.io. *; import java.net. *; Public class client {socket; buffredreader in; printwriter out; public client () {try {system.out.println ("try to connection 127.0.0.1:10000); socket = new socket (" 127.0.0.1 ", 10000); System.out.println ( "! The Server Connected"); System.out.println ( "Please enter some Character:"); BufferedReader line = new BufferedReader (newInputStreamReader (System.in)); out = new PrintWriter (Socket.getputStream (), true); out.println (line.readline ()); in = new buffreme (new input.getinputstream ()); system.out.println (In.Readline ()); Out.close (); in.close (); socket.close ();} catch (ooException e) {outputln ("wrong");}} public static void main (String [] args) {new client );}}; 6, use Java to implement a method of sequencing, Java classes (two)? As in the Collection framework, what kind of interface is to be achieved? A: Sort by the insertion method is as follows Package Test; import java.util. *; Class insertsort {arraylist al; public insertsort (int Num, int mod) {al = new arraylist (num); random rand = new random () System.out.println ("The ArrayList Sort Before:"); for (int i = 0; i ((Integer) Al.Get (j)). INTVALUE ()> = Tempint.intValue ()) {al.add (j, tempint); maxSize ; system.out.println (al.tostring ()); break }}}} System.out.println ("The arraylist sort after:"); for (int i = 0; i