1. How to Write the main method?
public static void main(String[] args) {}
2. What are the naming rules for variables?
The camper name method is used to indicate the name and meaning. It starts with lowercase letters.
Constant name: all uppercase.
Method Name: Start with a lower-case letter and name the camper.
Class Name: uppercase letters.
3. If... Else... What is the difference between the two if statements and the write operation?
If... Else... Execute only one of them,
Write two if statements, both of which must be executed.
4. Write the floating point constant directly in Java. What is the default type?
The default value is double.
double numd = 1.2222d;float numf = 1.111f;
Double numd (D/D)
Float numf (F/F)
5. What is an identifier? What is its naming rule?
Anything that can be named is called an identifier.
There are two types of identifiers: 1. System Identifiers (keywords );
2. User ID
It may consist of letters, numbers, underscores, and $ resurrection. It cannot start with a number.
6. What is a variable?
Variables are named memory space, and the value of space can be changed.
7. What are JDK and JRE respectively?
JDK is called a Java Development Tool Set, including the compiling environment, running environment, debugging environment, and basic class library.
JRE is called a Java Runtime Environment, including virtual machines, core class libraries, and health files.
8. What are the functions of try-catch-Finally three basic blocks? What is the code in catch?
The try block indicates that the Code may cause an exception.
Catch Block catch try block exception
Finally blocks are usually used to recycle resources, close connections, and clean up resources.
Try-catch-finally cannot exist independently. Try block must be followed by catch or finally
Catch or finally must be followed by a try Block
9. What are the inheritance classes and implementation interfaces respectively?
Use extends keywords to inherit
Define interface keywords for interfaces
Implements for implementing Interfaces
10. How to obtain the length of a string?
Call the length () method of the string class
String str = "nihao";int str_len = str.length();int[] num = new int[3];int num_len = num.length;
11. What are the basic data types of Java?
Int 4-byte integer
Byte 1-byte integer
Char 2-byte integer
Short 4-byte integer
Long 8-byte integer
Double 8-byte floating point
Float 4-byte floating point
Boolean
12. when an object is passed as a parameter to a method, this method can change the property of the object and return the changed result. In this case, whether it is a value transfer or a reference Transfer
Value Transfer, no reference transfer in Java
13. List at least five of the most common runtime exceptions and describe when
Ioexception is thrown when the file is not found.
Nullpointerexecption will be thrown when the object reference points to null
Arrayindexoutofboundsexecption is thrown when the array subscript is out of bounds.
Numberformatexception is thrown when the string cannot be converted to a number.
Arithmeticexception is thrown when the denominator is zero.
14. Differences between arraylist and vector
Vector is thread-safe, so the efficiency is low,
Arraylist is thread unsafe, but its efficiency is high.
15. What is the parent class of the byte stream and the primary stream in io?
The byte stream parent classes are inputstrean and outputstream.
The primary stream parent class is reader and writer.
16. What is a package? What are the benefits of defining a package?
Folder.
Benefits: 1. effectively organize related classes;
2. Information can be hidden.
17. How do I know which files are in the disk directory?
1. File object. List () method;
2. File object. listfile () method.
18. How do I obtain random integers in a certain range?
X + math. Random () * y where X is the displacement number, the minimum range is determined, Y is the amplification coefficient, and the maximum number is determined.
(X-y) * Math. randon () + Y
19. How to obtain the current working directory of Java
Use System. getproperty ("user. dir") to obtain the string address of the current working directory.
20. How can I determine whether an exception class is a checked exception or an unchecked exception?
Determines whether the current exception class is a subclass of runtimeexception. If yes, it is a runtime exception or a compilation exception.
21. How many levels does log4j have? What are them? What are the differences between levels.
Log4j has five levels:
Debug: Debug
Info: Information
Warn: Warning
Error: Error
Fatal: Crash
21. How should I access static variables and member variables?
Static variables can be accessed through objects and class names.
Member variables are accessed through objects.
public class Main {int numa = 1;static int numb = 2;void getNum() {Main main = new Main();System.out.println(main.numa + " " + main.numb + " " + Main.numb);}}
22. How to convert a string into a basic data type
Int x = integer. parselint ("32 ");
Double D = double. parsedouble (4.5 ");
23. How to center the initial position of the jframe (in different resolutions)
Form object. setlocationrelativeto (null );
24. Roles of Collections
It facilitates data storage, retrieval, operation, and transmission.
25. Can class modifiers be private, static, and protected?
Internal classes are acceptable, because internal classes are equivalent to external class attributes.
26. Will all the statements in the try block be executed? Why?
No. If an exception occurs in try, the following statement will not be executed when the exception occurs, and the Catch Block in the zone will be executed.
27. When to use inheritance and interfaces?
Use inheritance when attributes and methods need to be reused
Use interfaces when you only need to reuse methods
28. When will finally be executed?
When the virtual machine is shut down, system. Exit (0), finally content will not be executed;
29. What is a main thread?
When the main () method is executed, the main thread is generated. 1 starts first, 2 ends last.
3. Generate other subthreads
4. Recycle resources
30. What happens if the operated file does not exist during I/O Stream operations?
When the read Stream does not exist, an exception occurs when the file is not found.
When the write Stream does not exist, a file is created, but if the directory of the file does not exist, an exception is thrown.
31. What are the steps for Io stream operations?
Create stream operation flow close stream
32. What is the role of finally?
A code block that is executed regardless of whether an exception exists. It is generally used for resource recycling, such as flow shutdown and database shutdown.
34. can I access other non-synchronous methods after a thread enters a synchronization method of an object? ? When is it generally used?
Yes, but cannot access other Synchronization Methods.
33. If there is a return statement in try {}, will the code in finally {} following the try be executed? When will the code be executed?
Finally {} Only executes the code in the program itself when it is enabled.
Will be executed and executed before the method returns
35. How to start a thread? What is the difference between calling the run () method directly?
The start thread calls the start method. After a thread is started using the start method, multiple threads run simultaneously,
Run () is a common method. It does not produce new threads, but is a single thread.
36. Does the array have the length () method? Does string have the length () method?
The array has the Length attribute, and the string has the length method.
37. What is GC? Why does GC exist?
GC is called the Garbage Collector. In order to recycle the memory, it no longer uses objects and releases the memory space to avoid memory overflow.
38. What kind of results will thread synchronization bring?
1: Data Security
2: lower efficiency
39. What is thread security?
When two or more threads access the same resource, only the same time is allowed to ensure data security.
Only one thread can access this resource.
40. The server class has a while loop. Can I directly use while (true )?
Yes, but this lacks flexibility and there is no way to control the end of the loop. It is best to use the Boolean variable to control
Loop running and termination.
41. How is the Java help document generated?
Javadoc.exe
42. When must the class name and file name be consistent?
When the class is defined as public, the class name must be consistent with the file name
43. How to convert the packaging class and basic data type?
Packaging to basic 1: Packaging Class Object. xxxvalue (value); 2 direct value assignment
Basic conversion Package 1: integer = new INTEGER (90); 2 direct value assignment
44. What is the return value of the method read () in inputstream? What is read?
Read () returns int, read data
Read (byte []) returns the number of bytes currently read by Int.
45. If a class implements an interface, can it not implement all the methods defined in the interface?
Yes, but this class can only be an abstract class.
46. What are the differences between constructor methods and methods? Can constructor be overloaded or overwritten?
The constructor is the same as thunder. The constructor does not return a type and is called when an object is created.
The constructor can be overloaded and cannot be rewritten.
47. list all data types accepted in switch () brackets.
Char byte short int
48. Which of the following are common GUI layout managers?
Absolute Layout
Border layout manager
Card layout manager
Stream layout manager
Grid layout manager
49. What is the role of assertion?
An assertion is a Boolean expression. When the expression is true and the expression is false, an assertion error is thrown, which is mainly used for testing.
50. What is the difference between string and stringbuffer?
String has the character of immutable length. When adding, deleting, or modifying a string, a new object is generated.
Stringbuffer is an entity of the string class and an object of the buffer.
No new object is generated during addition or modification.
51. What is the method modifier in the interface?
Public Abstract
52. Can variables be defined in interfaces?
No, the variable modifier is public static final. Only constants can be defined.
53. Several common string Methods
String. Length () Split () substring () equals () indexof () lastundexof ()
54. How to compile and execute Java programs on the DOS interface?
Javac file name
Java class name
55. How can I create a thread?
Integration Thread class
Implement the runnable interface
56. What is the process of project development?
Market research, demand analysis, summary design, detailed design, coding, testing, and maintenance.
57. What are the characteristics of Java?
Simple, object-oriented, distributed, robust, portable, explanatory, secure, multithreading, garbage collection
58. The main method has a string [] ARGs parameter. Who will pass the value of this parameter to it.
When the Java class is executed, it is passed in by the Console
59. What character sequence set is used in Java? Can the char type be put into a text field?
UNICODE: A character set contains 2 bytes .,
Char is a two-byte Chinese character, because Chinese character is a two-byte character.
60. value range of byte
-128 ~ + 127 (-2 to the 7th Power of to2 to the 7th Power-1)
61. What are the differences between Stream submission in get and post modes?
Get and post are two methods for HTTP request Server
The get method page parameter is appended to the URL. /Login? Username = xxx
POST method. The page parameters are placed at the end of the stream.