java interview questions, with personal understanding answers

1. Object-oriented features:
1. Abstraction includes data abstraction and behavioral abstraction, taking out the common features of objects to form a class
2. Inheriting the inherited class as base class/superclass, and inheriting class as subclass/derived class
3. Encapsulation Use moral data or methods multiple times and encapsulate them into classes, which are convenient for repeated calls
. 4. Polymorphism Polymorphism at
compile time: method overloading (overload) to achieve polymorphism at compile time Polymorphism
at runtime: method override (override) Implement runtime polymorphism, also known as post-binding

Second, the difference between access modifiers:
public: public to all classes
private: available to the current class, unavailable to others
protected: available under the same package
Default default: public to other classes in the same package, subclasses, and unavailable to other packages

Three, String type:
String is not a basic data type, and enumeration is a reference type.
The 8 basic data types include: byte, short, int, long, float, double, char, boolean

Fourth, is float f=3.4; correct?
Incorrect. 3.4 is a double-precision number. Assigning a double-precision type (double) to a floating-point type (float) is down-casting (also known as narrowing), which will cause precision loss, so it needs to be cast to float f = (float )3.4; or as float f = 3.4F;.

Five, what is the difference between int and Integer?
public static void main(String[] args) {
Integer a = new Integer(3);
Integer b = 3; // autobox 3 to Integer type
int c = 3;
System.out.println(a == b ); // false two references do not refer to the same object
System.out.println(a == c); // true a is automatically unboxed into int type and then compared with c
}

public static void main(String[] args) {
Integer f1 = 100, f2 = 100, f3 = 150, f4 = 150; //Because the same wrapper class has all irrelevant values, but compares references

System.out.println(f1 == f2); //true The literal value is in -128~127, indicating that the same object is referenced
System.out.println(f3 == f4); //false The literal value is not in -128~ 127, the wrapper class will automatically generate a new wrapper object, all references are not the same object
}

Six, the difference between & , && is
the same: the result is the same, only return true when both sides meet the conditions.
Difference: && has a short circuit, that is, once the first expression is false, it returns false directly, and the latter is directly broken, and & will be executed before returning

Seven, is there a number that makes i + 1 < i?
If i is of type int, i+1 exceeds the largest integer, and it is negative (the largest integer is 32 bits)

Eight, how many days are there from 1900-1-1 to 2016-11-11
public static void main(String[] args){
int sum=0;
for(int year=1900;year<=2015;year++){ //because 2016 is not a full year, first count the year
if(year%4==0 && year%100!=0 || year%400==0){
sum=sum+366;
}else{
sum=sum+365;
}
}
for(int month=1;month<=10;month++){ //Because November is not full, first count October
if (month==2){
if(2016%10==0 && 2016%100! =0 ||2016%400==0){
sum=sum+29;
}else{
sum=sum+28;
}
}else{
if(month==4 || month==6 ||month==9 | |month==11){
sum=sum+30;
}else{
sum=sum+31;
}
}
}
sum=sum+11;
System.out.print("A total of "+sum+" days from January 1, 1900 to November 11, 2016");
}

Nine, what are the folders in tomcat?
bin: command to open and close the server
conf: configuration file
server.xml port
tomcat-user.xml remote user name, password
lib: jar package
logs: log
webapps: project release location

10. What is the difference between GET and POST request methods?
1. The get parameter is passed through the url, and the post is placed in the request body.
2. The parameters passed in the url of the get request are limited in length, while the post does not.
3. Get is less secure than post, because the parameters are directly exposed in the url, so they cannot be used to pass sensitive information.
4. The get request can only be url encoded, while the post supports a variety of encoding methods.
5. The get request will be actively cached by the browser, while the post supports a variety of encoding methods.
6. The get request parameters will be completely preserved in the browsing history, while the parameters in the post will not be preserved.

GET and POST are essentially TCP links, and there is no difference. However, due to HTTP regulations and browser/server limitations, they show some differences in the application process.

For GET requests, the browser will send the http header and data together, and the server responds with 200 (returning data);
for POST, the browser sends the header first, the server responds with 100 continue, the browser sends the data, and the server responds 200 ok (return data).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324834578&siteId=291194637