- 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.
- C程序設(shè)計簡明教程(第二版)
- Building a Quadcopter with Arduino
- iOS編程基礎(chǔ):Swift、Xcode和Cocoa入門指南
- 大模型RAG實(shí)戰(zhàn):RAG原理、應(yīng)用與系統(tǒng)構(gòu)建
- 大學(xué)計算機(jī)基礎(chǔ)實(shí)驗指導(dǎo)
- PHP 7+MySQL 8動態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- BeagleBone Robotic Projects(Second Edition)
- Java7程序設(shè)計入門經(jīng)典
- C#程序設(shè)計基礎(chǔ)入門教程
- Python應(yīng)用與實(shí)戰(zhàn)
- Wearable:Tech Projects with the Raspberry Pi Zero
- Mastering Drupal 8
- 你好!Java
- Android應(yīng)用開發(fā)攻略
- 高性能MVVM框架的設(shè)計與實(shí)現(xiàn):San