get a runtime error called an EX Ception.Downcasting and the runtime checks require extra time for the running program and extra effort from the programmer.The solution is called a parameterized type mechanism. (Java se5,called generics)A parameterized type (compiler-level technology) is a class, the compiler can automatically customize to work with particular Types.Object Creation LifetimeWhen to destroy object?C + + takes the approach that control
objects of a known type,can is multidimensional, can hold primitived. However, its size cannot is changed once you create it.2. Collection:hold single elements, automatically resize, won ' t hold Primitives3. Map:holds associated pairs, automatically resize, won ' t hold Primitives4. Like an array, a List of also associated numerical indexes to Objects--thus,arrays and Lists is ordered containers.5. The behavior of Queues and stacks is provided via the LinkedList6. A Map is a-to-associate not i
that wrap certain primitive Types:chara Cter, Byte, short, and Integer. where enum enum types are new additions in JDK1.5, and switch supports string strings after JDK7.When programming using the JDK7 version of the environment, the selection factor of the switch statement is used, and if the specification is not met (such as the float type variable), a hint is generated: cannot switch on a value of type float . Only convertible int values, strings or enum variables is permitted because, Byte,s
Down-Stack (linked list implementation):Import Java.util.iterator;public class LinkedstackFIFO Queue (linked list implementation):Import Java.util.iterator;public class Linkedqueue Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Algorithm (fourth edition) Java implementation stack and queue for
its elements can be accessed efficiently and randomly, and the disadvantage is that the performance of inserting and removing elements at a specified location is slow. LinkedList is slower in random access, but it is more efficient to insert and remove elements at a specified location.
2. Set has three important implementations, respectively, Hashset,treeset,linkedhashset
all implementation classes of the set interface ensure that their elements are not duplicat
Select the sort step:1. Locate the subscript of the smallest element in the array that participates in the traversal comparison;2. Swap the minimum element with the first element in the array that participates in the traversal comparison (if the first element is the smallest element, it will also be exchanged);3. If there are elements in the array that need to participate in the traversal comparison, jump to step 1, otherwise the sort ends.All of the sorts given in the
of ~2NLGN and constant additional space. Often used in embedded systems or in low-cost mobile devices (systems with very tight space), but many applications of modern systems seldom use it, because it cannot take advantage of caching. Array elements are rarely compared with other adjacent elements, so the number of cache misses is much higher than the algorithm that most comparisons make between adjacent elements, such as quick sort, merge sort, or even hill sort. On the other hand, the heap-im
Merge sort idea: Sort an array into two parts (using recursion), then merge the results together, merging the last two ordered arrays into a larger ordered array.Time complexity o (n) = NlognThe most appealing nature of merge sorting is that it guarantees that the time required to sort an array of any length n is proportional to the nlogn, and the disadvantage is that the extra space required is proportional to n.Merge sort is also divided into top-down sorting and bottom-up sorting methods:The
Down (LIFO) stack: an implementation that dynamically adjusts the size of the arrayImport Java.util.iterator;public class resizingarraystackAdvantages:Almost (but not useless) achieves the best performance for the implementation of any collection class data type:1. The time of each operation is independent of the collection size;2. Space requirements always do not exceed the set size multiplied by a constant.Disadvantages:Some push () and pop () operations adjust the size of the array, which is
Binary search tree: is a binary tree in which each node contains a key and a value associated with it, and each node has a key greater than the key of any node in its left subtree, which is less than the key of any node in its right sub-tree.The principle of each method of binary search tree is explained in detail in the code, the following is the code:/** * * @author seabear * Binary search tree * @param Copyright NOTICE: This article for Bo Master original article, without Bo Master permissio
UnsupportedOperationException ). If the list is variable size, the programmer must override add(int, E) and remove(int) method differently.Class:arraylist Public class extends Implements ListArrayList is an array-based implementation of the variable size of the list interface. The bottom of the array is implemented in such a way that it has good random access, but it is not efficient for inserting, deleting and so on at the specified location.Each ArrayList instance has a capacity. This capacit
to call inside a constructor is those that is final in the base class. (This also applies to private methods, which is automatically final.)Convariant return typesJava SE5 adds convariant return types, which means, a overridden method in a derived class can return a type derived From the type returned by the Base-class methodDesigning with InheritanceIf you choose inheritance First when you ' re using a existing class to make a new class, things can become needlessly comp Licated.A better appro
Java programming ideology fourth edition Chapter 3 personal exercises, programming ideology Fourth Edition
I hope you will be grateful for your criticism ......)Chapter 3 exercise 9 (1) show the maximum and minimum numbers represented by float and double indexes respectively
==N2) + "\ T" + "N1Exercise 4: (3) write a program that uses two nested for loops and the remainder operator (%) to detect and print a prime number (an integer that can be divisible only by itself and 1 and not by other numbers). public static void Main (string[] args) {test (33);} public static Boolean test (int num) {for (int i=2;iExercise 5: (4) Repeat Exercise 10 in chapter 3rd, instead of using the integer.tobinarystring () method, use the ternary and bitwise operators to display the
Java Programming Idea-the fourth edition of the Learning Summary, this is the second chapter: Everything is an object. Package Com.w3cjava.second; @SuppressWarnings ("All") public class Second {/** * Java Programming Ideas (F
interview and other books? First of all, I work in this company so far is still relatively happy, the boss is more open-minded, allowing me to play in the module I am better at, so there is no intention of leaving, but in case of resignation for some reason? The short-term effect of this book can not only supplement the basic knowledge, but also better face the possibility of leaving the situation, and then chose this book to read.I will read this book at the same time, will I think there is a
example:What exactly is boxing and unpacking, boxing is that the compiler performs a boxing operation after the underlying type is changed to the corresponding object type, and the reverse is the case. The following blog is a special introduction to Java Boxing and unpacking to share with youHttp://www.cnblogs.com/dolphin0520/p/3780005.html= = and equals I used almost every day, before this I did not care too much about the differences, and later loo
, which differs from C + +::. Although it can be overridden, it is not possible to delete any elements (methods, data fields) in the superclass.
The constructor for the Java subclass calls Super (), and as a constructor that calls the superclass, initializes the data fields declared in the superclass in the subclass, and super () must be placed at the first statement position. Here the author mentions that the method of this and super in
"])//Select links to all PDF documents on the page$ (' a[href^= ' http "][href*=" Henry "])//Select the href attribute to start with HTTP and include Henry's Elements anywhere3. Custom Selectors $ (' Div.horizontal:eq (1) ')//gets the second element in a collection$ (' Tr:even ')//select Odd rows. The odd line is because the first row is numbered 0.$ (' Tr:nth-child (odd) ')//select odd lines.: Nth-child () is the only selector in JQ that counts from 1$ (' Tr:contains (Henry) ')//selects elemen
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.