50-course questions and answers for Java Programmer Gold Three silver four carefully selected

Source: Internet
Author: User
Tags bitwise goto logical operators stringbuffer

Tag: cannot be inherited between its copy attribute level overrides loaded Util

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

A: Object-oriented features are mainly in the following areas:

1) Abstraction: Abstraction ignores aspects of a topic that are not relevant to the current goal in order to pay more attention to the aspects related to the current goal. Abstractions do not intend to understand all of the problems, but simply select one part of them, temporarily without some detail. Abstract includes two aspects, one is the process abstraction, the other is the data abstraction.

2) Inheritance: Inheritance is a hierarchical model of coupling classes, and allows and encourages reuse of classes, which provides a way to articulate commonalities. A new class of objects can be derived from existing classes, a process known as class inheritance. The new class inherits the attributes of the original class, which is called the derived class (subclass) of the original class, and the original class is called the base class of the new class (The parent Class). Derived classes can inherit methods and instance variables from their base classes, and classes can modify or add new methods to make them more suitable for special needs.

3) Encapsulation: Encapsulation is the process and data surrounded, access to data only through the defined interface. Object-oriented computing begins with this basic concept that the real world can be portrayed as a series of fully autonomous, encapsulated objects that access other objects through a protected interface.

4) Polymorphism: Polymorphism means that objects of different classes are allowed to respond to the same message. Polymorphism consists of parameterized polymorphism and inclusion polymorphism. Polymorphism language has the advantage of flexibility, abstraction, behavior sharing and code sharing, which solves the problem of application function with the same name.

2, Scope public,private,protected, and do not write when the difference? Infrastructure

A: The difference is as follows:

Scope current similar package descendant class other

Public√√√√

Protected√√√x

Default√√xx

Private√xxx

Defaults are default when not written.

3. Is String the most basic data type? Infrastructure

Answer: No.

4 Float type float f=3.4 is correct? Infrastructure

Answer: Incorrect precision, should be cast with coercion type, as follows: float f= (float) 3.4.

5, the statement float f=1.3; can compile pass? Infrastructure

A: No; you should cast with coercion type as follows: Float f= (float) 1.3;.

6, short S1 = 1; S1 = s1 + 1; what's wrong?

Short S1 = 1; S1 + = 1; what's wrong? Infrastructure

Answer: short S1 = 1; S1 = S1 + 1;s1+1 operation result is int type, need cast type; short S1 = 1; S1 + = 1; can be compiled correctly, automatic type promotion.

7. Does Java have goto? Infrastructure

A: Goto is a reserved word in Java and is not currently used in Java.

8, what is the difference between int and integer? Infrastructure

A: Java is available in two different types: reference type and primitive type (or built-in type);

int is the raw data type of Java, and Integer is the wrapper class provided by Java for Int.

Java provides a wrapper class for each primitive type:

Original type: boolean,char,byte,short,int,long,float,double

Encapsulation Type: boolean,character,byte,short,integer,long,float,double the behavior of reference types and primitive types is completely different, and they have different semantics. Reference types and primitive types have different characteristics and usages, including: size and speed issues, which types of data structures are stored as the default values that are specified when reference types and primitive types are used as instance data for a class. The default value of an object reference instance variable is NULL, and the default value of the original type instance variable is related to their type.

9, the difference between & and &&? Infrastructure

A:& is a bitwise operator that indicates that bitwise AND operation,&& are logical operators, representing logic and (and).

10. Brief description of logical operation (&,|,^) and condition operation (&&,| |) The difference? Infrastructure

A: The difference is mainly two points: a. The conditional operation can only operate on a Boolean type, while a logical operation may not only manipulate the Boolean type, but also manipulate the numeric type B. The logical operation does not produce a short circuit.

11. What is the difference between heap and stack? Infrastructure

A: The stack is a linear collection, its addition and deletion of elements should be done in the same paragraph, the stack is processed in a last-in, first-out way; The heap is a constituent element of the stack.

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

A: Math.Round (11.5) ==12 Math.Round ( -11.5) ==-11 round method returns the longest integer closest to the parameter, and the parameter adds 1/2 to its floor.

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

Answer: in switch (EXPR1), expr1 is an integer expression. So the arguments passed to the switch and case statements should be int, short, char, or byte. Long,string can not act on Swtich.

14, programming problems: the most efficient way to calculate 2 times 8 and so on? Infrastructure

Answer: 2 << 3.

15, there is no length () This method? Does String have the length () method? Infrastructure

A: The array does not have the length () method and has the length property. String has the length () method.

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

A: Add a label tag before the outermost loop, and then use the Break:label method to jump out of multiple loops.

17. Can the constructor constructor be override? Infrastructure

A: The constructor constructor cannot be inherited, so overriding cannot be overridden, but it can be overloaded with overloading.

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

Answer: No, there is the same hash code.

19. Can I inherit the String class? Infrastructure

A: The String class is the final class and therefore cannot be inherited.

20. The following two statements return a value of true:

A: "Beijing" = = "Beijing";

B: "Beijing". Equalsignorecase (New String ("Beijing")); "Base"

Answer: A and B.

21, 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? Infrastructure

A: The value is passed. The Java programming language has only value-passing 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 contents of the object can be changed in the called method, but the object's reference is never changed.

22, we often encountered in the Web application development process output some kind of encoded characters, such as iso8859-1, how to output a certain encoding of the string? Infrastructure

Answer: public string translate (string str) {

String tempstr = "";

try{

TempStr = new String (str.getbytes ("iso-8859-1"), "GBK");

TempStr = Tempstr.trim ();

}catch (Exception e) {

System.err.println (E.getmessage ());

}

return tempstr;

}

23. What is the difference between String and StringBuffer? Infrastructure

A: The JAVA platform provides two classes: string and StringBuffer, which can store and manipulate strings, that is, character data that contains multiple characters. This string class provides a string of values that cannot be changed. The string provided by this StringBuffer class is modified. You can use StringBuffer when you know that character data is going to change. Typically, you can use Stringbuffers to dynamically construct character data.

24, String, StringBuffer StringBuilder difference. Infrastructure

A: The length of the string is immutable, the length of the StringBuffer is variable, if you are working on the contents of the string frequently, especially when the content is to be modified, then use StringBuffer, if you need a string at the end, Then use the ToString () method of StringBuffer; thread-safe; StringBuilder is starting with JDK 5, which complements the equivalence class used by a single thread for StringBuffer class; StringBuilder classes should usually be preferred , because it supports all the same operations, but because it does not perform synchronization, it is faster.

25, the difference between overload and override. Can the Overloaded method change the type of the return value? Infrastructure

A: The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). When an object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked". If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, which is called a method overload (overloading). The Overloaded method is to change the type of the return value.

26. Define Class A and Class B as follows: "Foundation"

Class A {

int a=1;

Double d=2.0;

void Show () {

System.out.println ("Class a:a=" +a + "d=" +d);

}

}

Class B extends a{

float a=3.0f;

String d= "Java program.";

void Show () {

Super.show ();

System.out.println ("Class b:a=" +a + "d=" +d);

}

}

(1) If you have the following statement in the main method of the application:

A a=new a ();

A.show ();

What is the result of the output?

(2) If you define object B of Class B in the main method of the application:

A b=new B ();

B.show ();

What is the result of the output?

Answer: The output is:

1) Class a:a=1 d=2.0;

2) Class a:a=1 d=2.0

Class b:a=3.0 D=java Program.

27. Describe the principle mechanism of the JVM loading class file? Infrastructure

A: The loading of classes in the JVM is implemented by ClassLoader and its subclasses, and Java ClassLoader is an important Java Runtime system component. It is responsible for locating and loading classes of class files at run time.

28. Can I store a Chinese character in char type? Infrastructure

A: can be defined as a Chinese, because in Java encoding in Unicode, a char accounted for 16 bytes, so put a Chinese is no problem.

29. What is the difference between abstract class and interface? Infrastructure

A: The class that declares the existence of a method and does not implement it is called an abstract class. However, you can create a variable whose type is an abstract class that is used to create a class that embodies some basic behavior, declares a method for that class, but does not implement the class in that class. You cannot create an instance of an abstract class and point it to an instance of a specific subclass. Cannot have abstract constructors or abstract static methods. The subclasses of the abstract class provide implementations for all abstract methods in their parent class, otherwise they are also abstract classes. Instead, implement the method in the subclass. Other classes that know their behavior can implement these methods in the class. An interface (interface) is a variant of an abstract class. The new multi-inheritance can be achieved by implementing such an interface. All the methods in the interface are abstract, and all member variables are publicstatic final. A class can implement multiple interfaces, and when a class implements a special interface, it defines (that is,

The program body is given the method of all such interfaces. It can then invoke the interface's method on any object that implements the interface's class. Because of an abstract class, it allows you to use the interface name as the type of the reference variable. The usual dynamic binder will take effect. A reference can be converted to an interface type or converted from an interface type, and the instanceof operator can be used to determine whether the class of an object implements an interface.

30. What is the difference between Static Nested class and inner class? Infrastructure

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 classes need to be instantiated after the external class is instanced.

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

A: Yes, there are useless but accessible objects that cannot be recycled by GC, resulting in memory resources being consumed.

32, the abstract method can be static at the same time, whether it can be native at the same time, whether it can be synchronized at the same time? Infrastructure

Answer: No.

33. What is the difference between a static variable and an instance variable? Infrastructure

A: Static variables, also known as class variables, are common to all classes, do not depend on an object, can be accessed directly through the class name, and the instance variable must be dependent on an instance, only through the object to access it.

34. Is it possible to make a call to a non-static method from within a static method? Infrastructure

A: No, object initialization cannot be guaranteed if it contains the method () of the object.

35, when writing the Clone () method, usually have a line of code, what is it? "Basic" Java Learning Group 669823128

A: Clone has the default behavior: Super.clone (), he is responsible for generating the correct size of space, and the bit-wise replication.

36. What is GC? Why do you have a GC? Infrastructure

A: GC is the meaning of garbage collection (Gabage Collection), memory processing is a problem for programmers, forget or wrong memory recycling will cause the program or system instability or even crash, Java provides a GC Functions can automatically monitor whether an object exceeds the scope to achieve the purpose of automatically reclaiming memory, and the Java language does not provide a way to release the displayed operation of the 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 ().

37, the advantages and principles of garbage collection. and consider 2 kinds of recycling mechanisms. Infrastructure

A: One notable feature of the Java language is the introduction of a garbage collection mechanism, which makes it possible for C + + programmers to solve the most troublesome memory management problems, which makes it unnecessary for Java programmers to consider memory management when writing programs. Because there is a garbage collection mechanism, objects in Java no longer have a "scope" concept, and only references to objects are scoped. 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-level thread, unpredictable and clear and recyclable for objects that have died in the heap or that have not been used for a long time, and the programmer cannot call the garbage collector in real time for garbage collection of an object or all objects. The recycling mechanism has generational replication garbage collection and token garbage collection, incremental garbage collection.

38. What is the basic principle of the garbage collector? Can the garbage collector reclaim memory right away? Is there any way to proactively notify a virtual machine for garbage collection? Infrastructure

A: For GC, when a programmer creates an object, the GC starts to monitor the address, size, and usage of the object. Typically, a GC uses a graph to record and manage all objects in the heap. In this way, you determine which objects are "accessible" and which objects are "unreachable." When the GC determines that some objects are unreachable, it is the responsibility of the GC to reclaim those memory spaces. OK. The programmer can manually execute System.GC () to notify the GC to run, but the Java language specification does not guarantee that the GC will execute.

39, String S=new string ("xyz"), how many string Object has been created? Infrastructure

A: Two objects, one is "XyX", the other is a reference object pointing to "XyX" s.

40, interface can inherit interface? is an abstract class achievable (implements) interface? Does an abstract class inherit entity classes (concrete Class)? Infrastructure

A: An interface can inherit an interface. Abstract classes can implement (implements) interfaces, and abstract classes can inherit entity classes, but only if the entity classes must have explicit constructors.

41, Java interface and C + + virtual class of the same and different places. Infrastructure

A: Since Java does not support multiple inheritance, it is possible for a class or object to use a method or property that is within several classes or objects, and the existing single inheritance mechanism cannot satisfy the requirement. The interface has more flexibility than inheritance because there is no implementation code in the interface. When a class implements an interface, the class implements all the methods and properties inside the interface, and the properties inside the interface are public static under the default state, and all methods are public by default. A class can implement multiple interfaces.

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

A: Yes, only one class name must be the same as the file name.

43, say some of the commonly used classes, packages, interfaces, please give 5. Infrastructure

A: Commonly used classes: BufferedReader bufferedwriter filereader filewirter String Integer;

Commonly used packages: Java.lang java.awt java.io java.util java.sql;

Common interfaces: Remote List Map Document NodeList

44, Anonymous Inner Class (anonymous inner Class) can extends (inherit) other classes? Is it possible to implements (implement) interface (interface)? Infrastructure

A: You can inherit other classes or implement other interfaces, which are common in swing programming.

45. Can the inner class refer to the members of his containing class? Are there any restrictions? Infrastructure

A: An internal class object can access the contents of the external class object that created it.

46. What is the mechanism for polymorphism in Java? Infrastructure

A: The overlay overriding and overloaded overloading of a method are different manifestations of Java polymorphism; overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class.

47. In Java, a class is declared as the final type, what does that mean? Infrastructure

A: Indicates that the class cannot be inherited, and is a top-level class.

48. Which of the following classes can be inherited? Infrastructure

1) java.lang.Thread (T)

2) Java.lang.Number (T)

3) java.lang.Double (F)

4) Java.lang.Math (F)

5) java.lang.Void (F)

6) Java.lang.Class (F)

7) Java.lang.ClassLoader (T)

Answer: 1, 2, 7 can be inherited.

49, the following procedures to indicate the results of the operation: "Foundation"

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[] ARS) {

A ab = new B (); Executed here, results: 1a2b

AB = new B (); Executed here, results: 1a2b2b

}

}

A: the output is 1a2b2b; the static code snippet for a class can be thought of as code executed by the class for the first load (virtual machine load), and for class loading, the first thing to do is to execute the construction of its base class, and then perform its own construction.

50, the Succession time class execution order question, generally is the choice question, asks you will print what? "Foundation"

Parent class:

Package test;

public class Fatherclass {

Public Fatherclass () {

System.out.println ("Fatherclass Create");

}

}

Sub-class:

Package test;

Import Test. Fatherclass;

public class ChildClass extends Fatherclass {

Public ChildClass () {

System.out.println ("ChildClass Create");

}

public static void Main (string[] args) {

Fatherclass FC = new Fatherclass ();

ChildClass cc = new ChildClass ();

}

}

Answer: The output is:

Fatherclass Create

Fatherclass Create

ChildClass Create

Java Learning Group 669823128

50-course questions and answers for Java Programmer Gold Three silver four carefully selected

Related Article

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.