全部版块 我的主页
论坛 数据科学与人工智能 IT基础 JAVA语言开发
3952 18
2015-04-12

Learning Java, 4th Edition

Book Description
Java is the preferred language for many of today's leading-edge technologies—everything from smartphones and game consoles to robots, massive enterprise systems, and supercomputers. If you're new to Java, the fourth edition of this bestselling guide provides an example-driven introduction to the latest language features and APIs in Java 6 and 7. Advanced Java developers will be able to take a deep dive into areas such as concurrency and JVM enhancements.

You'll learn powerful new ways to manage resources and exceptions in your applications, and quickly get up to speed on Java's new concurrency utilities, and APIs for web services and XML. You'll also find an updated tutorial on how to get started with the Eclipse IDE, and a brand-new introduction to database access in Java.
Book Details
  • Publisher:        O'Reilly Media
  • By:        Patrick Niemeyer, Daniel Leuck
  • ISBN:        978-1-44931-924-3
  • Year:        2013
  • Pages:        1010
  • Language:        English
  • File size:        25.7 MB
  • File format:        PDF
  • Download:       

    本帖隐藏的内容

    Learning Java, 4th Edition.pdf
    大小:(24.55 MB)

    只需: 20 个论坛币  马上下载





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-4-16 06:02:14
StringBuilder and StringBuffer

In contrast to the immutable string, the java.lang.StringBuilder class is a modifiable and expandable buffer for characters. You can use it to create a big string efficiently. StringBuilder andStringBuffer are twins; they have exactly the same API. StringBuilder was added in Java 5.0 as a drop-in, unsynchronized replacement for StringBuffer. We’ll come back to that in a bit.

First, let’s look at some examples of String construction:

复制代码

This example creates an unnecessary String object each time we use the concatenation operator (+). Whether this is significant depends on how often this code is run and how big the string actually gets. Here’s a more extreme example:

   
复制代码

This example repeatedly produces new String objects. The character array must be copied over and over, which can adversely affect performance. The solution is to use a StringBuilder object and itsappend() method:

   
复制代码

Here, the StringBuilder efficiently handles expanding the array as necessary. We can get a String back from the StringBuilder with its toString() method:

复制代码

You can also retrieve part of a StringBuilder as a String by using one of the substring() methods.

You might be interested to know that when you write a long expression using string concatenation, the compiler generates code that uses a StringBuilder behind the scenes:

复制代码

It is really equivalent to:

    String foo = new      StringBuilder().append("To ").append("be ").append("or").toString();

In this case, the compiler knows what you are trying to do and takes care of it for you.

The StringBuilder class provides a number of overloaded append() methods for adding any type of data to the buffer. StringBuilder also provides a number of overloaded insert() methods for inserting various types of data at a particular location in the string buffer. Furthermore, you can remove a single character or a range of characters with the deleteCharAt() and delete() methods. Finally, you can replace part of the StringBuilder with the contents of a String using the replace() method. The String and StringBuilder classes cooperate so that, in some cases, no copy of the data has to be made; the string data is shared between the objects.

You should use a StringBuilder instead of a String any time you need to keep adding characters to a string; it’s designed to handle such modifications efficiently. You can convert the StringBuilder to a String when you need it, or simply concatenate or print it anywhere you’d use a String.

As we said earlier, StringBuilder was added in Java 5.0 as a replacement for StringBuffer. The only real difference between the two is that the methods of StringBuffer are synchronized and the methods of StringBuilder are not. This means that if you wish to use StringBuilder from multiple threads concurrently, you must synchronize the access yourself (which is easily accomplished). The reason for the change is that most simple usage does not require any synchronization and shouldn’t have to pay the associated penalty (slight as it is).

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-18 12:36:18

String Methods

Method

Functionality


charAt()

Gets a particular character in the string


compareTo()

Compares the string with another string


concat()

Concatenates the string with another string


contains()

Checks whether the string contains another string


copyValueOf()

Returns a string equivalent to the specified character array


endsWith()

Checks whether the string ends with a specified suffix


equals()

Compares the string with another string


equalsIgnoreCase()

Compares the string with another string, ignoring case


getBytes()

Copies characters from the string into a byte array


getChars()

Copies characters from the string into a character array


hashCode()

Returns a hashcode for the string


indexOf()

Searches for the first occurrence of a character or substring in the string


intern()

Fetches a unique instance of the string from a global shared-string pool


isEmpty()

Returns true if the string is zero length


lastIndexOf()

Searches for the last occurrence of a character or substring in a string


length()

Returns the length of the string


matches()

Determines if the whole string matches a regular expression pattern


regionMatches()

Checks whether a region of the string matches the specified region of another string


replace()

Replaces all occurrences of a character in the string with another character


replaceAll()

Replaces all occurrences of a regular expression pattern with a pattern


replaceFirst()

Replaces the first occurrence of a regular expression pattern with a pattern


split()

Splits the string into an array of strings using a regular expression pattern as a delimiter


startsWith()

Checks whether the string starts with a specified prefix


substring()

Returns a substring from the string


toCharArray()

Returns the array of characters from the string


toLowerCase()

Converts the string to lowercase


toString()

Returns the string value of an object


toUpperCase()

Converts the string to uppercase


trim()

Removes leading and trailing whitespace from the string


valueOf()

Returns a string representation of a value


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-5-16 11:19:12

Swing is Java’s graphical user interface toolkit. The javax.swing package (and its numerous subpackages) contain classes representing interface items such as windows, buttons, combo boxes, trees, tables, and menus—everything you need to build a modern, rich client-side application.

Swing is part of a larger collection of software called the Java Foundation Classes (JFC), which includes the following APIs:

  • The Abstract Window Toolkit (AWT), the original user interface toolkit and base graphics classes

  • Swing, the pure Java user interface toolkit

  • Accessibility, which provides tools for integrating nonstandard input and output devices into your user interfaces

  • The 2D API, a comprehensive set of classes for high-quality drawing

  • Drag and Drop, an API that supports the drag-and-drop metaphor



JFC is one of the largest and most complex parts of the standard Java platform, so it shouldn’t be any surprise that we’ll take several chapters to discuss it. In fact, we won’t even get to talk about all of it, just the most important parts—Swing and the 2D API.

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-5-16 15:10:48
复制代码

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-5-16 16:21:43

Drawing Animations

复制代码

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群