- Java Programming for Beginners
- Mark Lassoff
- 277字
- 2021-07-02 15:22:47
Strings
Let's talk about strings in Java. To begin, create a new NetBeans project, name it StringsInJava, and enter the main() function. Then, declare two variables: a character called c and String called s. Right away, it becomes clear to us that String is a little different. You'll notice that NetBeans did not choose to color code our String keyword with blue, as it would have done if we were declaring a variable of a primitive type:

This is because String, unlike char, is not a primitive type. String is what we call a class. Classes are the backbone of object-oriented programming. Just as we can declare variables of a primitive type, we can also declare variables of a class, which are called instances. In our program, the variable s is an instance of the String class. Unlike variables of primitive types, instances of a class can contain their own special methodologies and functions declared by the class of which they are an instance. In this section, we'll use some of these string-specific methods and functions to manipulate text.
But first, let's take a look at what makes the String class so special. As we know, we can pretty much use our character variables and our character literals interchangeably, as we can with just about any other primitive type. The String class also maps interchangeably with the string literal, which is like a character literal but uses double quotation marks and can contain many or no characters at all. Most Java classes do not map to any sort of literal, and our ability to manipulate string literals through the String class is what makes it so valuable.
- Spring Cloud Alibaba微服務架構設計與開發實戰
- Android Development with Kotlin
- JIRA 7 Administration Cookbook(Second Edition)
- 軟件測試工程師面試秘籍
- Securing WebLogic Server 12c
- 軟件架構:Python語言實現
- ADI DSP應用技術集錦
- C++寶典
- Visual Studio Code 權威指南
- Hands-On Kubernetes on Windows
- SQL Server 2016 從入門到實戰(視頻教學版)
- Getting Started with Python
- Learning Ionic
- HTML5移動前端開發基礎與實戰(微課版)
- 網絡綜合布線與組網實戰指南