This document covers objectives and content about mathematical functions, characters, and strings in Java. It discusses topics like the Math class and its static methods for mathematical operations, the char type for representing single characters, the String class for representing text as objects, and methods for manipulating and comparing strings. Examples are provided throughout to demonstrate various string and character operations in Java like concatenation, extraction of characters and substrings, conversion between char and int types, and comparing strings.
Chapter 4 Mathematical Functions, Characters, and Strings.pptxssusere3b1a2
This document provides an overview of mathematical functions, characters, and strings in Java. It describes the Math class and its common mathematical methods for trigonometric, exponent, rounding, and other functions. It also covers the char data type, escape sequences, Unicode encoding, and methods for comparing and testing characters. Finally, it discusses the String class and methods for string length, concatenation, comparison, substring extraction, and searching.
This document provides notes on Strings and StringBuffers in Java. It discusses:
- The String and StringBuffer classes, their key differences, and common constructors for each.
- Common String methods like length(), charAt(), equals(), compareTo(), and toUpperCase().
- How to extract, compare, modify and check substrings within a String.
- Common StringBuffer methods like append(), insert(), delete(), and replace() that allow mutable string operations.
- The Java util Date class and Random number generator, with examples of constructing and using each.
It then covers exceptions in Java, including checked vs unchecked exceptions, syntax for try/catch blocks, and using multiple
Vision academy classes_bcs_bca_bba_java part_2NayanTapare1
Digital marketing, refers to marketing methods that allow organizations to see how a campaign is performing in real-time, such as what is being viewed, how often, how long, as well as other statistics such as sales conversions.
This document discusses programming language foundations and provides information about mathematical functions, characters, and strings in Java. It includes a case study on computing triangle angles from user-entered coordinate points. It also covers the character and string data types in Java, encoding schemes like Unicode and ASCII, character testing and comparison methods, and basic string methods.
This document outlines Chapter 11 from a 2003 Prentice Hall textbook on Strings and Characters in Java. It covers the String, StringBuffer, and Character classes, including constructors, methods for length, comparison, locating/extracting substrings, and concatenation. It also discusses regular expressions and string tokenization. The chapter aims to explain fundamental string processing and manipulation in Java.
This document provides information about strings and characters in Java. It includes definitions of strings and characters, examples of using string methods like length(), substring(), indexOf(), and equals(). It also discusses formatting output with printf and comparing/modifying strings and characters. The document is from a textbook on building Java programs and is copyrighted material. It contains exercises for students to complete.
This document outlines Chapter 11 on strings and characters from a 2003 Prentice Hall textbook. It covers the String, StringBuffer, and Character classes, including constructors, methods for length, character access, comparison, searching, and extracting substrings. Code examples demonstrate using various string methods like indexOf, substring, equals, and concatenation.
This document outlines Chapter 11 on strings and characters from a 2003 Prentice Hall textbook. It covers the String, StringBuffer, and Character classes, including constructors, methods for length, character access, comparison, searching, and extracting substrings. Code examples demonstrate using various string methods like indexOf, substring, equals, and concatenation.
Chapter 4 Mathematical Functions, Characters, and Strings.pptxssusere3b1a2
This document provides an overview of mathematical functions, characters, and strings in Java. It describes the Math class and its common mathematical methods for trigonometric, exponent, rounding, and other functions. It also covers the char data type, escape sequences, Unicode encoding, and methods for comparing and testing characters. Finally, it discusses the String class and methods for string length, concatenation, comparison, substring extraction, and searching.
This document provides notes on Strings and StringBuffers in Java. It discusses:
- The String and StringBuffer classes, their key differences, and common constructors for each.
- Common String methods like length(), charAt(), equals(), compareTo(), and toUpperCase().
- How to extract, compare, modify and check substrings within a String.
- Common StringBuffer methods like append(), insert(), delete(), and replace() that allow mutable string operations.
- The Java util Date class and Random number generator, with examples of constructing and using each.
It then covers exceptions in Java, including checked vs unchecked exceptions, syntax for try/catch blocks, and using multiple
Vision academy classes_bcs_bca_bba_java part_2NayanTapare1
Digital marketing, refers to marketing methods that allow organizations to see how a campaign is performing in real-time, such as what is being viewed, how often, how long, as well as other statistics such as sales conversions.
This document discusses programming language foundations and provides information about mathematical functions, characters, and strings in Java. It includes a case study on computing triangle angles from user-entered coordinate points. It also covers the character and string data types in Java, encoding schemes like Unicode and ASCII, character testing and comparison methods, and basic string methods.
This document outlines Chapter 11 from a 2003 Prentice Hall textbook on Strings and Characters in Java. It covers the String, StringBuffer, and Character classes, including constructors, methods for length, comparison, locating/extracting substrings, and concatenation. It also discusses regular expressions and string tokenization. The chapter aims to explain fundamental string processing and manipulation in Java.
This document provides information about strings and characters in Java. It includes definitions of strings and characters, examples of using string methods like length(), substring(), indexOf(), and equals(). It also discusses formatting output with printf and comparing/modifying strings and characters. The document is from a textbook on building Java programs and is copyrighted material. It contains exercises for students to complete.
This document outlines Chapter 11 on strings and characters from a 2003 Prentice Hall textbook. It covers the String, StringBuffer, and Character classes, including constructors, methods for length, character access, comparison, searching, and extracting substrings. Code examples demonstrate using various string methods like indexOf, substring, equals, and concatenation.
This document outlines Chapter 11 on strings and characters from a 2003 Prentice Hall textbook. It covers the String, StringBuffer, and Character classes, including constructors, methods for length, character access, comparison, searching, and extracting substrings. Code examples demonstrate using various string methods like indexOf, substring, equals, and concatenation.
This document provides an overview of the Character class in Java, including how to create Character objects from primitive char values, common character methods like isLetter() and toUpperCase(), escape sequences, and examples of using Character class methods. Character class methods allow checking properties of characters, converting between cases, and boxing/unboxing primitive char values. The document also shares code snippets demonstrating the use of these Character class features in Java programs.
The document discusses the String and StringBuffer classes in Java and their key methods. It covers fundamentals of characters and strings, the various String constructors, methods for comparing and locating substrings in strings, extracting substrings, concatenating strings, and converting between string and character array representations. The StringBuffer class is introduced as a mutable alternative to String for modifying string content. Example code demonstrates the use of many string methods.
Maharishi University of Management (MSc Computer Science test questions)Dharma Kshetri
The document provides sample code for 3 programming challenges:
1) Write a function to return the second largest integer in an array.
2) Write a function to return the difference between the sum of odd and even numbers in an array.
3) Write a function to return a substring of characters from an input character array based on a start position and length. The function returns null if the start/length are invalid.
The Ring programming language version 1.3 book - Part 26 of 88Mahmoud Samir Fayed
The List Class provides methods for manipulating list data in Ring. Key methods include Add() to add an item, Delete() to remove an item by index, Item() to access an item by index, FindInColumn() to search for an item in a list column, and Sort() to return a new sorted list. Lists can be concatenated using the + operator and initialized from arrays or other lists.
The document provides an overview of Strings and StringBuilders in Java. It discusses Strings as immutable objects and how StringBuilders can be more efficient for modifying strings. It also covers common String and StringBuilder methods, when to use each, and exceptions in Java using try/catch blocks.
The document discusses Java character and string data types. It covers the char data type, Unicode encoding, ASCII character codes, escape sequences, methods in the Character class, the String type as a reference type, simple string methods like length(), concatenation, conversion methods, comparing strings, and substring methods.
The document discusses different types of arrays in C including one-dimensional, two-dimensional, and multi-dimensional arrays. It explains how to declare, initialize, and access array elements. Examples are provided to demonstrate array operations like addition, multiplication, and passing arrays to functions. The use of arrays to store strings and various string handling functions are also covered.
In this chapter we will explore strings. We are going to explain how they are implemented in C# and in what way we can process text content. Additionally, we will go through different methods for manipulating a text: we will learn how to compare strings, how to search for substrings, how to extract substrings upon previously settled parameters and last but not least how to split a string by separator chars. We will demonstrate how to correctly build strings with the StringBuilder class. We will provide a short but very useful information for the most commonly used regular expressions. We will discuss some classes for efficient construction of strings. Finally, we will take a look at the methods and classes for achieving more elegant and stricter formatting of the text content.
This document discusses string handling in Java. It covers key topics like:
- Strings are immutable objects in Java
- The String, StringBuffer, and StringBuilder classes can be used to manipulate strings
- Common string methods like length(), concat(), indexOf(), and replace()
- Strings can be compared using equals(), startsWith(), and compareTo()
- Immutability avoids security issues when strings are passed as parameters
This document provides information about strings in C++. It defines a string as a collection of characters within double quotes. Strings are stored as character arrays terminated by a null character. The document discusses declaring and initializing strings, inputting strings from the user, and functions for manipulating strings like strcat(), strcmp(), and memcpy(). It also covers arrays of strings and comparing, concatenating, copying and other operations on strings.
This document discusses C strings and string functions. It defines a C string as a sequence of characters terminated with a null character. Strings are stored as character arrays. It provides examples of declaring, initializing, reading, and passing strings. It also describes common string functions like strcpy(), strcat(), strcmp(), strlen() for copying, concatenating, comparing, and getting the length of strings.
This document summarizes a slide presentation on string methods and debugging in Java. It provides examples of common string methods like charAt, compareTo, indexOf, replace, and substring. It also briefly explains how to debug programs using breakpoints and stepping through code line-by-line.
The document provides an overview and summary of key features of C# classes, including:
- Class declaration syntax and default access levels
- Constructors and initializing fields
- Static and readonly fields
- Value and reference parameters
- Arrays as reference types that can be initialized with shorthand syntax
It also briefly discusses the System.Array base class and how to safely access elements in multi-dimensional arrays.
String in programming language in c or c++Azeemaj101
This document discusses strings in C++. It defines a string as a sequence of characters and provides examples. It explains that strings can be represented using C-style character arrays or the C++ string class. When using character arrays, strings are null-terminated and common functions like strcpy(), strcat(), and strlen() are used. The C++ string class provides a safer alternative with useful methods like assign(), append(), insert(), replace(), erase(), find(), and more. It also supports all C++ operators and returns the string length.
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUpanagenda
Webinar Recording: https://www.panagenda.com/webinars/hcl-notes-und-domino-lizenzkostenreduzierung-in-der-welt-von-dlau/
DLAU und die Lizenzen nach dem CCB- und CCX-Modell sind für viele in der HCL-Community seit letztem Jahr ein heißes Thema. Als Notes- oder Domino-Kunde haben Sie vielleicht mit unerwartet hohen Benutzerzahlen und Lizenzgebühren zu kämpfen. Sie fragen sich vielleicht, wie diese neue Art der Lizenzierung funktioniert und welchen Nutzen sie Ihnen bringt. Vor allem wollen Sie sicherlich Ihr Budget einhalten und Kosten sparen, wo immer möglich. Das verstehen wir und wir möchten Ihnen dabei helfen!
Wir erklären Ihnen, wie Sie häufige Konfigurationsprobleme lösen können, die dazu führen können, dass mehr Benutzer gezählt werden als nötig, und wie Sie überflüssige oder ungenutzte Konten identifizieren und entfernen können, um Geld zu sparen. Es gibt auch einige Ansätze, die zu unnötigen Ausgaben führen können, z. B. wenn ein Personendokument anstelle eines Mail-Ins für geteilte Mailboxen verwendet wird. Wir zeigen Ihnen solche Fälle und deren Lösungen. Und natürlich erklären wir Ihnen das neue Lizenzmodell.
Nehmen Sie an diesem Webinar teil, bei dem HCL-Ambassador Marc Thomas und Gastredner Franz Walder Ihnen diese neue Welt näherbringen. Es vermittelt Ihnen die Tools und das Know-how, um den Überblick zu bewahren. Sie werden in der Lage sein, Ihre Kosten durch eine optimierte Domino-Konfiguration zu reduzieren und auch in Zukunft gering zu halten.
Diese Themen werden behandelt
- Reduzierung der Lizenzkosten durch Auffinden und Beheben von Fehlkonfigurationen und überflüssigen Konten
- Wie funktionieren CCB- und CCX-Lizenzen wirklich?
- Verstehen des DLAU-Tools und wie man es am besten nutzt
- Tipps für häufige Problembereiche, wie z. B. Team-Postfächer, Funktions-/Testbenutzer usw.
- Praxisbeispiele und Best Practices zum sofortigen Umsetzen
This document provides an overview of the Character class in Java, including how to create Character objects from primitive char values, common character methods like isLetter() and toUpperCase(), escape sequences, and examples of using Character class methods. Character class methods allow checking properties of characters, converting between cases, and boxing/unboxing primitive char values. The document also shares code snippets demonstrating the use of these Character class features in Java programs.
The document discusses the String and StringBuffer classes in Java and their key methods. It covers fundamentals of characters and strings, the various String constructors, methods for comparing and locating substrings in strings, extracting substrings, concatenating strings, and converting between string and character array representations. The StringBuffer class is introduced as a mutable alternative to String for modifying string content. Example code demonstrates the use of many string methods.
Maharishi University of Management (MSc Computer Science test questions)Dharma Kshetri
The document provides sample code for 3 programming challenges:
1) Write a function to return the second largest integer in an array.
2) Write a function to return the difference between the sum of odd and even numbers in an array.
3) Write a function to return a substring of characters from an input character array based on a start position and length. The function returns null if the start/length are invalid.
The Ring programming language version 1.3 book - Part 26 of 88Mahmoud Samir Fayed
The List Class provides methods for manipulating list data in Ring. Key methods include Add() to add an item, Delete() to remove an item by index, Item() to access an item by index, FindInColumn() to search for an item in a list column, and Sort() to return a new sorted list. Lists can be concatenated using the + operator and initialized from arrays or other lists.
The document provides an overview of Strings and StringBuilders in Java. It discusses Strings as immutable objects and how StringBuilders can be more efficient for modifying strings. It also covers common String and StringBuilder methods, when to use each, and exceptions in Java using try/catch blocks.
The document discusses Java character and string data types. It covers the char data type, Unicode encoding, ASCII character codes, escape sequences, methods in the Character class, the String type as a reference type, simple string methods like length(), concatenation, conversion methods, comparing strings, and substring methods.
The document discusses different types of arrays in C including one-dimensional, two-dimensional, and multi-dimensional arrays. It explains how to declare, initialize, and access array elements. Examples are provided to demonstrate array operations like addition, multiplication, and passing arrays to functions. The use of arrays to store strings and various string handling functions are also covered.
In this chapter we will explore strings. We are going to explain how they are implemented in C# and in what way we can process text content. Additionally, we will go through different methods for manipulating a text: we will learn how to compare strings, how to search for substrings, how to extract substrings upon previously settled parameters and last but not least how to split a string by separator chars. We will demonstrate how to correctly build strings with the StringBuilder class. We will provide a short but very useful information for the most commonly used regular expressions. We will discuss some classes for efficient construction of strings. Finally, we will take a look at the methods and classes for achieving more elegant and stricter formatting of the text content.
This document discusses string handling in Java. It covers key topics like:
- Strings are immutable objects in Java
- The String, StringBuffer, and StringBuilder classes can be used to manipulate strings
- Common string methods like length(), concat(), indexOf(), and replace()
- Strings can be compared using equals(), startsWith(), and compareTo()
- Immutability avoids security issues when strings are passed as parameters
This document provides information about strings in C++. It defines a string as a collection of characters within double quotes. Strings are stored as character arrays terminated by a null character. The document discusses declaring and initializing strings, inputting strings from the user, and functions for manipulating strings like strcat(), strcmp(), and memcpy(). It also covers arrays of strings and comparing, concatenating, copying and other operations on strings.
This document discusses C strings and string functions. It defines a C string as a sequence of characters terminated with a null character. Strings are stored as character arrays. It provides examples of declaring, initializing, reading, and passing strings. It also describes common string functions like strcpy(), strcat(), strcmp(), strlen() for copying, concatenating, comparing, and getting the length of strings.
This document summarizes a slide presentation on string methods and debugging in Java. It provides examples of common string methods like charAt, compareTo, indexOf, replace, and substring. It also briefly explains how to debug programs using breakpoints and stepping through code line-by-line.
The document provides an overview and summary of key features of C# classes, including:
- Class declaration syntax and default access levels
- Constructors and initializing fields
- Static and readonly fields
- Value and reference parameters
- Arrays as reference types that can be initialized with shorthand syntax
It also briefly discusses the System.Array base class and how to safely access elements in multi-dimensional arrays.
String in programming language in c or c++Azeemaj101
This document discusses strings in C++. It defines a string as a sequence of characters and provides examples. It explains that strings can be represented using C-style character arrays or the C++ string class. When using character arrays, strings are null-terminated and common functions like strcpy(), strcat(), and strlen() are used. The C++ string class provides a safer alternative with useful methods like assign(), append(), insert(), replace(), erase(), find(), and more. It also supports all C++ operators and returns the string length.
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUpanagenda
Webinar Recording: https://www.panagenda.com/webinars/hcl-notes-und-domino-lizenzkostenreduzierung-in-der-welt-von-dlau/
DLAU und die Lizenzen nach dem CCB- und CCX-Modell sind für viele in der HCL-Community seit letztem Jahr ein heißes Thema. Als Notes- oder Domino-Kunde haben Sie vielleicht mit unerwartet hohen Benutzerzahlen und Lizenzgebühren zu kämpfen. Sie fragen sich vielleicht, wie diese neue Art der Lizenzierung funktioniert und welchen Nutzen sie Ihnen bringt. Vor allem wollen Sie sicherlich Ihr Budget einhalten und Kosten sparen, wo immer möglich. Das verstehen wir und wir möchten Ihnen dabei helfen!
Wir erklären Ihnen, wie Sie häufige Konfigurationsprobleme lösen können, die dazu führen können, dass mehr Benutzer gezählt werden als nötig, und wie Sie überflüssige oder ungenutzte Konten identifizieren und entfernen können, um Geld zu sparen. Es gibt auch einige Ansätze, die zu unnötigen Ausgaben führen können, z. B. wenn ein Personendokument anstelle eines Mail-Ins für geteilte Mailboxen verwendet wird. Wir zeigen Ihnen solche Fälle und deren Lösungen. Und natürlich erklären wir Ihnen das neue Lizenzmodell.
Nehmen Sie an diesem Webinar teil, bei dem HCL-Ambassador Marc Thomas und Gastredner Franz Walder Ihnen diese neue Welt näherbringen. Es vermittelt Ihnen die Tools und das Know-how, um den Überblick zu bewahren. Sie werden in der Lage sein, Ihre Kosten durch eine optimierte Domino-Konfiguration zu reduzieren und auch in Zukunft gering zu halten.
Diese Themen werden behandelt
- Reduzierung der Lizenzkosten durch Auffinden und Beheben von Fehlkonfigurationen und überflüssigen Konten
- Wie funktionieren CCB- und CCX-Lizenzen wirklich?
- Verstehen des DLAU-Tools und wie man es am besten nutzt
- Tipps für häufige Problembereiche, wie z. B. Team-Postfächer, Funktions-/Testbenutzer usw.
- Praxisbeispiele und Best Practices zum sofortigen Umsetzen
GraphRAG for Life Science to increase LLM accuracyTomaz Bratanic
GraphRAG for life science domain, where you retriever information from biomedical knowledge graphs using LLMs to increase the accuracy and performance of generated answers
Dr. Sean Tan, Head of Data Science, Changi Airport Group
Discover how Changi Airport Group (CAG) leverages graph technologies and generative AI to revolutionize their search capabilities. This session delves into the unique search needs of CAG’s diverse passengers and customers, showcasing how graph data structures enhance the accuracy and relevance of AI-generated search results, mitigating the risk of “hallucinations” and improving the overall customer journey.
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!SOFTTECHHUB
As the digital landscape continually evolves, operating systems play a critical role in shaping user experiences and productivity. The launch of Nitrux Linux 3.5.0 marks a significant milestone, offering a robust alternative to traditional systems such as Windows 11. This article delves into the essence of Nitrux Linux 3.5.0, exploring its unique features, advantages, and how it stands as a compelling choice for both casual users and tech enthusiasts.
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfMalak Abu Hammad
Discover how MongoDB Atlas and vector search technology can revolutionize your application's search capabilities. This comprehensive presentation covers:
* What is Vector Search?
* Importance and benefits of vector search
* Practical use cases across various industries
* Step-by-step implementation guide
* Live demos with code snippets
* Enhancing LLM capabilities with vector search
* Best practices and optimization strategies
Perfect for developers, AI enthusiasts, and tech leaders. Learn how to leverage MongoDB Atlas to deliver highly relevant, context-aware search results, transforming your data retrieval process. Stay ahead in tech innovation and maximize the potential of your applications.
#MongoDB #VectorSearch #AI #SemanticSearch #TechInnovation #DataScience #LLM #MachineLearning #SearchTechnology
“An Outlook of the Ongoing and Future Relationship between Blockchain Technologies and Process-aware Information Systems.” Invited talk at the joint workshop on Blockchain for Information Systems (BC4IS) and Blockchain for Trusted Data Sharing (B4TDS), co-located with with the 36th International Conference on Advanced Information Systems Engineering (CAiSE), 3 June 2024, Limassol, Cyprus.
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
For the full video of this presentation, please visit: https://www.edge-ai-vision.com/2024/06/building-and-scaling-ai-applications-with-the-nx-ai-manager-a-presentation-from-network-optix/
Robin van Emden, Senior Director of Data Science at Network Optix, presents the “Building and Scaling AI Applications with the Nx AI Manager,” tutorial at the May 2024 Embedded Vision Summit.
In this presentation, van Emden covers the basics of scaling edge AI solutions using the Nx tool kit. He emphasizes the process of developing AI models and deploying them globally. He also showcases the conversion of AI models and the creation of effective edge AI pipelines, with a focus on pre-processing, model conversion, selecting the appropriate inference engine for the target hardware and post-processing.
van Emden shows how Nx can simplify the developer’s life and facilitate a rapid transition from concept to production-ready applications.He provides valuable insights into developing scalable and efficient edge AI solutions, with a strong focus on practical implementation.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
UiPath Test Automation using UiPath Test Suite series, part 6DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 6. In this session, we will cover Test Automation with generative AI and Open AI.
UiPath Test Automation with generative AI and Open AI webinar offers an in-depth exploration of leveraging cutting-edge technologies for test automation within the UiPath platform. Attendees will delve into the integration of generative AI, a test automation solution, with Open AI advanced natural language processing capabilities.
Throughout the session, participants will discover how this synergy empowers testers to automate repetitive tasks, enhance testing accuracy, and expedite the software testing life cycle. Topics covered include the seamless integration process, practical use cases, and the benefits of harnessing AI-driven automation for UiPath testing initiatives. By attending this webinar, testers, and automation professionals can gain valuable insights into harnessing the power of AI to optimize their test automation workflows within the UiPath ecosystem, ultimately driving efficiency and quality in software development processes.
What will you get from this session?
1. Insights into integrating generative AI.
2. Understanding how this integration enhances test automation within the UiPath platform
3. Practical demonstrations
4. Exploration of real-world use cases illustrating the benefits of AI-driven test automation for UiPath
Topics covered:
What is generative AI
Test Automation with generative AI and Open AI.
UiPath integration with generative AI
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
2. OBJECTIVES
To solve mathematics problems by using the methods in the Math class (§4.2).
To represent characters using the char type (§4.3).
To represent special characters using the escape sequences (§4.4.2).
To cast a numeric value to a character and cast a character to an integer (§4.3.3).
To compare and test characters using the static methods in the Character class (§4.3.4).
To introduce objects and instance methods (§4.4).
To represent strings using the String objects (§4.4).
To return the string length using the length() method (§4.4.1).
To return a character in the string using the charAt(i) method (§4.4.2).
To use the + operator to concatenate strings (§4.4.3). 2
3. To read strings from the console (§4.4.4).
To read a character from the console (§4.4.5).
To compare strings using the equals method and the compareTo methods (§4.4.6).
To obtain substrings (§4.4.7).
To find a character or a substring in a string using the indexOf method (§4.4.8).
To convert a hexadecimal character to a decimal value (HexDigit2Dec) (§4.5.2).
To format output using the System.out.printf method (§4.6).
3
OBJECTIVES…
4. STATIC METHODS
⚫Remember the main method header?
public static void main(String[] args)
⚫What does static mean?
⚫associates a method with a particular class name
⚫any method can call a static method either:
⚫directly from within same class OR
⚫using class name from outside class
⚫Application Programming Interface (API) is the list of all
public members of a class
4
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
6. THE MATHCLASS API
6
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
⚫Class constants (always static):
⚫PI
⚫E
⚫Class static methods:
⚫Trigonometric methods
⚫Exponent methods
⚫Rounding methods
⚫min, max, abs, and random methods
7. TRIGONOMETRIC METHODS
⚫sin(double a)
⚫cos(double a)
⚫tan(double a)
⚫acos(double a)
⚫asin(double a)
⚫atan(double a)
Radians
•Examples: Math.sin(0)
returns 0.0
Math.sin(Math.PI / 6)
returns 0.5
Math.sin(Math.PI / 2)
returns 1.0
Math.cos(0) returns 1.0
Math.cos(Math.PI / 6)
returns 0.866
Math.cos(Math.PI / 2)
returns 0
(C) PEARSON EDUCATION, INC. & PAUL FODOR (CS STONY BROOK)
8. EXPONENT METHODS
⚫ exp(double a)
Returnse raised to the power of a.
⚫ log(double a)
Returnsthe natural logarithm of a.
⚫ log10(double a)
Returnsthe 10-basedlogarithm of a.
⚫ pow(double a, double b)
Returnsa raised to the power of b.
⚫ sqrt(double a)
Returnsthe square root of a.
•Examples:
Math.exp(1) returns 2.71
Math.log(2.71)
returns 1.0
Math.pow(2, 3)
returns 8.0
Math.pow(3, 2)
returns 9.0
Math.pow(3.5, 2.5)
returns 22.91765
Math.sqrt(4) returns 2.0
Math.sqrt(10.5)
returns 3.24
(C) PEARSON EDUCATION, INC. & PAUL FODOR (CS STONY BROOK)
9. ROUNDING METHODS
9
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
⚫ double ceil(double x)
x rounded up to its nearest integer.This integer is returned as a double value.
⚫ double floor(double x)
x is rounded down to its nearest integer.This integer is returned as a double
value.
⚫ double rint(double x)
x is rounded to its nearest integer. If x is equally close to two integers, the
even one is returned as a double.
⚫ int round(float x)
Return (int)Math.floor(x+0.5).
⚫ long round(double x)
Return (long)Math.floor(x+0.5).
11. MIN, MAX, AND ABS
⚫ max(a, b)and min(a, b) Returns
the maximum or minimum of two
parameters.
⚫ abs(a)
Returns the absolute value of the parameter.
⚫ random()
Returns arandom double
value
in the range [0.0, 1.0).
• Examples:
Math.max(2, 3)
returns 3
Math.max(2.5, 3)
returns 3.0
Math.min(2.5,3.6)
returns 2.5
Math.abs(-2)
returns 2
Math.abs(-2.1)
returns 2.1
(C) PEARSON EDUCATION, INC. & PAUL FODOR (CS STONY BROOK)
12. THE RANDOMMETHOD
Generates arandom double value greater than or equal to 0.0 and less
than 1.0 (0 <= Math.random() < 1.0)
Examples:
(int)(Math.random() * 10) Returns a random integer
between 0 and 9.
50 + (int)(Math.random() * 50) Returns a random integer
between 50 and 99.
In general,
a + Math.random() * b Returns a random number between
a and a + b, excluding a + b.
13. GENERATING RANDOM CHARACTERS
13
(char)((int)'a' + Math.random() * ((int)'z' - (int)'a' + 1))
⚫All numeric operators can be applied to the char operands
⚫The char operand is cast into anumber if the other operand isa
number or acharacter.
⚫So,the preceding expression can be simplified asfollows:
(char)('a' + Math.random() * ('z' - 'a'
+ 1))
14. ASCII CODE FOR COMMONLY USED CHARACTERS
Characters Code Value in Decimal Unicode Value
'0' to '9' 48 to 57 u0030 to u0039
'A' to 'Z'
'a' to 'z'
65 to 90
97 to 122
u0041 to u005A
u0061 to u007A
There is no need to remember them since we can do all mathematical
operations with characters:
(char)('a' + Math.random() * ('z' - 'a' + 1))
'0' <= c && c <= '9'
14
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
15. COMPARING AND TESTING CHARACTERS
if ('A' <= ch && ch <= 'Z')
System.out.println(ch + " is an uppercase
letter");
if ('a' <= ch && ch <= 'z')
System.out.println(ch + " is a lowercase letter");
if ('0' <= ch && ch <= '9')
System.out.println(ch + " is a numeric
character");
15
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
16. METHODS IN THE CHARACTER CLASS
Method Description
isDigit(ch)
isLetter(ch)
isLetterOrDigit(ch)
isLowerCase(ch)
isUpperCase(ch)
toLowerCase(ch)
toUpperCase(ch)
Returns true if the specified character is a digit.
Returns true if the specified character is a letter.
Returns true if the specified character is a letter or digit.
Returns true if the specified character is a lowercase letter.
Returns true if the specified character is an uppercase letter.
Returns the lowercase of the specified character.
Returns the uppercase of the specified character.
16
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
17. THE STRING TYPE
14
String message = "Welcome to Java";
: String
"Welcome to Java"
⚫ The char type only represents one character:
char ch = 'a';
'a'
⚫ To represent a string of characters, use the data type called String.
String is a predefined class in the Java library just like the System class
http://java.sun.com/javase/8/docs/api/java/lang/String.html
⚫ The String type is NOT a primitive type.
⚫ The String type is a reference type.
⚫ A String variable is a reference variable, an "address" which points to an object storing
the value or actual text
18. MORE ABOUT STRINGS
⚫Each character is stored at an index:
String sentence = "A statement";
012345678910
⚫The String class API has methods to process strings:
System.out.println("charAt(6) is " +
sentence.charAt(6));
System.out.println(sentence.toUpperCase());
System.out.println(sentence.substring(0,7) +
sentence.substring(10));
18
19. STRINGS ARE IMMUTABLE!
⚫There are no methods to change them once they have been
created
⚫any new assignment will assign a new String reference to the
old variable
String word = "Steven";
word = word.substring(0, 5);
⚫the variable word is now a reference to a new String that
contains "Steve"
19
21. STRING CONCATENATION
⚫ “+” is used for making a new string by concatenating strings:
// Three strings are concatenated
String message = "Welcome " + "to " + "Java";
// String Chapter is concatenated with number 2
String s = "Chapter" + 2; // s becomes Chapter2
// String Supplement is concatenated with character B
String s1 = "Supplement" + 'B';
// s1 becomes SupplementB
String s2 = 1 + 2 + "ABC";
// s2 become "3ABC"
21
23. READING A STRING FROM THE CONSOLE
Scanner input = new Scanner(System.in);
System.out.print("Enter three words separated by spaces:");
String s1 = input.next();
String s2 = input.next();
String s3 = input.next();
System.out.println("s1 is " + s1);
System.out.println("s2 is " + s2);
System.out.println("s3 is " + s3);
23
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
25. COMPARING STRINGS
⚫Don’t use ‘==’ to compare Strings
⚫it compares their memory addresses and not actual strings
(character sequences)
⚫Instead use the equalsmethod supplied by the String class:
⚫s.equals(t)
⚫returns true if s and t have same letters and sequence
⚫false otherwise
25
26. COMPARING STRINGS
String word1 = new String("Hello");
String word2 = new String("Hello");
if (word1 == word2){
System.out.println(true);
} else {
System.out.println(false);
}
false
T
wo different addresses
26
27. String word1 = new String("Hello");
String word2 = new String("Hello");
if (word1.equals(word2)){
System.out.println(true);
} else {
System.out.println(false);
}
true
compares the contents "Hello" with "Hello"
27
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
COMPARING STRINGS
29. String word1 = "Hello";
String word2 = "Hello";
if (word1 == word2){
System.out.println(true);
} else {
System.out.println(false);
}
true
⚫Interned Strings: Only one instance of “Hello” is stored
⚫so word1 and word2 will have the same address
29
COMPARING STRINGS
31. COMPARING STRINGS
Method Description
Returns true if this string is equal to string s1.
Returns true if this string is equal to string s1; it is case insensitive.
Returns an integer greater than 0, equal to 0, or less than 0 to indicate whether this string is
greater than, equal to, or greater than s1.
Same as compareTo except that the comparison is case insensitive.
Returns true if this string starts with the specified prefix.
Returns true if this string ends with the specified suffix.
equals(s1)
equalsIgnoreCase(s1)
compareTo(s1)
compareToIgnoreCase(s1)
startsWith(prefix)
endsWith(suffix)
31
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
OrderTwoCities
32. 32
import java.util.Scanner;
public class OrderTwoCities {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Prompt the user to enter two cities
System.out.print("Enter the first city: ");
String city1 = input.nextLine();
System.out.print("Enter the second city: ");
String city2 = input.nextLine();
if (city1.compareTo(city2) < 0)
System.out.println("The cities in alphabetical order are " +
city1 + " " + city2);
else
System.out.println("The cities in alphabetical order are " +
city2 + " " + city1);
}
}
OrderTwoCities
33. GETTING CHARACTERS FROM A STRING
String message = "Welcome to Java";
System.out.println(
"The first character in message is "
+ message.charAt(0));
33
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
34. READING A SINGLE CHARACTER FROM THE CONSOLE
Scanner input = new Scanner(System.in);
System.out.print("Enter a character: ");
String s = input.nextLine();
char ch = s.charAt(0);
System.out.print("The character entered is "+ch);
34
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
35. OBTAINING SUBSTRINGS
Method Description
Returns this string’s substring that begins with the character at the specified
beginIndex and extends to the end of the string, as shown in Figure 4.2.
Returns this string’s substring that begins at the specified beginIndex and
extends to the character at index endIndex – 1, as shown in Figure 9.6.
Note that the character at endIndex is not part of the substring.
substring(beginIndex)
substring(beginIndex,
endIndex)
35
36. FINDING A CHARACTER OR A SUBSTRING IN A STRING
Method Description
Returns the index of the first occurrence of ch in the string. Returns -1 if not
matched.
Returns the index of the first occurrence of ch after fromIndex in the string.
Returns -1 if not matched.
Returns the index of the first occurrence of string s in this string. Returns -1 if
not matched.
Returns the index of the first occurrence of string s in this string after
fromIndex. Returns -1 if not matched.
Returns the index of the last occurrence of ch in the string. Returns -1 if not
matched.
Returns the index of the last occurrence of ch before fromIndex in this
string. Returns -1 if not matched.
Returns the index of the last occurrence of string s. Returns -1 if not matched.
Returns the index of the last occurrence of string s before fromIndex.
Returns -1 if not matched.
indexOf(ch)
indexOf(ch, fromIndex)
indexOf(s)
indexOf(s, fromIndex)
lastIndexOf(ch)
lastIndexOf(ch,
fromIndex)
lastIndexOf(s)
lastIndexOf(s,
fromIndex)
36
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
37. FINDING A CHARACTER OR A SUBSTRING IN A STRING
int k = s.indexOf(' '); //3
String firstName = s.substring(0, k);
String lastName = s.substring(k + 1);
37
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
38. CONVERSION BETWEEN STRINGS AND NUMBERS
String intString = "15";
String doubleString = "56.77653";
int intValue =
Integer.parseInt(intString);
double doubleValue =
Double.parseDouble(doubleString);
String s2 = "" + intValue;
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
39. CASE STUDY: CONVERTING A HEXADECIMAL DIGIT TO A DECIMAL
VALUE
Write a program that converts a hexadecimal digit into a
decimal value.
39
HexDigit2Dec
https://liveexample.pearsoncmg.com/html/HexDigit2Dec.h
tml
40. FORMATTING OUTPUT
(c) Pearson Education, Inc. & Paul Fodor (CS Stony Brook)
The printf statement:
System.out.printf(format, items);
• format is a string that may consist of
substrings and format specifiers
• A format specifier begins with a percent sign and
specifies how an item should be displayed: a numeric
value, character, boolean value, or a string
41. FREQUENTLY-USED SPECIFIERS
Specifier Output
%b a boolean value
Example
true or false
%c
%d
a
a
character
decimal integer
'a'
200
%f a floating-point number 45.460000
%e a number in standard scientific notation 4.556000e+01
%s a string "Java is cool"
int count = 5;
double amount = 45.567899;
System.out.printf("count is %d and amount is %.2f", count, amount)
Displays: count is 5 and amount is 45.56
items
42. BITWISE OPERATIONS IN JAVA
⚫ T
o write programs at the machine-level, often you need to deal with
binary numbers directly and perform operations at the bit- level
⚫ Java provides the bitwise operators and shift operators
⚫The bit operators apply only to integer types (byte, short, int, and
long)
⚫All bitwise operators can form bitwise assignment operators, such as
=: |=, <<=, >>=, and >>>=
⚫ Bitwise AND: &
⚫1010 & 1001 yields 1000
System.out.print(10&9); // 8
⚫The AND of two corresponding bits yields a 1 if both bits are 1,
otherwise 0
43. BITWISE OPERATIONS IN JAVA
⚫ BitwiseOR:|
⚫The OR of two corresponding bits yields a1 ifeither bit is1
⚫10101110 | 10010010 yields10111110
class BitwiseOR {
public static void main(String[] args) {
int number1 = 12, number2 = 25, result;
result = number1 | number2;
System.out.println(result);
}
}
1100 | 12
11001 25
11101 = 29
43
44. BITWISE OPERATIONS IN JAVA
⚫ Bitwise exclusive OR: ^
⚫1010 ^ 1001 yields 0011
⚫The XOR of two corresponding bits yields a 1 only if two bits are
different.
⚫ One’s complement: ~
⚫~1010 yields 0101
⚫The operator toggles each bit from 0 to 1 and from 1 to 0.
⚫ Left shift: <<
⚫1010 << 2 yields 101000
System.out.print(10 << 2); // 40
⚫The operator shifts bits in the first operand left by the number of
bits specified in the second operand, filling with 0s on the right.
45. ⚫Right shift with sign extension: >>
⚫1010 >> 2 yields 10
System.out.print(10 >> 2); // 2
⚫The operator shifts bit in the first operand right by the
number of bits specified in the second operand, filling
with the highest (sign) bit on the left.
⚫Unsigned right shift with zero extension: >>>
System.out.print(-10 >>> 2); // 1073741821
⚫The operator shifts bit in the first operand right by the
number of bits specified in the second operand, filling with
0s on the left.
45
BITWISE OPERATIONS IN JAVA
46. CONSTANTS IN BINARY FORMAT
byte fourTimesThree = 0b1100;
byte data = 0b0000110011;
short number = 0b111111111111111;
int overflow = 0b10101010101010101010101010101011;
long bow = 0b101010101010101010101010101010111L;
⚫ Just be careful not to overflow the numbers with too much data,or else you'll get acompiler
error:
byte data = 0b1100110011;
// Type mismatch: cannot convert from int to byte
⚫New feature in Java7 known asnumeric literals with underscores:
⚫int overflow = 0b1010_1010_1010_1010_1010_1010_1010_1011;
⚫long bow = 0b1 01010101 01010101 01010101 01010111L;
46
47. CONSTANTS IN OCTAL AND HEXADECIMAL FORMAT
int x = 010;
int y = 0xf;
(C) PEARSON EDUCATION, INC. & PAUL FODOR (CS STONY BROOK)
//octal = 8
//hexadecimal = 15
In computer science, string interning is a method of storing only one copy of each distinct string value, which must be immutable. Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned.