Java Basics-001

Source: Internet
Author: User

First, to distinguish final, finally, finalize

1. Final keyword

The Java language's keyword final can be used for variables, classes, or methods, but the meaning will vary.

-For variables: once initialized, the value of the variable cannot be modified

-For methods: The method cannot be overridden by a quilt class (Overrride)

-For class: The class cannot derive a subclass

2. Keyword finally

The keyword finally and Try/catch statements are paired, even if an exception is thrown, to ensure that a piece of code is bound to execute. The finally statement block is executed after the Try/catch statement block, before the control is returned.

3.finalize method

The automatic garbage collector calls the Finalize () method before the object is actually destroyed. Therefore, a class can override the Finalize () method of the object class to define specific behavior at garbage collection time.

  

protected void Finalize () throws throwable{/      * Close the file to open, release the resource, etc. */  }

  

Second, distinguish between overloading and rewriting

1. Overloading (overloading) means that two methods have the same name, but different parameter types or numbers.

1  Public Double Computearea (Circle c) {... ..} 2 3  Public double Computearea (Square s) {...}.  

2. Override (overriding) means that a method has the same name and function signature as a method of the parent class

Iii. Common Set Frame

1.arraylist:arraylist is a dynamically sized array that, with the insertion of elements, expands the array as appropriate.

1 New Arraylist<string>(); 2 myarray.add ("one"); 3 Myarray.add ("both"); 4 // print "One"

2.vector:vector is very similar to ArrayList, except that the former (Vector) is synchronous (synchronized). The two are similar in syntax.

1 New Vector<string>(); 2 myvector.add ("one"); 3 Myvector.add ("both"); 4 System.out.println (myvector.get (0));

3.linkedlist:java built-in LinkedList class that will draw some iterator syntax when used

1 linkedlist<string>  new linkedlist<string>(); 2 Mylinkedlist.add ("both"); 3 Mylinkedlist.add ("one"); 4 iterator<string> iter = mylinkedlist.iterator (); 5  while (Iter.hasnext ()) {6      System.out.println (Iter.next ());       7 }

The 4.hashmap:hashmap collection is widely used in a variety of situations.

1 New Hashmap<string,string>(); 2 map.put ("One", "one"); 3 map.put ("n", "a"); 4 System.out.println (Map.get ("one"));

Java Basics-001

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.