Preview

Java Language

Powerful Essays
Open Document
Open Document
2935 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Java Language
C H A P T E R I
ALL ABOUT Java.lang PACKAGE

Discussions

String

A String is a series of characters, example [‘h’,’e’,’l’,’l’,’o’]. In Java, string is an object. The Java platform has String class to create and manipulate strings in a Java application. To create a string, write

String remark = “This is it!”;

In the above statement, “This is it!” is a string literal, a series of characters. This string literal is assigned to a String object named remark. The string literal can be displayed using the Java output statements, System.out.print( ); or System.out.println( );.

Likewise, a String object can be created by using the new operator and a constructor method.

ex: char [ ] remarkArray = {‘A’,’w’,’e’,’s’,’o’,’m’,’e’,’!’}; String remarkString = new String(remarkArray); System.out.println(remarkString);

The last statement displays the string “Awesome!”.

String length

The String class has a method named, length( ), which returns the number of characters in a string object. In the example below, the length of the string object named len is 7: ex: String palindrome = “racecar”; int len = palindrome.length( );

note: a palindrome is a word or sentence that is spelled the same forward and backward. Case and punctuation is ignored.
Here is a short application to reverse a palindrome string.
/**
* className: Palindrome * This application will print a palindrome word. * * @author: The Java Tutorials * @url: http://docs.oracle.com/javase/tutorial/java/data/strings.html * @comments: Roberto U. Acepcion Jr. */ public class Palindrome
{
public static void main(String[ ] args) { String palindrome = "Dot saw I was Tod"; //string is assigned to a String object named palindrome int len = palindrome.length( ); //counts the number of characters in the string char[ ] tempCharArray = new char[len]; //uses the value of len

You May Also Find These Documents Helpful

  • Good Essays

    PRG/420 Week 3

    • 1025 Words
    • 5 Pages

    /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package commission2; import java.lang. *; import java.text. DecimalFormat; import java.util.…

    • 1025 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    Nt1310 Unit 4 Lab

    • 252 Words
    • 2 Pages

    ➢ To define a class of your own and use it to create an object.…

    • 252 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    The output of this program shows the original word, the reversed word, and the stripped word. Also, the program indicates whether or not the string is a palindrome.…

    • 204 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    Tin Foil Ship

    • 199 Words
    • 1 Page

    We were given a piece of tin foil to make into our ship. We formed a rectangular flat-bottomed ship with short sides all around it from our piece of tin foil. Next, using the formula to find the volume of an object, we calculated the volume of the ship that we had created. Then, to get our prediction, we used a calculation that took the volume of our ship, multiplied the volume of our ship by the density of the water and divided that answer by the weight of a penny. After that, we placed our ship into a container of water, and keeping an accurate count, placed one penny at a time into our ship until it sank to the bottom of the container of water. After that, we subtracted the predicted number of pennies from the actual number of pennies to…

    • 199 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    1.3.1 response

    • 620 Words
    • 3 Pages

    4. What do you notice about each restriction site? What does the word palindrome mean? Each site is just revrese order top and bottm. Pallindrome: word spelled the same forward and back.…

    • 620 Words
    • 3 Pages
    Satisfactory Essays
  • Better Essays

    E-Commerce Exercise

    • 1068 Words
    • 5 Pages

    2. A method of the Double class is the ____ method, which takes a String argument and returns its double value.…

    • 1068 Words
    • 5 Pages
    Better Essays
  • Good Essays

    Java

    • 5076 Words
    • 21 Pages

    Explanation: B) Programs are classified as software to differentiate them from the mechanisms of the computer (hardware). Storage and the processor are two forms of hardware while input is the information that the program processes.…

    • 5076 Words
    • 21 Pages
    Good Essays
  • Good Essays

    Java

    • 490 Words
    • 3 Pages

    Write a Java program to demonstrate using bitmaps and bitwise operators to sort and remove duplicates from a file of random phone numbers. Do not confuse the term bitmap used for compressing data into smaller spaces with the bitmap that has come to mean a graphic image.…

    • 490 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Billy Frank Monologue

    • 1457 Words
    • 6 Pages

    I have somewhat of a friend named Billy. He is the sort of person that puts salt and pepper in our classmates’ juices and taught me to eat row potatoes if I want to pretend to be sick, so I can get out of classes. Yet, his soul possesses a tricky nobleness – one that is not easily discernible. One day we were walking around the town when, stopping in front of a puppet workshop, Billie knocked on the door and shout: ‘’Barmy Barney, open the door you puppet carny”. ‘Who’s that Barney?’…

    • 1457 Words
    • 6 Pages
    Good Essays
  • Powerful Essays

    Java vs .Net

    • 970 Words
    • 4 Pages

    CDCo needs to improve its architecture strategy in order to make the current application architecture more efficient and productive. Looking at the level 0 target state architecture of CDCo, improvement is necessary and choosing which types of technology to use needs to be thoroughly examine to see which is more beneficial to use or adapt. We will address this and explain which approached we will choose after presenting the benefits and pointing out the problems that can eliminate high cost of maintenance. We will define and compare two technologies, discuss their advantages and disadvantages so that we can rule out the best option that we have. Furthermore it is very important to know how this two software architecture overhead cost when it is implemented. For the purpose of this white paper I will introduce the technology that I believe and consider to be appropriate solutions on the current CDCo’s software architecture these are the JAVA technology and the .NET technology.…

    • 970 Words
    • 4 Pages
    Powerful Essays
  • Satisfactory Essays

    Java vs Net

    • 611 Words
    • 3 Pages

    The question is “ Which is better Java or .net?” This seems to be an ongoing debate. You can read article after article that give great reasons to choose one over the other. In fact, as I was researching the advantages and disadvantages of each architecture. I went back and forth in my own opinion. I have seen where .net is better at building UI’s, while Java seems to give more portability. In the end it seems that each has its own advantages based on what you’re trying to accomplish. One is better in this area while the other is better in this area. So you must first understand what you setting out to do before you can choose which architecture to use. Lets look at each, and see where each is better used.…

    • 611 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Char D1

    • 599 Words
    • 3 Pages

    cout << "ERROR - Hyphen is not in the correct position" << endl << endl;…

    • 599 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    C# String Functions

    • 325 Words
    • 2 Pages

    6. IndexOf - Reports the zero-based index of the first occurrence of the specified string in this instance.…

    • 325 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    数据结构C语言版 串的块链存储表示和实现.txt成熟不是心变老,而是眼泪在眼里打转却还保持微笑。把一切平凡的事做好既不平凡,把一切简单的事做对既不简单。/* 数据结构C语言版 串的块链存储表示和实现 P78 编译环境:Dev-C++ 4.9.9.2 日期:2011年2月12日 */ #include #include #include #include // LString.h 串的块链存储表示 #define CHUNKSIZE 4 // 可由用户定义的块大小 typedef struct Chunk { char ch[CHUNKSIZE]; //块的数据域 struct Chunk *next; //块的指针域 }Chunk; typedef struct { Chunk *head, // 串的头指针 *tail; // 串的尾指针 int curlen; // 串的当前长度 }LString; char blank = '#'; // 全局变量,用于填补空余 // 初始化(产生空串)字符串T。 void InitString(LString *T) { (*T).curlen=0; (*T).head=…

    • 1320 Words
    • 6 Pages
    Good Essays
  • Powerful Essays

    Question & Answer

    • 1915 Words
    • 8 Pages

    System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.…

    • 1915 Words
    • 8 Pages
    Powerful Essays

Related Topics