"Java basic question" "01"

Source: Internet
Author: User
Tags modifiers set set java keywords


1. What are the aspects of object-oriented features?


A: Object-oriented features are mainly in the following areas:
-Abstraction: Abstraction is the process of constructing classes by summarizing the common features of a class of objects, including both data abstraction and behavioral abstraction. Abstractions focus only on what properties and behaviors the object has, and do not care what the details of those behaviors are.
-Inheritance: Inheritance is the process of creating a new class from an existing class to get inherited information. The class that provides the inheritance information is called the parent class (the superclass, the base class), and the class that gets the inherited information is called the subclass (derived class). Inheritance allows for a certain degree of continuity in the changing software system, while inheritance is also an important means to encapsulate the variable factors in the program.
-Encapsulation: Encapsulation is generally considered to be the binding of data and the method of manipulating data, and access to data can only be achieved through defined interfaces. The essence of object-oriented is to portray the real world as a series of completely autonomous and closed objects. The method we write in the class is a encapsulation of the implementation details, and we write a class that encapsulates the data and data operations. It can be said that encapsulation is to hide all the hidden things, only to the outside world to provide the simplest programming interface.
-Polymorphism: Polymorphism means that objects of different subtypes are allowed to respond differently to the same message. The simple thing is to invoke the same method with the same object reference but do something different. Polymorphism is divided into compile-time polymorphism and run-time polymorphism. If the method of an object is treated as a service to the outside world, then the runtime polymorphism can be interpreted as: when a system accesses the services provided by System B, System B has several ways of providing services, but everything is transparent to a system. Method overloads (overload) implement compile-time polymorphism (also known as pre-binding), while the method override (override) implements runtime polymorphism (also known as post-bind). The polymorphism of the runtime is the most essential thing for the object, and there are two things to do to achieve polymorphism:
1). Method overrides (subclasses inherit the parent class and override existing or abstract methods in the parent class);
2). Object styling (referencing the subtype object with the parent type reference, so that the same reference calls the same method will behave differently depending on the subclass object).


2, access modifier public,private,protected, and do not write (default) when the difference?


A: Members of a class do not write access modifiers by default when they are not. The default is equivalent to exposing (public) to other classes in the same package, and for other classes that are not in the same package are equivalent to private (private). A protected (protected) subclass is equivalent to exposing a class that is not a parent-child relationship in the same package as private. In Java, the modifiers of an outer class can only be public or default, and the members of the class (including inner classes) can have the four modifiers.


3. Is String the most basic data type?


Answer: No. There are only 8 basic data types in Java: Byte, short, int, long, float, double, char, Boolean, except for the base type (primitive type), and the remaining reference type (reference type). The enumeration type (enumeration type) is also a reference type.


4. Float f=3.4, is it correct?


Answer: not correct. 3.4 is a double, assigning a double type (double) to a float (float) belonging to the lower transformation (down-casting, also known as narrowing) will result in a loss of precision, so you need to force the type conversion of float F = (float) 3.4; or written in float f=3.4f;


5, short S1 = 1; S1 = s1 + 1; Is it wrong? short S1 = 1; S1 + = 1; Is it wrong?


Answer: for short S1 = 1; S1 = s1 + 1; since 1 is an int type, the result of the s1+1 operation is also an int type, which requires a cast type to be assigned to the short type. and short S1 = 1; S1 + = 1; can be compiled correctly because s1+= 1, equivalent to S1 = (short) (S1 + 1), which has an implicit coercion type conversion.


6. Does Java have goto?


A: Goto is a reserved word in Java and is not used in the current version of Java. (in the appendix to the Java programming Language, written by James Gosling (the father of Java), is a list of Java keywords with goto and const, but these two are keywords that are not currently available, So in some places it is called a reserved word, in fact, the word reserved word should have more extensive meaning, because the familiar C language programmers know that in the System class library used in the special meaning of the word or word combination is considered a reserved word)


7, what is the difference between int and integer?

A: Java is a nearly pure object-oriented programming language, but for the convenience of programming or the introduction of basic data types, but in order to be able to use these basic data types as Object operations, Java for each basic data type has introduced the corresponding wrapper type (wrapper class), The wrapper class for int is integer, and the automatic boxing/unpacking mechanism is introduced from Java 5, allowing the two to be converted to each other.
Java provides the wrapper type for each primitive type:
-Original type: boolean,char,byte,short,int,long,float,double
-Package Type: boolean,character,byte,short,integer,long,float,double
Class Autounboxingtest {
public static void Main (string[] args) {
Integer a = new integer (3);
Integer B = 3; Automatically boxing 3 into an integer type
int c = 3;
System.out.println (A = = B); False two references do not reference the same object
System.out.println (A = = c); True a automatically unboxing into int type and C comparison
}
}
Recently encountered a face test, but also with automatic boxing and unpacking a bit of a relationship, the code is as follows:
public class Test03 {
public static void Main (string[] args) {
Integer f1 = F2 = 150, F3 = F4
System.out.println (f1 = = F2);
System.out.println (F3 = = F4);
}
}
If unknown, it is easy to assume that both outputs are either true or false. The first thing to note is that F1, F2, F3, and F4 Four variables are all integer object references, so the following = = Operation compares values instead of references. What is the nature of boxing? When we assign an int value to an integer object, the static method valueof of the integer class is called. (The role of speaking valueof)
To put it simply, if the value of an integer literal is between 128 and 127, then the integer object in the constant pool is not new, and the result of F1==F2 in the above interview is true, and the result of F3==F4 is false.

8, the difference between & and &&?


The:& operator is used in two ways: (1) bitwise and; (2) Logical AND. The && operator is short-circuiting and arithmetic. The difference between the logic and the short-circuit is very large, although both require that the Boolean value on both sides of the operator is true the value of the entire expression is true. && is called a short-circuit operation because if the value of the expression on the left side of && is false, the expression on the right will be shorted out directly and will not be evaluated. Most of the time we may need to use && instead of &, for example, to verify that the user's name is not NULL and is not an empty string when validating the login, it should be written as: Username! = null &&!username.equals ("") , the order of the two cannot be exchanged, not the & operator, because if the first condition is not true, the equals of the string cannot be compared, otherwise a nullpointerexception exception will be generated. Note: Logical OR operator (|) and short-circuit or operator (| | The difference is also true.


9. Explain the usage of the in-memory stack (stack), heap, and static area.


A: Usually we define a variable of a basic data type, a reference to an object, and a field save for a function call that uses the in-memory stack space, while the object created by the new keyword and the constructor is placed in the heap space; the literal in the program (literal) is 100, "Hello" written directly And constants are placed in the static zone. Stack space is the fastest, but the stack is small, usually a large number of objects are placed in the heap space, in theory, the entire memory is not used by other processes in the space or even the hard disk virtual memory can be used as a heap space.
String str = new string ("Hello");
In the above statement, the variable str is placed on the stack, the string object created with new is placed on the heap, and the literal "hello" is placed in the static area.
Add: The newer version of Java (starting with an update to Java 6) uses a technique called escape analysis, which allows you to put some local objects on the stack to improve the performance of the object.


10, Math.Round (11.5) equals how much? How much does Math.Round (-11.5) equal?


Answer: The return value of Math.Round (11.5) is the return value of 12,math.round (-11.5) is-11. Rounding is done by adding 0.5 to the parameter and then taking the next rounding.


11, whether the Swtich can function on a byte, whether it can function on a long, whether it can function on a string?


A: Before Java 5, in switch (expr), expr can only be a byte, short, char, Int. Starting with Java 5, the enumeration type is introduced in Java, and expr can be an enum type, starting with Java 7, expr can also be a string (string), but long is not available in all current versions.


12. Calculate 2 times 8 with the most efficient method?


A: 2 << 3 (left 3 is the equivalent of multiplying by 2 by 3, and the right shift 3 is equivalent to dividing by 2 3).
Add: When we rewrite the Hashcode method for a class we write, we may see code like the following, in fact we do not understand why we use such multiplication to generate hash code (hash code), and why this number is a prime, why usually choose 31 this number? The answer to the first two questions you can Baidu, choose 31 is because you can use SHIFT and subtraction operation instead of multiplication, so as to get better performance. You may have thought about it here: * num is equivalent to (NUM << 5)-Num, the left 5 is the equivalent of multiplying by 2 by 5 and subtracting itself by the equivalent of multiplying by 31, now the VM can automatically complete this optimization.


13. Does the array have the length () method? Does the string have the length () method?


Answer: The array does not have the length () method and has the length property. String has the length () method. In JavaScript, getting the length of a string is obtained through the long property, which is easily confused with Java.


14. How do I jump out of the current multiple nested loops in Java?


A: Before the outermost loop, add a tag such as a, and then use break A; You can jump out of multiple loops. (Java supports tagged break and continue statements that are somewhat similar to goto statements in C and C + +, but like avoiding goto, avoid using tagged break and continue, because it doesn't make your program more elegant, Many times even have the opposite effect, so this grammar actually does not know better)


15. Can the constructor (constructor) be rewritten (override)?


A: The constructor cannot be inherited and therefore cannot be overridden, but can be overloaded


16, two object values are the same (x.equals (y) = = true), but can have different hash code, this sentence right?


A: No, if two objects x and y satisfy x.equals (y) = = True, their hash code (hash code) should be the same. Java for the Eqauls method and Hashcode method is this: (1) If two objects are the same (the Equals method returns True), then their hashcode values must be the same, (2) If two objects have the same hashcode, they are not necessarily the same. Of course, you may not have to do as required, but if you violate the above principles you will find that when using containers, the same objects can appear in the set set, while the efficiency of adding new elements is greatly reduced (for systems using hash storage, if the hash code conflicts frequently, the access performance will be drastically reduced).
First the Equals method must satisfy the reflexivity (x.equals (x) must return True),
When symmetry (x.equals (Y) returns True, Y.equals (x) must also return true),
X.equals (z) must also return True when transitivity (X.equals (y) and y.equals (z) return True)
Consistency (when the object information referenced by x and Y is not modified, multiple calls to X.equals (y) should get the same return value), and a reference to any non-null value x,x.equals (NULL) must return FALSE.
The tips for achieving a high-quality equals method include:
1. Use the = = operator to check if "parameter is a reference to this object";
2. Use the instanceof operator to check if the parameter is the correct type;
3. For the key attribute in the class, check whether the property of the parameter passed in object matches it;
4. After writing the Equals method, ask yourself whether it satisfies symmetry, transitivity, consistency;
5. Always rewrite hashcode when overriding equals;
6. Do not replace object objects in the Equals method argument with other types, and do not forget the @override annotations when overriding.


17. Can I inherit the String class?


A: The String class is the final class and cannot be inherited.
Add: Inheriting a string is itself a bad behavior, and the best way to reuse the string type is the association relationship (HAS-A) and the dependency (use-a) rather than the inheritance relationship (IS-A).


18, when an object is passed as a parameter to a method, this method can change the properties of the object, and can return the changed results, then this is the value of the pass or reference pass?


A: The value is passed. Method calls in the Java language only support value passing of parameters. When an object instance is passed as a parameter to a method, the value of the parameter is a reference to the object. The properties of an object can be changed during the call, but changes to the object reference do not affect the caller. In C + + and C #, you can change the value of an incoming parameter by passing a reference or transmitting a parameter. You can write code like the following in C #, but you can't do it in Java.


 
using System;
namespace CS01 {
    class Program { public static void swap(ref int x, ref int y) { int temp = x;
            x = y;
            y = temp;
        } public static void Main (string[] args) { int a = 5, b = 10;
            swap (ref a, ref b); // a = 10, b = 5; Console.WriteLine ("a = {0}, b = {1}", a, b);
        }
    }
}


Description: There is no reference in Java is very inconvenient, this point in Java 8 is still not improved, it is so in Java code is written in a large number of wrapper class (will need to be modified by the method call to the reference in a wrapper class, Then passing the wrapper object into the method will only make the code bloated, especially for developers who are transitioning from C and C + + to Java programmers.


20. The difference between overloading (overload) and overriding (override). Can overloaded methods be differentiated according to the return type?


A: The overloads and overrides of a method are implemented in a polymorphic way, except that the former implements the polymorphism at compile time, while the latter implements the runtime polymorphism. Overloads occur in a class, and methods with the same name are considered overloaded if they have different parameter lists (different parameter types, different number of arguments, or both); Overrides occur between subclasses and parent classes, and overrides require subclasses to be overridden by methods that have the same return type as the parent class, which is better accessed than the overridden method of the parent class. You cannot declare more exceptions than the parent class is overridden by the method (the Richter substitution principle). Overloads do not have special requirements for return types.


21. Describe the principle mechanism of the JVM loading class file?


A: The load of classes in the JVM is implemented by the class loader (ClassLoader) and its subclasses, and the ClassLoader in Java is an important Java Runtime system component that is responsible for locating and loading classes in class files at run time.
Because of the cross-platform nature of Java, the compiled Java source program is not an executable program, but one or more class files. When a Java program needs to use a class, the JVM ensures that the class has been loaded, connected (validated, prepared, parsed), and initialized. Class loading refers to reading the data in the class's. class file into memory, usually by creating a byte array to read into the. class file, and then produce a class object corresponding to the loaded class. When the load is complete, the class object is not yet complete, so the classes are not available at this time. When a class is loaded, it enters the connection phase, which includes validation, preparation (allocating memory for static variables and setting default initial values, basic variables 0, reference variables being null), and parsing (replacing symbolic references with direct references) three steps. Finally, the JVM initializes the class, including: 1) If the class has a direct parent class and the class has not been initialized, initialize the parent class first, and 2) Execute the initialization statements sequentially if there are initialization statements in the class. The loading of the
class is done by the ClassLoader, which includes: Launch class loader (BootStrap), extension loader (Extension), System loader (systems), and user-defined class loader (subclass Java.lang.ClassLoader). Starting with Java 2 (JDK 1.2), the class loading process takes a parental delegation mechanism (PDM). It better guarantees the security of the Java platform, in which the JVM's own bootstrap is the root loader, and the other loaders have only one parent ClassLoader. The load of a class first requests that the parent ClassLoader be loaded, and the parent ClassLoader is not loaded by its child ClassLoader. The JVM does not provide a reference to the bootstrap to the Java program. The following is a description of several class loaders:
? Bootstrap: Generally implemented with native code, responsible for loading the JVM base Core class library (Rt.jar);
? Extension:jre/ext or java.ext.dirs the class library is loaded in the directory specified by the system property, and its parent loader is bootstrap;
? System: Also called the application ClassLoader, whose parent class is extension. It is the most widely used class loader. It is the default parent loader for the user-defined loader, which records the class from the environment variable classpath or the directory specified by the system attribute Java.class.path.


22, Char type variable can not be stored in a Chinese character, why?


A: The char type can store a Chinese character because the encoding used in Java is Unicode (no specific encoding is selected, the character is used directly in the character set, this is the only way to unify), and a char type is 2 bytes (16 bits), so putting a Chinese is no problem.
Supplement: Using Unicode means that characters have different representations both inside and outside the JVM, Unicode within the JVM, and encoded when the character is transferred from inside the JVM to the outside (for example, to a file system). So in Java there are byte stream and character stream, as well as the conversion stream between character stream and byte stream, such as InputStreamReader and Outputstreamreader, these two classes are the adapter classes between byte stream and character stream, which assume the task of encoding conversion. For C programmers, it may be possible to accomplish such a conversion by relying on the characteristics of the Union (Union/Commons) shared memory.


23. What are the similarities and differences between abstract class and interface (interface)?


A: Abstract classes and interfaces cannot be instantiated, but you can define references to abstract classes and interface types. If a class inherits an abstract class or implements an interface that requires all of its abstract methods to be implemented, the class still needs to be declared as an abstract class. Interfaces are more abstract than abstract classes, because constructors can be defined in abstract classes, can have abstract methods and concrete methods, and constructors are not defined in an interface, and the methods are all abstract methods. Members in an abstract class can be private, default, protected, public, and members of the interface are all public. Member variables can be defined in an abstract class, whereas member variables defined in an interface are actually constants. Classes with abstract methods must be declared as abstract classes, and abstract classes may not necessarily have abstract methods.


24. What is the difference between static nested classes (the static Nested Class) and inner classes (Inner Class)?


A: The static Nested class is an inner class that is declared static (static), and it can be instantiated without relying on an external class instance. The usual inner class needs to be instantiated after an external class instantiation, and its syntax looks pretty weird.
Note: the creation of a non-static inner class object in Java relies on its outer class object, there is no this in the static method, that is, there is no so-called external class object, so the inner class object cannot be created, and if you want to create an inner class object in a static method, you can do this: New Outer (). New Inner ();


25. There is a memory leak in Java, please describe it briefly.


A: In theory, Java has no memory leaks due to garbage collection (GC) (which is an important reason why Java is widely used in server-side programming); However, in real-world development, there may be useless but accessible objects that cannot be recycled by GC and therefore can also cause memory leaks to occur. For example, the objects in Hibernate's session (first-level cache) are persistent, and the garbage collector does not reclaim those objects, but there may be useless garbage objects in them, which can cause memory leaks if you do not close (close) or empty (flush) The first-level cache in a timely manner.
In languages that support garbage collection, memory leaks are subtle, and this memory leak is actually an unconscious object hold. If an object reference is unconsciously persisted, the garbage collector does not process the object, nor does it handle other objects referenced by the object, even if only a few of these objects can cause a large number of objects to be excluded from garbage collection, which has a significant impact on performance. In extreme cases, disk Paging (the physical memory and the hard disk's virtual memory Exchange data) is raised, even causing outofmemoryerror.


26. Whether the abstract method can be static at the same time (static), whether it can be a local method (native), and whether it can be synchronized modified at the same time?


Answer: No. Abstract methods require subclasses to rewrite, and static methods cannot be overridden, so they are contradictory. Local methods are methods implemented by local code, such as C code, and abstract methods are not implemented and are contradictory. Synchronized is related to the implementation details of the method, and the abstract method does not involve implementation details, and therefore is contradictory to each other.


27. Explain the difference between static variable and instance variable.


A: A static variable is a variable modified by the static modifier, also known as a class variable, which belongs to a class, not to any object of the class, and a class has no matter how many objects are created, the static variable has only one copy in memory, and the instance variable must be dependent on an instance, first creating the object and then accessing it through the object Static variables can be implemented to allow multiple objects to share memory.
Add: In Java development, there are often a large number of static members in context classes and tool classes.


28. Is it possible to make a call to a non-static (Non-static) method from within a static method?


A: No, static methods can only access static members, because calls to non-static methods create objects first, and when static methods are called, they may not be initialized.


29, how to implement object cloning?

Answer: There are two ways:
?? 1). Implement the Cloneable interface and override the Clone () method in the object class;
?? 2). Implement the Serializable interface, through the serialization and deserialization of objects to achieve cloning, you can achieve true deep cloning.
Note: Clones based on serialization and deserialization are not just deep clones, but more importantly, by generic qualification, you can check that the object to be cloned supports serialization, which is done by the compiler, not by throwing an exception at run time. This scenario is significantly better than cloning an object using the Clone method of the object class. It is always better to let the problem be exposed at compile time than to leave the problem at runtime.
30. What is GC? Why do you have a GC?
A: GC is the meaning of garbage collection, memory processing is the programmer is prone to problems, forget or wrong memory recycling will cause the program or system instability or even crash, Java provides the GC function can automatically monitor whether the object exceeds the scope to achieve the purpose of automatic recovery of memory, The Java language does not provide a display action method that frees allocated memory. Java programmers don't have to worry about memory management because the garbage collector is automatically managed. To request garbage collection, you can call one of the following methods: System.GC () or Runtime.getruntime (). GC (), but the JVM can mask the displayed garbage collection calls.
Garbage collection can effectively prevent memory leaks and effectively use memory that can be used. The garbage collector is typically run as a separate, low-priority thread, and in unpredictable cases the dead or unused objects in the heap are purged and reclaimed, and the programmer is not able to call the garbage collector in real time for garbage collection of an object or all objects. In the early days of Java, garbage collection is one of the biggest highlights of Java, because the server-side programming needs to effectively prevent memory leaks, however, now the Java garbage collection mechanism has become the thing to be criticized. Mobile Smart end users often feel that iOS systems have a better user experience than Android systems, and one of the underlying reasons is the unpredictability of garbage collection in the Android system.
Add: There are many kinds of garbage collection algorithms, including: Tag clearing algorithm, copying algorithm, labeling and sorting algorithm, and collecting and retrieving algorithms. The standard Java process is both stack and heap. The stack holds the original local variables, and the heap holds the objects to be created. The basic Java platform algorithm for heap memory recycling and reuse is known as tagging and purging, but Java has improved it with "generational garbage collection." This method divides the heap memory into different areas with the Java object's life cycle, and may move objects to different areas during garbage collection:
New generation: Can be subdivided into three logical regions of Eden (Eden), from Survivor (survivor) and to Survivor, with objects preferentially stored in the new generation of Eden areas.
Eden (Eden): This is the area where the object was originally born, and for most objects, this is the only area where they exist.
Surviving area (Survivor): Objects that survived from Eden will be moved here.
Old age: The new generation of objects after several garbage collection, still survive will be stored in the old age, and large objects can not go through the new generation and directly stored in the old age
The Young Generation Collection (MINOR-GC) process is not going to touch this place. When the young generation collects objects that cannot be placed into a lifelong home garden, it triggers a full collection (MAJOR-GC), which may also involve compression in order to make enough space for large objects.
Permanent generation: The method area uses the permanent generation as the storage area, logically, the permanent generation is part of the Java heap, but is often referred to as "non-heap" (NON-HEAP) memory as a distinction. Method areas are typically used to hold information about a class (fields of classes loaded by the ClassLoader, method signatures, and so on), run constant pools (such as string constant pools), static reference variables, and so on.
JVM parameters related to garbage collection:
The initial size of the-xms/-xmx-heap/maximum size of the heap
The size of the young generation in the-xmn-heap
-xx:-disableexplicitgc-let System.GC () not have any effect
?-xx:+printgcdetails-Print GC Details
?-xx:+printgcdatestamps-Print the timestamp of the GC operation
?-xx:newsize/xx:maxnewsize-set Cenozoic size/Cenozoic maximum size
-xx:newratio-can set the proportion of Laosheng generation and Cenozoic
-xx:printtenuringdistribution-set the distribution of age of objects in Survivor's paradise after each generation of GC
-xx:initialtenuringthreshold/-xx:maxtenuringthreshold: Set initial and maximum values for the old age threshold
-xx:targetsurvivorratio: Set target usage for surviving zones

31, String s = new string ("xyz"), how many string objects have been created?


A: Two objects, one is the "xyz" of the static zone, and the other is the object created on the heap with new.


32. Is the interface inheritable (extends) interface? is an abstract class achievable (implements) interface? Can abstract classes inherit concrete classes (concrete Class)?


A: Interfaces can inherit interfaces, and multiple inheritance is supported. Abstract classes can implement (implements) interfaces, and abstract classes can inherit concrete classes or they can inherit abstract classes.


33. Can a ". Java" source file contain more than one class (not an inner class)? What are the restrictions?


A: Yes, but there can be at most one public class in a source file and the file name must be fully consistent with the class name of the public class


34, Anonymous Inner Class (anonymous inner Class) can inherit other classes? Is it possible to implement an interface?


A: You can inherit other classes or implement other interfaces, which are commonly used in swing programming and Android development to implement event snooping and callbacks.


35. Can an inner class reference a member of its containing class (an outer Class)? Are there any restrictions?


A: An internal class object can access the members of the external class object that created it, including private members.


36. What are the uses of the final keyword in Java?


A: (1) Modifier class: Indicates that the class cannot be inherited, (2) The modification method: means that the method cannot be overridden, (3) A modifier variable: Indicates that a variable can only be assigned once and the value cannot be modified (constant).


37. Point out the operation result of the following procedure.

class A { static {
        System.out.print("1");
    } public A() {
        System.out.print("2");
    }
}
class B extends A{ static {
        System.out.print("a");
    } public B() {
        System.out.print("b");
    }
} public class Hello { public static void main(String[] args) {
        A ab = new B();
        ab = new B();
    }
}


A: Execution result: 1a2b2b. When you create an object, the constructor is called in the order that it initializes the static member, then calls the parent class constructor, initializes the non-static member, and finally calls itself the constructor.


38. Conversions between data types:-How do I convert a string to a base data type? -How do I convert a base data type to a string?


A: The method Parsexxx (string) or valueof (string) in the wrapper class that calls the base data type can return the corresponding base type by connecting the base data type with an empty string ("") to get its corresponding string Another method is to call the valueof () method in the string class to return the corresponding string.


39, how to implement the reversal and substitution of strings?


A: There are many ways to write your own implementation or you can use the methods in string or Stringbuffer/stringbuilder. One common interview topic is recursive implementation of string inversion, as shown in the following code:



 
 
  public static String reverse(String originStr) {
        if(originStr == null || originStr.length() <= 1) 
            return originStr;
        return reverse(originStr.substring(1)) + originStr.charAt(0);
}
40. How do I convert a GB2312 encoded string to a iso-8859-1 encoded string?


A: The code looks like this:
String S1 = "Hello";
String s2 = new String (S1.getbytes ("GB2312"), "iso-8859-1");



"Java basic question" "01"


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.