web123456

Reverse output of strings in java

First choice congratulations on finding a job.

Now summarize some fragmentary questions that appear in the written test interview for common jobs.

String in javaReverse output

public class NiXu {
   public static void main(String[] args) {
String s ="abc";
for(int i=()-1;i>=0;i--){
((i));
}
}


}

  1. public class NiXu {
  2.    public static void main(String[] args) {
  3. String s ="abc";
  4. for(int i=()-1;i>=0;i--){
  5. ((i));
  6. }
  7. }
  8. }

1. Java Basics
1. What is the difference between JDK and JRE?

  • JDK: The abbreviation of Java Development Kit, the java development toolkit, provides the development and running environment of Java.
  • JRE: The abbreviation of Java Runtime Environment, the Java running environment, provides the required environment for Java running.

Specifically, JDK actually contains JRE and also includes compiling java source code.Compilerjavac also includes many tools for debugging and analysis of java programs. In short: if you need to run a java program, just install JRE, if you need to write a java program, you need to install JDK.
2. What is the difference between == and equals?
== For basic types, it is a value comparison, and for reference types, it is a reference comparison; while equals is a reference comparison by default, but many classes have re-estimated the equals method, such as String, Integer, etc., turning it into value comparison, so in general, equals compares whether the values ​​are equal.
3. If the hashCode() of two objects is the same, equals() must also be true, right?
No, the hashCode() of the two objects is the same, equals() may not be true.
Code interpretation: It is obvious that the hashCode() of "call" is the same as "highly" and the hashCode() is false, because in a hash table, hashCode() is equal, that is, the hash values ​​of two key-value pairs are equal, but the hash values ​​are equal, which does not necessarily mean that the key-value pairs are equal.

4. What is final role in java?

  • The class modified by final is called the final class, and this class cannot be inherited.
  • The final modification method cannot be rewritten.
  • The variable modified by final is called a constant. The constant must be initialized, and the value cannot be modified after initialization.

5. What is (-1.5) in java equal?
It is equal to -1, because when taking the value on the number axis, the intermediate value (0.5) is rounded to the right, so positive 0.5 is rounded upward, and negative 0.5 is discarded directly.
6. Is String the basic data type?
String does not belong to the basic type, there are 8 basic types: byte, boolean, char, short, int, float, long, and double, while String belongs to an object.
7. What are the classes of manipulating strings in java? What is the difference between them?
The classes that operate strings are: String, StringBuffer, and StringBuilder.
The difference between String and StringBuffer and StringBuilder is that String declares immutable objects. Each operation will generate a new String object and then point the pointer to the new String object. StringBuffer and StringBuilder can operate on the basis of the original object, so it is best not to use String when the string content is often changed.
The biggest difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe, while StringBuilder is non-thread-safe, but StringBuilder'sperformanceBut it is higher than StringBuffer, so it is recommended to use StringBuilder in a single-threaded environment, and StringBuffer in a multi-threaded environment.
8. Is String str="i" the same as String str=new String("i")?
Different because the memory allocation method is different. String str="i" way, javaVirtual MachineIt will be allocated to the constant pool; while String str=new String("i") will be allocated to the heap memory.
9. How to reverse a string?
Use the reverse() method of StringBuilder or stringBuffer.
10. What are the common methods of the String class?

  • indexOf(): Returns the index of the specified character.
  • charAt(): Returns the character at the specified index.
  • replace(): string replacement.
  • trim(): Remove blanks at both ends of the string.
  • split(): splits a string, returns a split string array.
  • getBytes(): Returns an array of byte type of string.
  • length(): Returns the length of the string.
  • toLowerCase(): Converts a string to lowercase letters.
  • toUpperCase(): Converts a string to uppercase characters.
  • substring(): Intercept the string.
  • equals(): string comparison.

11. Do abstract classes have abstract methods?
No, abstract classes do not necessarily have abstract methods.

  • Ordinary classes cannot contain abstract methods, abstract classes can contain abstract methods.
  • Abstract classes cannot be instantiated directly, ordinary classes can be instantiated directly.

13. Can abstract classes be modified using final?
No, defining an abstract class is to allow other classes to inherit. If defined as final, the class cannot be inherited, so there will be conflicts between them, so final cannot modify abstract classes.
14. What is the difference between an interface and an abstract class?

  • Implementation: Subclasses of abstract classes use extends to inherit; interfaces must use implements to implement interfaces.
  • Constructor: Abstract classes can have constructors; interfaces cannot.
  • main method: The abstract class can have a main method, and we can run it; the interface cannot have a main method.
  • Number of implementations: A class can implement many interfaces; but can only inherit one abstract class.
  • Access modifier: Methods in the interface use public modifier by default; methods in abstract classes can be any access modifier.

15. How many types of IO streams are divided into java?
According to functions, it is divided into: input stream and output stream.
By type: byte stream and character stream.
The difference between a byte stream and a character stream is that the byte stream is transmitted in 8 bits and input and output data in bytes, and the character stream is transmitted in 16 bits and input and output data in 16 bits.
16. What is the difference between BIO, NIO, and AIO?

  • BIO: Block IO synchronous blocking IO is the traditional IO we usually use. Its characteristics are simple and convenient modes and low concurrency processing capabilities.
  • NIO: New IO synchronous non-blocking IO is an upgrade of traditional IO. The client and server communicate through Channel (channel) to realize multiplexing.
  • AIO: Asynchronous IO is an upgrade of NIO, also known as NIO2, which implements asynchronous non-blocking IO. The operation of asynchronous IO is based on event and callback mechanisms.

17. What are the common methods of Files?

  • (): Detect whether the file path exists.
  • (): Create a file.
  • (): Create a folder.
  • (): Delete a file or directory.
  • (): Copy the file.
  • (): Move the file.
  • (): Check the number of files.
  • (): Read the file.
  • (): Write to the file.