Java common syntax, but found a switch and other basic, common interview routines will not be, to be added

Source: Internet
Author: User
Tags modifier stringbuffer

1, object-oriented, everything objects, object-oriented three basic features: encapsulation, inheritance, polymorphism. Object-oriented programs are made up of classes that encapsulate the properties and behavior of objects. Encapsulation: Hides the properties and implementation details of an object, providing only external interfaces. Inheritance: Implements code reuse and extracts the same parts into a parent class. Several access rights private, can not be decorated classes, the same class is visible. Default, same class, same package. Protected cannot modify classes and interfaces, the same class, the same package, and subclasses. Public, all classes. The static modifier, which is used to modify class methods and class variables. Final modifiers, which are used to modify classes, methods, and variables, the final decorated class cannot be inherited, the decorated method cannot be redefined by the inheriting class, the modified variable is constant, and is not modifiable. An abstract modifier that is used to create abstract classes and abstract methods. Polymorphic: 2, a local variable is only visible in the method, construction method, or block of statements that declares it; local variables are static variables on the stack that are seldom used except when declared as constants; Static variables are stored in a static storage area. Static variables are created at the beginning of the program and are destroyed at the end of the program. 3,a instanceof Car. ()=. ()= . () = String site = "www.runoob.com"; int len = Site.length (); String1.concat (string2); Objects of the StringBuffer and StringBuilder classes can be modified more than once, and no new unused objects are generated. The StringBuilder class is presented in Java 5, and the biggest difference between it and StringBuffer is that the StringBuilder method is not thread-safe (cannot be accessed synchronously). Since StringBuilder has a speed advantage over StringBuffer, it is recommended to use the StringBuilder class in most cases. Append (String s) Delete (int start, int end) replace (int start, int end, String str) charAt (int index) CompareTo (object o) concat (string str) equals (object AnObject) hashcode () startsWith (string prefix) Trim () 6, double[] MyList = {1.9, 2.9, 3.4, 3.5}; Prints all array elements for (int i = 0; i < mylist.length; i++) {System.out.println (Mylist[i] + "");} 7,import java.util.date;date date = new Date ()//Use the toString () function to display datetime SYSTEM.OUT.PRINTLN (date.tostring ()); 8, in In the Finalize () method, you must specify the operation to be performed when the object is destroyed. 9, we can get the user input Scanner s = new Scanner (system.in) through the Scanner class, 10,:ioexception class and RuntimeException class NullPointerException indexoutofboundsexception 11,extends keyword in Java, the inheritance of a class is a single inheritance, that is, a subclass can have only one parent class, using implements Keywords can be disguised to make Java a multi-inheritance, using the scope of the class to inherit the interface, you can inherit multiple interfaces (interface and interface comma-delimited) Super keyword: We can use the Super keyword to achieve access to the parent class members, to refer to the parent class of the current object. This keyword: point to your own reference. The final keyword final keyword declares that a class can be defined as a class that cannot be inherited, that is, a final class, or for a decorated method that cannot be overridden by a quilt class: The  12,java override (override) is a subclass that rewrites the implementation of methods that allow access to the parent class. Neither the return value nor the formal parameter can be changed. That is, the shell does not change, the core rewrite! Animal a = new Animal (); Animal object Animal b = new Dog (); The Dog object B.move ();//Execute the method   overload (overload) overload of the Dog Class (overloading) is in a class, the method has the same name, and the parameters are different. The return type can be the same or different.  13, polymorphism is a different form of the same thing. Printer-Black and white printer-color Printer multi-state advantages, decoupling, scalable, flexible.   Three prerequisites for polymorphic existence, inheritance, overriding, parent class pointing to subclass Reference. P (); When calling a method using polymorphic mode, first check if there is a method in the parent class, if not, compile the error, and if so, then call the method with the same name as the subclass. Abstract class Animal {abstract void Eat ()} class Cat extends Animal {public void Eat () {System.out.println ("eat Fish");} public void work () {System.out.println ("catch Mouse");}} Animal a = new Cat (); A.eat (),  interface Animal {public void eat ();  public class Mammalint implements animal{public void Eat () {System.out.println ("Mammal Eats"); () {System.out.println ("mammal Travels"), public int nooflegs () {return 0,} public static void Main (String args[]) {Mam Malint m = new Mammalint (); M.eat (); M.travel (); }14, abstract classes cannot be instantiated, abstract classes are not abstract, abstract methods must be abstract class 15, encapsulated, privatize properties, and then provide public methods. 16, Reflection 17, stack, advanced out stack<integer> st = new Stack<integer> (); St.push (New Integer (a)); St.pop () Import java.util. *;

Java common syntax, but found a switch and other basics, common interview routines will not, to be added

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.