Java Basics Summary
1 、--What are the features of the Java language?
Simple object-oriented cross-platform multithreading robustness security garbage collection mechanism
2. How do I compile and execute Java files? What are the commands for generating help documents?
Compiling: Javac file name
Execution: Java class name
Generate Help document Javadoc file name
3. What is the workflow of a virtual machine?
Write source files (*.java)------compiled into *.class bytecode files------class load--------bytecode check----interpreter----operating system.
4. How to write the Main method?
public static void Main (string[] AAA) {}
Static public void Main (String sss[]) {}
5. What is an identifier? How many identifiers are there? What are the naming rules for identifiers?
Any place that can be named is called an identifier. We can use identifiers to name classes, methods, and variables.
There are two types of identifiers: System identifiers (keywords) and user identifiers.
Identifier naming rules: Letters, numbers, underscores, and $. Cannot start with a number.
6. What are the basic data types in Java? How many bytes each? What are the reference data types in Java? What is the difference between a base type and a reference type?
Java basic data type, the variable itself holds the data. A byte (1) value is -128~127. Short (2), int (4), Long (8), float (4), double (8), char (2), Boolean (1)
The Java reference type, where the variable holds the address of the object. class, array, interface.
The base type holds the specific data, and the reference type holds the address of the object
7. What is the encoding for char types in Java?
Unicode
8. What are the three elements of a variable?
Variable type variable name variable value
9. How many comments are there in Java?
Single-line Comment
/* * * Multi-line Comment
/** */Documentation comments
10. What are the key words for defining constants?
Final
11. What is an object? What is a class? What are the relationships between objects and classes?
An object is an entity that exists with explicit characteristics and behavior.
A class is a collection of sets of objects that have the same characteristics and behavior.
A class is an abstraction of an object. An object is an instance and a concrete representation of a class.
12. What kinds of variables are divided by scope? What do I need to be aware of when using local variables?
Local variables, member variables (attributes), static variables (class variables)
Note Before using local variables: 1, variables must be initialized 2, scope 3, local variable modifiers can only be default, or final
13. What is the difference between a static variable and a member variable? How should I call it?
Member variables are subordinate to the object and are part of the object and placed in the heap.
Static variables are shared by many objects and placed in data segments.
Member variables are object-specific, independent of each other, and change the value of an object member variable without affecting other objects.
Static variables are object-shared, and when an object is changed, all objects are affected.
Static variables are generated when the class is loaded, the load time precedes the object, and the member variables are loaded when the object is produced. Therefore, the static method cannot directly access the member method.
Member variables are called through the object name. Member variables
Static variables are called through the object name. Static variable class name. Static variable
14. What kind of object does garbage collection GC recycle?
Reclaims objects that are not pointed to by a variable.
15. What is a package? What is the purpose of the package? How do I import a class from another package? What kind of class does not need to be imported?
A package is a folder. Packages can be used to organize related classes and to make information hidden.
The full path of the import class; (package name + class name)
The classes and java.lang.* in this package do not need to be imported for direct use.
16. Can static methods invoke member methods or properties directly? Why?
No way. Static stuff loads the time before the object.
17. What is passed and returned when the object is passed and returned?
Reference.
18, what is the construction method? What is the function of the construction method?
The method name and class name of the constructor method are the same, and there is no return type.
Role: 1, allocating space for objects
2. If the class does not load, the class is loaded.
3. Initialize member variables
4. Returns a reference.
19. How many ways do you create objects?
New class name (); Reflection: Class object. newinstance () Clone (Via Object Clone ())
Deserialization (call ObjectInputStream in ReadObject ())
20, this and super each represent what meaning?
This represents the current object. Super represents the parent class object.
21. How are arrays defined? How do arrays, strings, and collections have their respective lengths?
int[] I = new Int[3]; Int[] I = {A-I};
Array Length: Length property
String Lengths: Length () method
Collection Length: Size () method
22. What are the characteristics of arrays?
1, the array is a continuous space, through the subscript access elements, subscript starting from 0, the maximum subscript is the length-1;
2. The elements of an array are variables, and the type of the variable is the type that defines the array.
3. Elements of an array are initialized when they are created. int----0 Double----0.0 reference type----NULL
4, the length of the array can not be changed.
23. The difference between private attribute +get/set method and public property
The private property +get/set method, which can validate the data legitimacy before setting the property value, cannot be done by the public property.
The private property +get/set method allows you to delete a Get or set method, make the property read-only or write-only, and the public property cannot.
24. What are the key words for inheritance? Subclass inherits the parent class, how should the first sentence of the construction method be written?
Inheritance uses the extends keyword. The subclass inherits the parent class, and the first sentence of the constructor method is super (), which produces the parent class object and extends the methods and properties of the subclass on the parent class object.
25. What is the difference between rewriting and overloading? What are the requirements for rewriting?
Overloads occur in the same class, with the same method name, with different parameter lists (the type of the parameter, the number of arguments, the order of the parameters), and the return type.
Overrides occur between the parent class and the child class. Method names are the same, parameter lists are the same, and return types are the same. The access modifier class is greater than or equal to the parent class, and the exception that is thrown by the subclass is less than or equal to the parent class. Subclasses override the method of the parent class, and invoke the method overridden by the subclass in preference.
26. Can a class in Java inherit multiple classes at the same time? What is the parent class for all classes?
No, a class can inherit only one root in Java, and the parent class of all classes is object.
27. Can the construction method inherit? Can the construction method be overloaded?
The construction method cannot inherit, but it can be called by the quilt class. The construction method can be overloaded.
28. What is the difference between final, finally and finalize?
Final can modify classes, methods, and variables. Modifies the class to indicate that the class cannot be inherited. A modification method that indicates that the method cannot be overridden by a quilt class. A modifier variable indicates that the variable is a constant and the content cannot be changed.
Finally is a block of code that executes whenever an exception is handled, whether or not an exception occurs. Generally used for resource recovery.
Finalize is the method defined in object. The method is executed before the object is garbage collected.
29. What are the access modifiers? What is the scope of their respective scopes?
Private (privately) can only be accessed in this class
The default in this package is to access
Protected (protected Class) subclasses of this package and different packages can access
Public all classes are accessible.
30. What is an internal class? What is the name of the inner class file?
An inner class is another class that is defined in a class. An inner class is equivalent to an attribute of an external class, and can have public, private, protected, static. Its production must depend on the object of the outer class.
The Inner class classes file names the outer class name $ internal class name. class
31, what is polymorphic? What are the characteristics of polymorphism?
Polymorphism means that a parent class variable can be used to point to a subclass object, and an interface variable can be used to point to an implementation class object.
Polymorphism characteristics: The same behavior of different manifestations, you can dynamically bind the behavior of subclasses.
32. What are the object-oriented features?
Inheritance, encapsulation, polymorphism, abstraction
33. What is abstract class? What is an abstract method? What are the keywords that define abstract classes?
If a method is defined, only the method definition, no method implementation, this method is called abstract method, the class with abstract method is called abstract class. Abstract classes cannot be instantiated directly. The keyword that defines the abstract class is abstract
34, how to define the interface? What keywords are used to implement the interface? What does a class implementation interface have to do?
Interface definition with interface.
Implement interface with implements
A class implements an interface and must implement all the abstract methods in the interface, otherwise the class can only be an abstract class.
35. What are the method modifiers defined in the interface? What are the variable modifiers defined in the interface?
The method modifier in the interface is public abstract
The variable modifier in the interface is public static final
36. What is the difference between an abstract class and an interface?
1, the abstract class can have the method definition (abstract method), but also can have the method implementation (concrete method). There can only be definitions of methods in the interface.
2, the variables in the abstract class are attributes, and the variables in the interface are public static final
3, abstract class can only be inherited by a single, and interface can be implemented more.
37. What is the API structure of the exception? What is the difference between error and exception?
Throwable parent class, below two subclasses, error (errors, can catch, cannot handle) and exception (exception, can capture, can handle)
38. What is the order of exception execution? If there are return,finally in the try block, will it execute?
Executes the try block first, executes it sequentially, and, if there is an exception, goes to the catch block to execute while aborting the other code in the try block. The finally content is executed regardless of whether there is an exception. If there is a return,finally in the try block or catch block, the same will be done before jumping out of the method.
39. Will finally be executed at any time?
No, it does not execute when the virtual machine shuts down. System.exit (0);
40. What is the difference between throw and throws?
Throw is a statement that shows the throw exception object throw new Exception ();
Throws is a method modifier that means that the method might throw an exception, and when called, it needs to handle the exception thrown by the method.
41, the exception is divided into several? How to differentiate?
Exceptions are divided into compile-time exceptions and run-time exceptions. Compile-time exception, must be processed, or the compilation will not pass. Run-time exceptions can be handled, not handled, and all run-time exceptions are runtimeexception subclasses.
42, how to get the current working directory?
System.getproperty ("User.dir");
43. What is the difference between string x = "abc" and string x = new String ("abc")?
String x = "abc". X points to a string constant in the data segment.
string x = new String ("abc"); X points to the string object in the heap. However, the object must be a template with the corresponding string constant.
44. What is the difference between string and StringBuffer?
String has an attribute that is not variable in length, and when added, deleted, replaced, a new object is created.
StringBuffer is a buffer object that does not produce new objects when added, deleted, and replaced.
45. How do I convert a string to a basic data type?
int x = Integer.parseint ("23");
Double x = double.parsedouble ("23.3");
46. How do I format the Date object for "2011-12-10" output? How do I convert a "2011-12-10" string to a date type?
SimpleDateFormat s = new SimpleDateFormat ("Yyyy-mm-dd");
String str = s.format (new Date ());
Date date = S.parse ("2011-12-10");
47. What are the contents of the JavaBean specification?
1, there is a common non-parametric construction method.
2, the private property plus the Get/set method to access and set.
3, the object is serializable.
48. What is reflection?
Reflection is at compile time, it is unclear which class should be loaded, and the loading of the class is performed at runtime. By reflection I can load, detect, and self-audit classes.
49. How to get the class object? How can I use class objects to produce objects of this class?
Class name. class object name. GetClass () class.forname ("Full Path to Class")
Class object. newinstance ();
50. What are the differences between threads and processes?
Processes have their own separate memory space, which consumes memory as soon as the process is turned on. The thread is the sequential control flow inside the process. Multiple threads share a process memory space.
51. How many ways are there to create threads? How do I start a thread? What is the difference between calling start () and calling run ()?
Create thread: 1, inherit the thread class, rewrite run () 2, implement Runnable interface, implement run ().
Start thread: Start ();
Starting a thread with start, a new thread is generated outside the main thread, and multiple tasks are executed concurrently. The direct call to run () does not produce a new thread.
52, the thread has several states?
New ready run death sleep wait pending blocking
53. What is thread priority? What are the levels?
When two or more two threads are required to start at the same time, a high priority thread takes precedence over the use of the CPU. Priority is divided into 10 levels, and the higher the number, the higher the priority level.
54. What is thread synchronization? What is the result of synchronization?
Thread synchronization refers to the fact that when two or more threads access the same resource at the same time, in order to secure the data, only one thread is allowed to access it at the same moment.
Thread synchronization can cause 1, data security 2, and inefficiency.
55. What is the difference between wait and sleep?
1. Sleep is defined in thread, and wait is defined in object.
2, wait can only be placed in the synchronization method or synchronization block, and sleep can be placed in any location.
3. Wait will release the object lock, and sleep will not.
4. Wait requires the wake-up thread to continue execution, and sleep resumes automatically after the sleep has ended.
56. What is the function of the set? What is the API structure of the collection framework?
The function of a set is to store, retrieve, manipulate, and transmit data.
The collection framework is divided into: interface, implementation class, algorithm.
Interface: Collection for parent interface, below two sub-interfaces: List, Set, plus map interface
57. What are the characteristics of List, set, and map sets?
List features: linear, elements can be repeated
Set features: elements cannot be duplicated
Map features: A key-value pair, an element containing two objects. Key cannot be duplicated.
58. How are the collection elements added? How do I delete it? How do I traverse?
Added: Add () put ()
Remove: Remove ()
Traverse:
1, for (int i =0;i<list.size (); i++) {
Object obj = List.get (i);
}
2, Iterator it = List.iterator ();
while (It.hasnext ()) {
Object obj = It.next ();
}
3, for (Object obj:list) {
}
59, the list interface realization class ArrayList, Vector, LinkedList difference? The difference between HashMap and Hashtable?
ArrayList the bottom layer is implemented by an array. is a continuous space, traverse, tail append fast, intermediate insertion, deletion speed is slow.
The bottom of the vector is also implemented by arrays. is a thread-safe class.
LinkedList is a discontinuous space, the middle insert, the deletion speed is fast, the traverse speed is slow.
HashMap allow null keys and null values, thread is unsafe. Hashtable does not allow NULL keys and null values, thread safety.
60, how to sort the collection?
Collections.sort (List,comparator c);
61. What is the difference between AWT and swing?
AWT is building components using the style of the operating system, which shows inconsistent styles across platforms.
Swing is a separate component that is consistent across platform styles.
62. What are the common layout managers of GUI?
Absolute layout, border layout, streaming layout, grid layout
63. How do I add an event?
Determine the event source, determine the listener (implement listener Interface) registration (establish the connection between event source and listener)
64, the flow according to the input and output direction divided into several? What is the relative?
Streams are divided by the input and output direction, which is called the read stream when the data is read from the data source to memory, as opposed to memory. When data is written from memory to the data source, it is called a write stream.
65, the flow according to the content of the transmission of several? What are the respective parent classes?
Streams have byte streams, stream of characters, and object flows in accordance with the transmitted content. But its essence is byte stream. Character stream and object flow are encapsulated on a byte stream basis for better manipulation of characters and objects.
Parent class for Byte stream: InputStream and OutputStream
The parent of a character stream: Reader and writer
66. What happens if the file does not exist when the flow is being manipulated? What happens if the stream doesn't close?
When the flow is manipulated, if the file does not exist, for the read stream, the file is thrown and the exception is not found. For a write stream, a new file is created. If you do not close the stream when it is finished, the memory resource is wasted. And for write streams, it is possible to write data if the stream is not closed or flushed.
67. How can I tell if a file exists? How do I create a directory? How do I know how many files are in a directory?
Use exists () in the file class to determine whether the files exist.
Create a new directory: MkDir ();
List files in directory: Listfiles ();
68. What is Object serialization? How do I implement object serialization?
When you need to transfer objects, because the data in the object is large, you need to break the object into a sequence of bytes to facilitate transmission. This process is called serialization. When you arrive at your destination, you need to restore the sequence of bytes to an object called deserialization.
At this point, the object that needs to be serialized must implement the Java.io.Serializable interface
69, the TCP/IP protocol is divided into several layers?
TCP/IP is divided into four tiers: application layer, Transport layer, network layer, network interface layer
70. What is a port? What are the common ports?
A port is a channel for an application to input and output data. Each application will have a fixed port.
Common ports: Telnet protocol: ftp:21 smtp:25 http:80
71. What is the difference between TCP and UDP? Mastering the TCP programming process.
TCP is a more reliable transport protocol, providing three handshake mechanism, if the information is lost or consumed in the transmission, will require the sender to resend, to ensure the integrity of data transmission.
UDP is a less reliable transport protocol that does not require the sender to resend when the information is lost or consumed in transit. The advantage is that speed is fast.
72. What is XML? What is the XML declaration? What is the XML comment?
XML is called an extensible Identity language that describes objects in the same way as tags and child tags.
Declaration <?xml version= "1.0" encoding= "Utf-8"?>
Notes <!---->
73. What are the provisions of a well-formed XML?
1, must have a statement
2. There is only one root element
3. Case sensitivity
4. Attribute must be quoted
5. Sign in pairs appear
6. Tags should be nested correctly.
7. Empty Mark to close
74. What is the difference between well-formed XML and valid XML?
In addition to the XML Basic specification, valid XML satisfies the element rules defined by the DTD and schema. Valid XML must be well-formed XML, but well-formed XML is not necessarily valid.
75. What is the difference between DOM and sax?
The DOM is a tree-like set of APIs that can be read to write to, random access to elements in the XML, and large documents that consume more memory.
Sax is a set of event-based APIs. The memory is small, can only read cannot write, cannot randomly access elements, the document can only traverse once.
76. When are static blocks and instantiation blocks executed separately?
Static blocks are executed when the class is loaded and executed only once. The instantiation block executes when the object is produced. Each time an object is generated, it executes once and executes after super ().
77, what is a pair of one or one-to-many, many-to-many?
A pair of one finger is a master table record corresponding to a record from the table. One-to-many refers to a master table record that corresponds to multiple entries from the table. Many-to-many refers to a main table record corresponding to a number of records from the table, while one from the table records also corresponds to a number of main table records, through the intermediate table to describe the many-to-many relationship.
78. What are the integrity of the database?
Entity integrity: Each record must be distinguished, and there cannot be an identical record. Implemented by primary KEY and UNIQUE constraint
Domain integrity: Ensure that the values for each column are valid. Implemented by default constraints, non-null constraints, and CHECK constraints
Referential integrity: guarantees that the foreign key from the table must reference the primary key of the primary table. Implemented with FOREIGN KEY constraints
User-defined integrity: User-defined rules
79, what is the primary key, what are the characteristics of the primary key?
A primary key is a column that identifies two records in a table that cannot be exactly the same, and it has two features: non-null and values cannot be duplicated.
80, what is the foreign key, it and foreign key constraints have what difference
A foreign key is an association that exists between a column of a table and a column in a primary table
A FOREIGN KEY constraint is a constraint on a foreign key column from a table that enforces that a foreign key from the table must refer to the primary key of the primary table. If the constraint is violated, the addition of the data to the bar is not allowed to be modified.
81, add, delete, change, check the basic SQL statement
Add: INSERT into Table name (field list) values (value)
Delete: Delete from table name where id=1
Modified: Update table name set field name = new value where id=1
Query: SELECT * FROM table name
82. The difference between delete and truncate
Delete can selectively delete records, to write log files, and to roll back deleted records
Truncate can only empty all records in the table, do not write log files, deleted records can not be rolled back, but the execution is high efficiency.
83. What are the key words for excluding duplicate records? How can I limit the number of rows that are returned for query data?
DISTINCT
Select * FROM table name limit 0, 3;
84. How to query for null values
Query null value with IS NULL or is not NULL
85. What are the aggregate functions of SQL statements?
Count: Count rows sum: Calculates the sum of a single column
AVG: Calculate the average of a single column Max: Calculate the maximum value for a single column
Min: Calculates the minimum value of a single column
86. In a grouping statement, what columns can I query?
Only Group field columns and aggregate functions
87. The difference between where and having
The where is executed before grouping, so the aggregate function cannot be used. Having is executed after grouping, the result of grouping is conditionally filtered, only the aggregate function can be used.
88. Describe the execution order of SQL query statements
First step: Execute from
Step two: where conditional filtering
Step three: Group by group
Fourth step: Execute the Select projection column
Fifth step: Having conditional filtering
Sixth step: Perform ORDER by ordering
89, internal connection and outer connection difference
An inner join is the use of a comparison operator to match rows in two tables based on the values of the columns that are common to each table.
An outer join is a table data that is defined as an outer join, regardless of whether there is a match, to appear in the result.
Internal connection:
Select e.*,d.deptname from T_employee e,t_dept D where e.deptid=d.id;
Select E.*,d.deptname from T_employee E joins t_dept D on E.deptid=d.id;
External connection:
Select E.*,d.deptname from T_employee e left joins T_dept D on E.deptid=d.id;
90. How do I delete a master table record?
Because a foreign key constraint exists, the primary table record cannot be deleted if the primary table record has a reference from the table record.
There are two ways to delete a master table record:
1, Cascade Delete, first delete the main table records corresponding to all the records from the table, and then delete the main table records.
2, foreign key blank, the primary table record corresponding to all the foreign key from the table is set to NULL, and then delete the main table record.
91. Writing case WHEN statement
case where price>=1000 then ' high-priced goods '
When price>=100 and prices < Then ' mid range '
ELSE ' low-grade goods '
END
92. What is JDBC
JDBC is a set of specifications for a Java connected database. The specification defines a series of interfaces that are implemented by the database vendor and called by the user based on the interface. Users can block differences in different databases based on the interface method, regardless of which database they connect to is a set of APIs.
93. JDBC Development process
Load Driver
Establish a connection
Execute SQL statement
Close connection
94. What is SQL injection
SQL injection is when an SQL statement is executed, if the value is injected in a concatenation string, then if there are illegal characters or database keywords in the value, the execution error or incorrect execution result is caused.
95. The difference between statement and PreparedStatement
Statement is the parent interface of PreparedStatement, populating the values in the SQL statement with a concatenation of strings, so JDBC compiles SQL statements at different times, is inefficient, and tends to cause SQL injection.
PreparedStatement provides placeholder methods for setting up SQL statements, and JDBC does not recompile SQL statements, and no SQL injection is caused by any value that is treated as a string.
96. What is a three-tier architecture
Three-tier architecture: Presentation layer, business layer, persistence layer. Each layer completes the function that is fixed, the layer and the layer with the interface to do the coupling. The components of each layer can be tested individually, and when one of the components is replaced or modified, the components of the other layers are not affected.
Persistence layer: Used to complete database-related operations. With the DAO pattern, you create an entity class and a database table for mapping, which is which class corresponds to which table and which property corresponds to which column. The goal of the persistence layer is to accomplish the transformation of the object data and the relational data.
Business layer: for business processing. Takes a transactional scripting pattern. Encapsulates all the services in a single request into a single method, ensuring that all database update operations in the method succeed at the same time and fail. Partial successes are not allowed, and partial failures occur that cause data confusion.
Presentation layer: Use MVC mode. M represents the model, which is the entity class, used for the encapsulation of data and the transmission of data. V represents a view for displaying data and receiving data. C represents control, which is used to invoke business components and complete control of business processes.
97. Write a single case pattern
Public class Man {
Private Static Man m = new man ();
Private Man () {}
Public Static Man Getman () {
return m;
}
}
Java Basics Summary