Javaoo Summary One

Source: Internet
Author: User
Tags array length define abstract modifier modifiers

1. What are the characteristics of the Java language?
Simple, object-oriented, cross-platform, multi-threading, garbage collection, robustness, and security

2. How do I compile and execute Java files? What are the commands for generating help documents?
Compiling: Javac file name
Execution: Java class name
Generate Help Document: Javadoc file name
3. What is the workflow of a virtual machine?
Write source file (*.java)--compile into *.class bytecode file--class load--bytecode check--Interpreter---operating system
4. How to write the Main method?
public static void Main (String [] args) {}
5. What is an identifier? How many identifiers are there? What are the naming rules for identifiers?
Any place that can be named is called an identifier. You typically use identifiers to name classes, methods, variables
Identifiers are divided into two types: the system identifier and the user identifier.
Naming rules for identifiers: must be made up of letters, numbers, underscores, and $, and cannot begin with a number.
Naming conventions for identifiers: 1, see the name of the meaning; 2, the class name starts with the capital letter, the Hump is named; 3, the variable name and method name start with a lowercase letter, the hump is named, 4, the constants are all uppercase letters.
6. What are the basic data types in Java? How many bytes each? What are the reference data types in Java? What is the difference between a base type and a reference type?
Eight basic data types: Byte (1), short (2), int (4), Long (8), float, double, char, Boolean
Reference types in Java: classes, interfaces, arrays
Basic data types differ from reference data types: Basic type variables hold specific data, and reference type variables hold object addresses
7. What is the encoding for char types in Java?
Unicode
8. What are the three elements of a variable?
Variable type, variable name, variable value
9. How many comments are there in Java?
Single-line comments, multiline comments, document comments

10. What are the key words for defining constants? What does it mean when a variable of a reference type is declared as a constant?
Defining constants by: Final
When a reference type variable is declared as a constant, it means that the variable cannot point to another object, but the property value can be changed.
11. What is an object? What is a class? What are the relationships between objects and classes?
Object: An object is a concrete entity that exists with well-defined characteristics and behaviors; All things are objects, objects are created by me.
Class: A collection of groups of objects with the same behavior and attributes
Objects and classes: Classes are abstractions of objects, objects are concrete embodiment of classes and instances
12. What kinds of variables are divided by scope? What do I need to be aware of when using local variables?
Local variables: stored in the stack space, method or statement block end, local variable destruction.
Member variables (attributes): stored in the heap space, resulting from the object, destroyed with the destruction of the object.
Static variables (class variables): stored in the data segment, long-standing memory, virtual institutions closed disappear.
Local variables need to be aware of: 1, local variables must be initialized before use. 2, when using local variables, you need to pay attention to the scope. 3. Local variables can only be declared as default or final
13. What is the difference between a static variable and a member variable? How should I call it?
1. The member variables are stored in the heap space and are part of the object. Properties are independent of each other between objects and objects. Static variables are stored in data segments, which are independent of variables outside the object, and many objects share a static variable. 2, static variable loading time before the object. A static method cannot call a member method or member variable directly. 3. Invocation of member variables: object. member variable invocation. Static variable invocation: Class name. and object. All can be called. But it is recommended to use the class name. Called. Therefore, a static variable becomes a class variable as well.
14. What kind of object does garbage collection GC recycle?
There are no objects to which the variable is pointing
15. What is a package? What is the purpose of the package? How do I import a class from another package? What kind of class does not need to be imported?
A package is a folder.
The role of the package: 1, through the package to organize classes, 2, through the package can do information hiding.
Importing packages: Import
Classes and java.lang.* in this package do not need to be imported
16. Can static methods invoke member methods or properties directly? Why?
No, because static methods are loaded first before the object is generated, static variables cannot directly invoke member variables and member methods.
17. What is passed and returned when the object is passed and returned?
Reference (Address)
18, what is the construction method? What is the function of the construction method?
Constructor method: The method name and class name of the constructor method are the same, there is no return type, and the object of the class can be produced by constructing the method.
Function: 1, allocate space for the object 2, if the class does not load, load Class 3, initialize member variable 4, return the reference of the object
19, this and super each represent what meaning?
This indicates that the current object super represents the parent class object
20. How are arrays defined? How do arrays, strings, and collections have their respective lengths?
array type [] Variable name = new array type [array length] or array type [] variable name = {array element};
Array, string length with. Length (), and the length of the collection with. Size ().
21. What are the characteristics of arrays?
1, the array is a series of contiguous memory space, through the subscript access elements. Subscript starting from 0 The maximum subscript is the array length-1.2, the element is a variable, and the type of the variable is the type that defines the array. 3. After the array is created, each element is initialized with int--0, double--0.0, and reference type--null. 4, the length of the array can not be changed
22. The difference between private attribute +get/set method and public property
1, the private property cannot be accessed directly, only through the public get method and set method value or set value. Once the Get/set method is deleted, it can be directly made into a read-only or write-only property, and the public attribute cannot.
2, can be set by the modifier in the property, the validation of data legitimacy, so as to avoid the assignment of illegal data, but the public properties do not.
23. What are the key words for inheritance? Subclass inherits the parent class, how should the first sentence of the construction method be written?
Inheritance uses the extends subclass to inherit the parent class using Super () in the first sentence of the constructor method, calling the parent class's constructor to produce the parent class object. Then, on the basis of the parent class, extend the properties and methods that are unique to the subclass.
24. What is the difference between rewriting and overloading? What are the requirements for rewriting?
Overloading: occurs in the same class. The method names of the two methods are the same, and the parameter list is different (parameter type, number, order) and return type regardless. When called, determines which method to invoke, based on the parameters of the method.
Overriding: Overrides occur between the parent class and the child class, and the child class has the same method name, argument list, and return type as the parent class. Subclasses override the methods of the parent class, and when called, the subclass overrides are called preferentially.
Overriding requirement: The access modifier of a subclass method is greater than or equal to the parent class access modifier, and throws an exception that is less than or equal to the exception thrown by the parent class method
25. Can a class in Java inherit multiple classes at the same time? What is the parent class for all classes?
Inheritance in Java is a single inheritance, a class can inherit only one parent class, and the parent class of all classes is the object class


26. Can the construction method inherit? Can the construction method be overloaded?
The construction method cannot inherit, but the subclass object is created with a call to the parent class's constructor to produce the parent class object.
The constructor method can be overloaded, and the initialization of the property is done by overloading the method.
27. What is the difference between final, finally and finalize?
Final is a modifier. A decorated class that indicates that the class cannot be inherited by a decorated method, which means that the method cannot be overridden by the quilt class, modifies the variable, and indicates that the value of the variable cannot be changed.
Finally is a statement block that represents a block of statements that executes regardless of whether an exception occurs. Typically used for the shutdown of a stream, the database shuts down these cleanup efforts.
Finalize is a method. defined in object. This method is called automatically before the object is garbage collected.
28. What are the access modifiers? What is the scope of their respective scopes?
Private: Accessible only in this class.
Default: The classes in this package can access the
Protect: Subclasses of this package and different packages can use
Public: Both this package and the classes that are not in this package can be used
29. What is an internal class? What is the name of the inner class file?
Inner class: A class defined within a class. An inner class is equivalent to an attribute of an outer class, and its object generation must depend on the outer class object.
External class name $ internal class name. class
30, what is polymorphic? What are the characteristics of polymorphism?
Polymorphism refers to allowing the parent class variable to be used to point to the child class object. Allows you to use an interface variable to point to an implementation class object. But not in the reverse.
Characteristics of polymorphism: The same behavior, different ways of realization

31. What are the object-oriented features?
Inheritance, encapsulation, polymorphism
32. What is abstract class? What is an abstract method? What are the keywords that define abstract classes?
Abstract class: A class that has an abstract method.
Abstract method: Only the method definition does not have an implementation of the method.
Keywords: abstract
33, how to define the interface? What keywords are used to implement the interface? What does a class implementation interface have to do?
Defining interfaces By: interface
Implementation interface: Implement
Implementing an interface must override all the abstract methods defined in the interface. Otherwise, the class can only be an abstract class
34. What are the method modifiers defined in the interface? What are the variable modifiers defined in the interface?
Modifiers for defining methods in interfaces: Public abstract
Variable modifiers defined in the interface: public final static
35. What is the difference between an abstract class and an interface?
Abstract classes and interfaces cannot be instantiated directly. Abstract class variables can only point to subclass objects, and interface variables can only point to implementation class objects;
Abstract classes can have abstract methods, but also can have specific methods, but the interface can only have abstract methods;
The variables defined in the abstract class are normal properties, but the variables defined in the interface are public static constants;
The 四、一个 class inherits only one abstract class, but can implement multiple interfaces.
36. What is the API structure of the exception? What is the difference between error and exception?
Exception API structure: Throwable is the parent class, which has two subclass error (Error) and exception (exception). Where error can be captured, but cannot be processed. And exception can be captured and can be processed.
37. What is the order of exception execution? If there are return,finally in the try block, will it execute?
Executes the contents of the try block first, executes it sequentially, and, if there is an exception, turns to the catch block execution while terminating other code in the try block. Whether or not an exception occurs, it points to the finally statement block.
If there is a return,finally in the try block, it will be executed before jumping out of the method
38. Will finally be executed at any time?
No, shutting down the virtual machine will not be performed. System.exit (0)
39. What is the difference between throw and throws?
Trow is a statement that shows an exception being thrown. throw new Exception
Thows is a method modifier that indicates that the method might throw an exception. The exception that is thrown by the method must be handled when the method is called.
40, the exception is divided into several? How to differentiate?
Exceptions are divided into 2 types: Compile-time exceptions (check exceptions) and run-time exceptions (non-check exceptions).
Compile-time exceptions must be handled, or compile errors. Run-time exceptions can be handled without processing, and will be compiled by non-processing. All run-time exceptions are runtimeexception subclasses
41, how to get the current working directory?
System.getproperty ("User.dir");
42. What is the difference between string x = "abc" and string x = new String ("abc")?
String x = "ABC": the x Variable points to the "ABC" constant object in the constant pool.
string x = new String ("abc"): The x variable executes the string object in the heap. However, the generation of the string object in the heap must be a template for the string constant object in the constant pool
43. What is the difference between string and StringBuffer?
String has an immutable character, and when you add, replace, or delete a string, it does not alter the object's contents, but instead produces a new object, so it is less efficient when the string is frequently manipulated.
StringBuffer is a buffer object that cannot produce a new object when it operates on a StringBuffer object.
In general, use StringBuffer to complete string-related operations, and then use ToString () to convert to string.
44. How do I convert a string to a basic data type?
int x =integer.parseint ("232")
45. How do I format the Date object for "2011-12-10" output?
SimpleDateFormat s = new SimpleDateFormat ("Yyyy-mm-dd");
S.format (New Date ());
46. What are the contents of the JavaBean specification?
1, must provide the public's non-parametric construction method
2. Property private +get/set Access and settings
3. The class must implement the serialization interface
47. What is the function of the set? What is the API structure of the collection framework?
The function of a collection is to store, retrieve, manipulate, and transfer data.
The collection Framework (JCF) consists of three parts: interfaces, implementation classes, and algorithms
Interface: Collection is the parent interface for list and set, plus a map interface
Implementation class: List:arraylist Set:hashset map:hashmap.
Algorithm: Iterator (iterative algorithm), Collection (algorithm Class)
48. What are the characteristics of List, set, and map sets?
Liset: Linear, elements can be repeated
Set: element is not repeatable
Map: An element contains two objects, key-value pairs, and key objects are not repeatable
49. How are the collection elements added? How do I delete it? How do I traverse?
Added: Add () put ()
Remove: Remove ()
Traversal: 1, for (int i = 0;i<list.size (); i++) {Object obj = List.get (i)}
2, Iterator it = List.iterator ();
while (It.hasnext ()) {Object obj = It.next ()};
3, for (Object x:list) {}

50, how to sort the collection?
Collections.sort (list,new Comparator) {public int compare (Object o1,object O2)}

Javaoo Summary One

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.