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

  • 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
  • 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

    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

    1. True or False: The class String is defined in java.lang.String, which is automatically imported into every program you write.…

    • 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

    Java

    • 827 Words
    • 4 Pages

    9. The withholding tax on a weekly salary (let us assume) is computed as follows: 14% of the difference between a person's gross pay and $13 times the number of dependents he or she claims. Read the values for the gross pay and the number of dependents; print the withholding tax.…

    • 827 Words
    • 4 Pages
    Good Essays
  • Better Essays

    JAVA

    • 956 Words
    • 4 Pages

    Java is one of the computer programming languages. In this language computer programmers write set of instructions using English commands instead of using numeric codes to execute certain task. Java language can be easily written and read by humans so it 's called "high level language". Once Java program is written using high-level instructions it 's translated to numeric codes because computer can understand program only in numeric version. Java language was very simple to use. Java language was developed from the ideas of C++. C++ is also a one of the powerful language but there is one drawback about it i.e., syntax of C++ is very complex. Java language is very simple to use and more powerful. Java provides high level of security so it 's used in the mobile devices were the information’s transferred over the…

    • 956 Words
    • 4 Pages
    Better 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

    7. Insert - Returns a new string in which a specified string is inserted at a specified index position 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