May 23, 2015 Basic Java Basics

Source: Internet
Author: User
Tags natural logarithm

Java Basics

1, inheritance (extends): Can be understood as sub-class to the parent class in addition to the private method of a variable and a copy of the method;

2, Overwrite (override): Subclass overrides the parent class method, note:

(1) The parameters of the sub-method must be consistent with the parent method;

(2) The scope of the modifier of the subclass method must be greater than the parent class, such as the parent class is the public subclass must be public;

3, polymorphic: Parent Object obj = new child object (), where obj can only invoke methods inherited from the parent class;

4, Abstract: no concrete method body; interfaces: Abstract classes that can be understood as advanced, in which the methods are all abstract, the member variables are public/static (need to be initialized)/fiinal, and when the subclasses implement the interface, all the methods in the interface must be overwritten;

5, Package: (1) Pack: Package (2) Introduction Pack: Import, Default introduction package Java.lang;

6,string---Java.lang

(1) String Name= "..." differs from string s1 = new String ("...") in that the former has only one object, and the latter defines a copy of the "..." string;

(2) commonly used string method: CharAt (integer), char at this position, starting from 0, GetBytes string into an array, isempty to determine whether it is empty, replaceall substitution, subsequence () return subsequence Trim () eliminates whitespace on the left and right sides of the string;

(3) String is the final class, there is no inheritable, can not be changed, StringBuffer thread-safe variable class, append,insert,tostring method, StringBuilder thread insecure mutable class, single-threaded when the first use, less overhead than stringbuffer;

7,calendar,date---java.util

(1) Date date = new Date (), at which date the current time is printed, and the method has SetTime (), Tostring,after ()-Used to compare time;

(2) Calendar abstract class, all methods can be called directly with the class, cd = Calendar.getinstance () initialization; Cd.get (calendar.year);

8,math---java.util

(1) The math method is static and is all used with math.

(2) math.pi-π value, math.e-the base of the natural logarithm;

(3) Math.ceil (double A) the smallest integer greater than the parameter; Math.floor (double x)-the largest x integer less than the parameter; Math.pow (2,3)-power function; Math.random () produces a random number between 0 and 1; Math.Round () rounded;

9, aggregate function: In contrast to an array, the element data class can be different;--java.util

(1) List (ordered): ArrayList (array as the underlying)/linkedlist (linked list as the underlying)/vector (thread synchronization, add a synchronization lock, can be used to ArrayList themselves with a synchronous lock);

(2) Set (does not contain duplicate elements, ordered): HashSet (with hash table, allow key value and value to be null); TreeSet (binary tree, natural sort, can return sequential order); constructor: Interator iterator = Ser iterator;while (iterator.hasnext ()) {System.out.println ( Interator.next)};

(3) Map:hashmap (initial construction method), TreeMap according to the key value of the natural order, key is the same, the latter covers the former, and size only one;

(4) Map is not collection interface, List,map is collection interface;

  

7,

May 23, 2015 Basic Java Basics

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.