A classic Java Foundation question collection

Source: Internet
Author: User

question: What happens if the main method is declared private ?

Answer: Can compile normally, but will prompt " main method is not public "when run.

question: What is the difference between a reference and a pass in Java?

Answer: A pass-through refers to an address rather than the value itself, and a pass value is a copy of the passed value.

question: What else to consider if you want to override the Equals method of an object ?

Answer:hashcode.

question:How is Java 's " write once, run everywhere " implemented?

Answer: Java programs are compiled into a class file consisting of bytecode that can be run on any platform, so Java is platform Independent.

question: Explain the function of each keyword in the declaration of public static void Main (String args[])

Answer:The Public:main method is the first method that is called when the Java program is run, so it must be visible to the Java environment. So the visibility is set to pulic.

The Static:java platform calls this method without creating an instance of the class, so this method must be declared as static.

The Void:main method does not return a value.

String is the type of the command-line input parameter, andargs refers to the string array that the command line passes into.

question: the difference between = = and equals

Answer:= = Compare two objects in memory is not the same object, that is, in memory storage location consistent. The values stored by two String objects are the same, but may be stored in different places in memory .

==The comparison is the reference andequalsmethod compares the content. Public Boolean equals (Object obj)This method is determined by theObjectobject, which can be overridden by a subclass. The default implementation returns only if the object and itself are compared.true,this time and==is equivalent. String, BitSet, Date,and theFileare rightequalsmethod has been rewritten for a total of twoStringobjects, the value equality means that they contain the same sequence of characters. For a wrapper class of a basic type, a value equal means the value of the corresponding base type.

1  Public classEqualstest {2      Public Static voidMain (string[] args) {3String S1 ="ABC";4String s2 =S1;5String S5 ="ABC";6String s3 =NewString ("abc");7String S4 =NewString ("abc");8System.out.println ("= = Comparison:" + (S1 = =S5));9System.out.println ("= = Comparison:" + (S1 = =s2));TenSystem.out.println ("Using equals method:" +s1.equals (S2)); OneSystem.out.println ("= = Comparison:" + s3 = =S4); ASystem.out.println ("Using equals method:" +S3.equals (S4)); -     } -}

Results:

true true  truefalseUsing equals method:True

question: What happens if I remove the static modifier from the main method ?

Answer: The program compiles normally. The runtime throws a Nosuchmethoderror exception.

Question: Why is the Oracle Type4 driver known as a thin drive?

Answer Case:Oracleprovides aType 4 JDBCDrive, known as Thin drive. This driver contains aOracleI use it completely .Javaimplementation of aTCP/IPof theNet8implementation, so it is platform independent and can be downloaded at runtime by the browser, without relying on any client'sOracleimplementation. The client connection string is using theTCP/IPaddress port, not the database name.Tnsname.

problem: Describe the Finalize method

Answer: final: constant declaration. finally: handles the exception. Finalize: helps with garbage collection.

Connect the variables declared in the mouth are the defaultFinalthe. Finalclass cannot inherit, that is, there are no subclasses. This is done for basic types of security considerations, such asStringand theInteger. This also allows the compiler to perform some optimizations that make it easier to secure threads. Finalmethod cannot be overridden. Finalthe value of the variable cannot be changed. Finalize ()method is called before an object is destroyed and recycled. Finally,typically used for exception handling, whether or not an exception is thrown. For example, closing a connection usually putsfinallyThe block is complete.

question: What is the Java API?

Answer: The Java API is a collection of a large number of software components that provide a number of useful features, such as GUI components.

question: What is the GregorianCalendar class?

Answer: GregorianCalendar provides support for traditional western calendars.

question: What is the ResourceBundle class ?

Answer: ResourceBundle is used to store resources for the specified locale, and applications can load these resources according to the language context of the runtime, providing a presentation in different languages.

question: Why is there no global variable in Java ?

Answer: Global variables are globally visible, Java does not support globally visible variables because: global variables undermine the principle of referential transparency. A global variable causes a namespace conflict.

question: How do I convert a String type to number type?

Answer: The valueOf method of the Integer class converts a String to number. The following is a code example:

String numstring = "1000″;int id=integer.valueof (numstring). Intvalue ();

question: What is the SimpleTimeZone class ?

Answer: SimpleTimeZone provides Gregorian date support.

question:What is the difference between the while loop and the do loop?

Answer:The while structure determines whether the next iteration should continue at the beginning of the loop. do/while structure at the end of the loop to determine whether the next iteration will continue. The do structure executes at least one loop body.

question: What is the Locale class?

Answer: the locale class is used to dynamically adjust the output of the program according to the locale.

question: What is the principle of object-oriented programming ?

Answer: There are three main points, polymorphism, inheritance and encapsulation.

Question: Introduction to the principles of inheritance

Answer: Inheritance enables an object to get the properties of another object. Using inheritance allows the functionality that has been tested to be reused and can be modified one at a time, with all inherited places in effect.

question: What is implicit type conversions ?

Answer: Implicit type conversion is simply a type assignment to another type, without explicitly telling the compiler that a conversion has occurred. Not all types support implicit type conversions.

code example:

int i = 1000;long J = i; Implicit casting

question: is sizeof a key word for Java ?

Answer: No.

question: What is the native method ?

Answer:The native method is a non- Java Code implementation method.

question: in System.out.println () , System, out, println What are the respective ?

Answer: system is a pre-defined final class provided by the systems, out is a printstream object, println is An overloaded method inside an Out object.

question: What is encapsulation, inheritance, and polymorphism?

Answer: In simple terms, polymorphism refers to multiple implementations of a name. Polymorphism allows an entity to implement different operations in a common way. The specific operation is determined by the actual implementation.

Polymorphic in There are three ways to behave in Java: Method overloading is overridden through the Java interface through the inheritance implementation method .

question: What is an explicit type conversion ?

The answer: Explicit type conversions are explicitly telling the compiler to convert objects.

code example:

Long i = 700.20;int j = (int) i; Explicit Casting

question: What is a Java virtual machine ?

Answer: Java virtual machines are software systems that can be ported to different hardware platforms.

question: What is type down conversion ?

The answer: A down conversion refers to a generic type that is converted to a specific type, down on the inheritance structure.

question: What is the access modifier for Java ?

Answer: TheJava access modifier includes private,default,protected andpublic. The meanings represent private, default, protected, and public access modifiers, respectively. These access modifiers can both decorate properties in a class and modify methods in a class, while public and default can also decorate classes. In the same Java file, the public class has only one, and the file is named the class name. JAVa.

The Java access modifier is the ability to determine the access rights of a property or method in a class, in other words, the scope of the properties and methods.

Private, privileged access, and the most stringent access rights, can only be accessed in the class in which the permission is set, and this access permission is used to demonstrate the encapsulation idea.

Default access, which can be omitted, can be accessed not only in the class in which the permission is set, but also in classes or subclasses in the same package.

Protected, protected Access, which, in addition to the access rights of default, can be accessed by subclasses inherited from different packages.

Public, publicly accessible, and the most permissive access, can be accessed not only by the same class or subclass, or by a class or subclass in the same package, or by a class or subclass in a different package.

In order to understand these access rights more deeply, one needs to understand the respective scopes, on the other hand, it is necessary to clarify the programming ideas embodied by each other, for example, the encapsulation thought of prvite performance, the idea of the interface programming for public performance.

In the process of object-oriented design and programming, it is the design of the class in the final analysis. To design a class that not only satisfies current requirements but also meets future requirements, it is necessary to set appropriate access rights to the properties and behaviors in the class. Those should be private, those should be public, and those should be protected, etc., should be given reasonable planning and layout, one to ensure the function of the program requirements, and secondly to reflect the program's extended performance, Sunline to show the program-friendly nature. In short, the program should serve the user better. Access rights play an important role in such ambitious goals.

A classic Java Foundation question collection

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.