javastringexample problems using string classfedcoordinator
Java strings are sequences of characters that are treated as objects. The String class provides methods to create and manipulate strings. Strings are immutable, so the StringBuffer and StringBuilder classes provide mutable alternatives. Key string methods include concat(), equals(), substring(), length(), and indexOf(). The StringBuffer class is synchronized and thread-safe, while the StringBuilder class is non-synchronized and more efficient for single-threaded use.
String Handling, Inheritance, Packages and InterfacesPrabu U
The presentation starts with string handling. Then the concepts of inheritance is detailed. Finally the concepts of packages and interfaces are detailed.
This document discusses Java strings and provides information about:
1. What strings are in Java and how they are treated as objects of the String class. Strings are immutable.
2. Two ways to create String objects: using string literals or the new keyword.
3. Important string methods like concatenation, comparison, substring, and length; and string classes like StringBuffer and StringBuilder that allow mutability.
Wrapper classes allow primitive data types to be used as objects. Wrapper classes include Integer, Double, Boolean etc. Strings in Java are immutable - their values cannot be changed once created. StringBuffer and StringBuilder can be used to create mutable strings that can be modified. StringTokenizer can split a string into tokens based on a specified delimiter.
The document discusses string handling in Java. It covers:
1) Strings are immutable objects that cannot be modified, but new strings can be created from existing ones. StringBuffer and StringBuilder allow mutable strings.
2) Common string operations like comparison, searching, and concatenation are built into the language.
3) Methods like length(), charAt(), substring(), and trim() allow extracting characters from strings.
This document discusses strings and string buffers in Java. It defines strings as sequences of characters that are class objects implemented using the String and StringBuffer classes. It provides examples of declaring, initializing, concatenating and using various methods like length(), charAt() etc. on strings. The document also introduces the StringBuffer class for mutable strings and lists some common StringBuffer functions.
This document discusses arrays and StringBuffer class in Java. It defines single and multi-dimensional arrays and provides examples. It also explains the difference between String and StringBuffer classes and lists common methods of StringBuffer class like append(), insert(), reverse() etc. Examples are given to demonstrate the usage of these StringBuffer methods.
The document discusses various Java string concepts:
1. Java strings are immutable sequences of characters that are objects of the String class. The StringBuffer class can be used to modify strings.
2. Common string methods include length(), charAt(), compareTo(), concat(), and substring().
3. The StringBuffer class represents mutable strings and defines methods like append(), insert(), delete(), and replace() to modify the string content.
4. Enumerated types in Java can be defined using the enum keyword to represent a fixed set of constants, like the days of the week.
The StringBuilder class in Java is used to create mutable strings. It is similar to the StringBuffer class but is non-synchronized. Some key methods of StringBuilder include append() to add to the string, insert() to insert into the string, replace() to replace part of the string, and delete() to remove part of the string. StringBuilder also allows getting and setting the capacity, length, and characters of the string.
In the given example only one object will be created. Firstly JVM will not fi...Indu32
In the given example only one object will be created. Firstly JVM will not find any string object with the value “Welcome” in the string constant pool, so it will create a new object. After that it will find the string with the value “Welcome” in the pool, it will not create a new object but will return the reference to the same instance. In this article, we will learn about Java Strings.
The StringBuffer class represents mutable sequences of characters. It is similar to strings but allows modifications by providing methods like append(), insert(), delete(), and replace(). StringBuffer has a default capacity of 16 characters that is increased automatically when more space is needed to store character sequences. It is used by the compiler to implement string concatenation with the + operator.
The document discusses the StringBuffer class in Java. Some key points:
- StringBuffer is like String but mutable and growable, used for string concatenation.
- It has methods to append, insert, delete, and modify characters. As characters are added and removed, the StringBuffer will automatically increase capacity if needed.
- Common methods include append(), insert(), delete(), replace(), reverse(), and substring() to modify the character sequence within a StringBuffer.
The document discusses strings and StringBuffers in Java. Strings are immutable sequences of characters represented by the String class. StringBuffers allow modifying character sequences and are represented by the StringBuffer class. The summary provides an overview of common string and StringBuffer operations like concatenation, extraction, comparison, and modification.
String objects in Java are immutable and stored in a string pool to improve performance. The StringBuffer class can be used to create mutable strings that can be modified after creation. It provides methods like append(), insert(), replace(), and delete() to modify the string content. The ensureCapacity() method on StringBuffer is used to reserve enough memory to reduce reallocation as the string is modified.
Packages in Java prevent naming conflicts, control access, and make classes easier to locate and use. A package groups related types and provides namespace management and access protection. Exceptions in Java handle runtime errors to maintain normal program flow. There are three types of exceptions: checked exceptions which are verified at compile-time; unchecked exceptions which are verified at runtime; and errors which are irrecoverable. Multithreading allows concurrent execution of program parts through threads, which can be created by extending the Thread class or implementing the Runnable interface.
This document provides an overview of arrays in C#, including:
- Arrays are fixed-length collections that store elements of the same type. They can be one-dimensional or multidimensional.
- Elements are accessed via an index that starts at 0. The Length property returns the array size.
- Common operations include initialization, iteration with for loops and foreach, and passing arrays to methods.
- Strings are objects that can be treated similarly to character arrays. Common string methods include comparison, searching, and manipulation.
- The StringBuilder class provides a mutable alternative to immutable strings for efficient string operations.
Strings In OOP(Object oriented programming)Danial Virk
The document discusses strings and string handling in Java. It covers the String and StringBuffer classes, basic string methods like length(), substring(), indexOf(), and replace(). It also discusses parsing strings with StringTokenizer and the differences between StringBuffer and String in terms of mutability and capacity. StringBuffer allows growing the string size while String is immutable.
This document discusses the StringBuffer and StringBuilder classes in Java. It explains that StringBuffer can be used to create mutable strings, while StringBuilder is similar but non-synchronized. It outlines several key methods for each class, such as append(), insert(), reverse(), substring(), and describes how to construct and manipulate string objects in Java.
The document discusses the difference between constructors and methods in Java. Constructors are used to initialize an object's state and must not have a return type, while methods are used to expose an object's behavior and must have a return type. Constructors are implicitly invoked, while methods are explicitly invoked. The Java compiler provides a default constructor if none is defined, but does not provide default methods. Constructors must have the same name as the class, but method names are more flexible.
This document provides an overview of strings in C# programming. It defines what a string is, how to declare string variables and literals, and describes several common string methods like ToUpper(), Trim(), Contains(), Split(), IndexOf(), and Replace(). The objectives are to learn how to construct programs that format strings and to explain how string methods are implemented in C# to manipulate text content. Examples of string method usage are provided.
Wrapper classes allow primitive data types to be used as objects. The key reasons for wrapper classes are:
1) Collections like ArrayList only support objects, so wrapper classes allow primitive types to be stored.
2) Wrapper classes have useful methods to manipulate primitive values as objects.
3) There are eight wrapper classes that correspond to the eight primitive types: Integer, Double, Character, etc. These classes have methods like parse, toString, and type conversion methods.
The document discusses strings in C++. It defines strings as arrays of characters and describes how to declare, initialize, input, and output strings. It also discusses storing multiple strings using a 2D character array. Finally, it lists and provides the syntax for various string handling functions in C++ like strcpy(), strcat(), strlen(), strcmp(), etc.
This document discusses strings in Java. It explains that strings are immutable sequences of characters that can be represented by the String, StringBuffer, or StringBuilder classes. It covers string literals, the string literal pool, comparing and concatenating strings, useful string methods, and creating mutable strings using StringBuffer. It also discusses string interning and representing objects as strings using the toString() method.
This document provides an overview of key concepts in object-oriented programming in Java including classes, objects, methods, constructors, arrays, strings, and vectors. It defines classes as templates that define the data and behaviors of objects. Methods represent behaviors of classes. Constructors initialize objects. Arrays are containers that hold a fixed number of values of a single type. Strings are sequences of characters that can be manipulated using methods. Vectors are dynamic arrays that can grow or shrink as needed. The document includes examples of creating objects from classes, defining methods and constructors, declaring and initializing arrays, performing string operations, and using common vector methods.
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 StringBuilder class in Java is used to create mutable strings. It is similar to the StringBuffer class but is non-synchronized. Some key methods of StringBuilder include append() to add to the string, insert() to insert into the string, replace() to replace part of the string, and delete() to remove part of the string. StringBuilder also allows getting and setting the capacity, length, and characters of the string.
In the given example only one object will be created. Firstly JVM will not fi...Indu32
In the given example only one object will be created. Firstly JVM will not find any string object with the value “Welcome” in the string constant pool, so it will create a new object. After that it will find the string with the value “Welcome” in the pool, it will not create a new object but will return the reference to the same instance. In this article, we will learn about Java Strings.
The StringBuffer class represents mutable sequences of characters. It is similar to strings but allows modifications by providing methods like append(), insert(), delete(), and replace(). StringBuffer has a default capacity of 16 characters that is increased automatically when more space is needed to store character sequences. It is used by the compiler to implement string concatenation with the + operator.
The document discusses the StringBuffer class in Java. Some key points:
- StringBuffer is like String but mutable and growable, used for string concatenation.
- It has methods to append, insert, delete, and modify characters. As characters are added and removed, the StringBuffer will automatically increase capacity if needed.
- Common methods include append(), insert(), delete(), replace(), reverse(), and substring() to modify the character sequence within a StringBuffer.
The document discusses strings and StringBuffers in Java. Strings are immutable sequences of characters represented by the String class. StringBuffers allow modifying character sequences and are represented by the StringBuffer class. The summary provides an overview of common string and StringBuffer operations like concatenation, extraction, comparison, and modification.
String objects in Java are immutable and stored in a string pool to improve performance. The StringBuffer class can be used to create mutable strings that can be modified after creation. It provides methods like append(), insert(), replace(), and delete() to modify the string content. The ensureCapacity() method on StringBuffer is used to reserve enough memory to reduce reallocation as the string is modified.
Packages in Java prevent naming conflicts, control access, and make classes easier to locate and use. A package groups related types and provides namespace management and access protection. Exceptions in Java handle runtime errors to maintain normal program flow. There are three types of exceptions: checked exceptions which are verified at compile-time; unchecked exceptions which are verified at runtime; and errors which are irrecoverable. Multithreading allows concurrent execution of program parts through threads, which can be created by extending the Thread class or implementing the Runnable interface.
This document provides an overview of arrays in C#, including:
- Arrays are fixed-length collections that store elements of the same type. They can be one-dimensional or multidimensional.
- Elements are accessed via an index that starts at 0. The Length property returns the array size.
- Common operations include initialization, iteration with for loops and foreach, and passing arrays to methods.
- Strings are objects that can be treated similarly to character arrays. Common string methods include comparison, searching, and manipulation.
- The StringBuilder class provides a mutable alternative to immutable strings for efficient string operations.
Strings In OOP(Object oriented programming)Danial Virk
The document discusses strings and string handling in Java. It covers the String and StringBuffer classes, basic string methods like length(), substring(), indexOf(), and replace(). It also discusses parsing strings with StringTokenizer and the differences between StringBuffer and String in terms of mutability and capacity. StringBuffer allows growing the string size while String is immutable.
This document discusses the StringBuffer and StringBuilder classes in Java. It explains that StringBuffer can be used to create mutable strings, while StringBuilder is similar but non-synchronized. It outlines several key methods for each class, such as append(), insert(), reverse(), substring(), and describes how to construct and manipulate string objects in Java.
The document discusses the difference between constructors and methods in Java. Constructors are used to initialize an object's state and must not have a return type, while methods are used to expose an object's behavior and must have a return type. Constructors are implicitly invoked, while methods are explicitly invoked. The Java compiler provides a default constructor if none is defined, but does not provide default methods. Constructors must have the same name as the class, but method names are more flexible.
This document provides an overview of strings in C# programming. It defines what a string is, how to declare string variables and literals, and describes several common string methods like ToUpper(), Trim(), Contains(), Split(), IndexOf(), and Replace(). The objectives are to learn how to construct programs that format strings and to explain how string methods are implemented in C# to manipulate text content. Examples of string method usage are provided.
Wrapper classes allow primitive data types to be used as objects. The key reasons for wrapper classes are:
1) Collections like ArrayList only support objects, so wrapper classes allow primitive types to be stored.
2) Wrapper classes have useful methods to manipulate primitive values as objects.
3) There are eight wrapper classes that correspond to the eight primitive types: Integer, Double, Character, etc. These classes have methods like parse, toString, and type conversion methods.
The document discusses strings in C++. It defines strings as arrays of characters and describes how to declare, initialize, input, and output strings. It also discusses storing multiple strings using a 2D character array. Finally, it lists and provides the syntax for various string handling functions in C++ like strcpy(), strcat(), strlen(), strcmp(), etc.
This document discusses strings in Java. It explains that strings are immutable sequences of characters that can be represented by the String, StringBuffer, or StringBuilder classes. It covers string literals, the string literal pool, comparing and concatenating strings, useful string methods, and creating mutable strings using StringBuffer. It also discusses string interning and representing objects as strings using the toString() method.
This document provides an overview of key concepts in object-oriented programming in Java including classes, objects, methods, constructors, arrays, strings, and vectors. It defines classes as templates that define the data and behaviors of objects. Methods represent behaviors of classes. Constructors initialize objects. Arrays are containers that hold a fixed number of values of a single type. Strings are sequences of characters that can be manipulated using methods. Vectors are dynamic arrays that can grow or shrink as needed. The document includes examples of creating objects from classes, defining methods and constructors, declaring and initializing arrays, performing string operations, and using common vector methods.
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.
- HTML5 is the newest version of HTML that began development in 2004 and was officially published in 2012.
- It incorporates features from prior HTML versions and adds new elements and features like built-in audio/video, canvas drawing, and offline web apps.
- HTML5 simplifies elements like DOCTYPE and <html> and removes unnecessary code like XML namespaces.
This document provides an introduction to the Python programming language. It discusses that Python was created in 1991, is an interpreted language useful for scripting, and is used by many companies and organizations. It also gives instructions on installing Python on Windows, Mac OS X, and Linux systems. Finally, it demonstrates some basic Python concepts like print statements, comments, functions, and whitespace significance through simple code examples.
This document discusses Java interfaces. It describes how interfaces define abstract methods that implementing classes must provide. Interfaces can contain constant variables and default methods. Classes can inherit methods from extended interfaces and must implement inherited abstract methods. Default methods provide an implementation within an interface that classes can optionally override. Static methods are defined with the static keyword and are not inherited by implementing classes. Polymorphism allows objects to be accessed using superclass or interface references.
This document discusses JavaScript functions. It explains that functions are first-class objects that can be stored in variables, passed as arguments, and returned from other functions. It provides examples of defining, calling, and returning values from functions. It also covers optional parameters, anonymous functions, higher-order functions, and functions as methods.
This document provides an overview of interfaces in Java. It discusses that interfaces define abstract methods that implementing classes must provide, interfaces can contain constant variables and default methods, and interfaces cannot be instantiated directly. It also covers interface inheritance, default methods introduced in Java 8, static methods in interfaces, and polymorphism through interfaces.
This document summarizes a session on the Java technology. It introduces key concepts like the Java Runtime Environment (JRE) and Java Virtual Machine (JVM). The JRE loads and executes Java classes, verifies code, and performs garbage collection. The JVM interprets Java bytecode and defines instruction sets, registers and memory areas. The document provides examples of a simple Java application and how to compile and run Java code, as well as examples of common compile-time and runtime errors.
This document provides an overview of the Java programming language. It discusses Java's key features such as being robust, multithreaded, architecture-neutral, interpreted, high-performance, distributed, and dynamic. Additional features added in later Java releases include Java Beans, serialization, remote method invocation, database connectivity, and more. Since its inception, Java usage has spread across hardware development, standalone applications, client-server applications, distributed applications, and enterprise applications, establishing Java as a full-fledged technology.
Java is a set of computer software and specifications that provides a system for developing application software and deploying it across multiple platforms. It is widely used to develop networked applications, embedded systems, mobile applications, games, web content and enterprise software. With millions of developers worldwide, Java enables efficient development and use of exciting applications.
Form-based login in Spring Security is configured using the <form-login> element. The action URL and input field names can be customized, and a custom login page can be specified using the login-page attribute. On login error, users are redirected to the URL configured in the authentication-failure-url attribute, and the error message is available in the SPRING_SECURITY_LAST_EXCEPTION session attribute.
A measles outbreak originating in West Texas has been linked to confirmed cases in New Mexico, with additional cases reported in Oklahoma and Kansas. The current case count is 795 from Texas, New Mexico, Oklahoma, and Kansas. 95 individuals have required hospitalization, and 3 deaths, 2 children in Texas and one adult in New Mexico. These fatalities mark the first measles-related deaths in the United States since 2015 and the first pediatric measles death since 2003.
The YSPH Virtual Medical Operations Center Briefs (VMOC) were created as a service-learning project by faculty and graduate students at the Yale School of Public Health in response to the 2010 Haiti Earthquake. Each year, the VMOC Briefs are produced by students enrolled in Environmental Health Science Course 581 - Public Health Emergencies: Disaster Planning and Response. These briefs compile diverse information sources – including status reports, maps, news articles, and web content– into a single, easily digestible document that can be widely shared and used interactively. Key features of this report include:
- Comprehensive Overview: Provides situation updates, maps, relevant news, and web resources.
- Accessibility: Designed for easy reading, wide distribution, and interactive use.
- Collaboration: The “unlocked" format enables other responders to share, copy, and adapt seamlessly. The students learn by doing, quickly discovering how and where to find critical information and presenting it in an easily understood manner.
This chapter provides an in-depth overview of the viscosity of macromolecules, an essential concept in biophysics and medical sciences, especially in understanding fluid behavior like blood flow in the human body.
Key concepts covered include:
✅ Definition and Types of Viscosity: Dynamic vs. Kinematic viscosity, cohesion, and adhesion.
⚙️ Methods of Measuring Viscosity:
Rotary Viscometer
Vibrational Viscometer
Falling Object Method
Capillary Viscometer
🌡️ Factors Affecting Viscosity: Temperature, composition, flow rate.
🩺 Clinical Relevance: Impact of blood viscosity in cardiovascular health.
🌊 Fluid Dynamics: Laminar vs. turbulent flow, Reynolds number.
🔬 Extension Techniques:
Chromatography (adsorption, partition, TLC, etc.)
Electrophoresis (protein/DNA separation)
Sedimentation and Centrifugation methods.
The ever evoilving world of science /7th class science curiosity /samyans aca...Sandeep Swamy
The Ever-Evolving World of
Science
Welcome to Grade 7 Science4not just a textbook with facts, but an invitation to
question, experiment, and explore the beautiful world we live in. From tiny cells
inside a leaf to the movement of celestial bodies, from household materials to
underground water flows, this journey will challenge your thinking and expand
your knowledge.
Notice something special about this book? The page numbers follow the playful
flight of a butterfly and a soaring paper plane! Just as these objects take flight,
learning soars when curiosity leads the way. Simple observations, like paper
planes, have inspired scientific explorations throughout history.
How to Subscribe Newsletter From Odoo 18 WebsiteCeline George
Newsletter is a powerful tool that effectively manage the email marketing . It allows us to send professional looking HTML formatted emails. Under the Mailing Lists in Email Marketing we can find all the Newsletter.
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...Celine George
Analytic accounts are used to track and manage financial transactions related to specific projects, departments, or business units. They provide detailed insights into costs and revenues at a granular level, independent of the main accounting system. This helps to better understand profitability, performance, and resource allocation, making it easier to make informed financial decisions and strategic planning.
A measles outbreak originating in West Texas has been linked to confirmed cases in New Mexico, with additional cases reported in Oklahoma and Kansas. The current case count is 817 from Texas, New Mexico, Oklahoma, and Kansas. 97 individuals have required hospitalization, and 3 deaths, 2 children in Texas and one adult in New Mexico. These fatalities mark the first measles-related deaths in the United States since 2015 and the first pediatric measles death since 2003.
The YSPH Virtual Medical Operations Center Briefs (VMOC) were created as a service-learning project by faculty and graduate students at the Yale School of Public Health in response to the 2010 Haiti Earthquake. Each year, the VMOC Briefs are produced by students enrolled in Environmental Health Science Course 581 - Public Health Emergencies: Disaster Planning and Response. These briefs compile diverse information sources – including status reports, maps, news articles, and web content– into a single, easily digestible document that can be widely shared and used interactively. Key features of this report include:
- Comprehensive Overview: Provides situation updates, maps, relevant news, and web resources.
- Accessibility: Designed for easy reading, wide distribution, and interactive use.
- Collaboration: The “unlocked" format enables other responders to share, copy, and adapt seamlessly. The students learn by doing, quickly discovering how and where to find critical information and presenting it in an easily understood manner.
CURRENT CASE COUNT: 817 (As of 05/3/2025)
• Texas: 688 (+20)(62% of these cases are in Gaines County).
• New Mexico: 67 (+1 )(92.4% of the cases are from Eddy County)
• Oklahoma: 16 (+1)
• Kansas: 46 (32% of the cases are from Gray County)
HOSPITALIZATIONS: 97 (+2)
• Texas: 89 (+2) - This is 13.02% of all TX cases.
• New Mexico: 7 - This is 10.6% of all NM cases.
• Kansas: 1 - This is 2.7% of all KS cases.
DEATHS: 3
• Texas: 2 – This is 0.31% of all cases
• New Mexico: 1 – This is 1.54% of all cases
US NATIONAL CASE COUNT: 967 (Confirmed and suspected):
INTERNATIONAL SPREAD (As of 4/2/2025)
• Mexico – 865 (+58)
‒Chihuahua, Mexico: 844 (+58) cases, 3 hospitalizations, 1 fatality
• Canada: 1531 (+270) (This reflects Ontario's Outbreak, which began 11/24)
‒Ontario, Canada – 1243 (+223) cases, 84 hospitalizations.
• Europe: 6,814
Exploring Substances:
Acidic, Basic, and
Neutral
Welcome to the fascinating world of acids and bases! Join siblings Ashwin and
Keerthi as they explore the colorful world of substances at their school's
National Science Day fair. Their adventure begins with a mysterious white paper
that reveals hidden messages when sprayed with a special liquid.
In this presentation, we'll discover how different substances can be classified as
acidic, basic, or neutral. We'll explore natural indicators like litmus, red rose
extract, and turmeric that help us identify these substances through color
changes. We'll also learn about neutralization reactions and their applications in
our daily lives.
by sandeep swamy
Odoo Inventory Rules and Routes v17 - Odoo SlidesCeline George
Odoo's inventory management system is highly flexible and powerful, allowing businesses to efficiently manage their stock operations through the use of Rules and Routes.
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsDrNidhiAgarwal
Unemployment is a major social problem, by which not only rural population have suffered but also urban population are suffered while they are literate having good qualification.The evil consequences like poverty, frustration, revolution
result in crimes and social disorganization. Therefore, it is
necessary that all efforts be made to have maximum.
employment facilities. The Government of India has already
announced that the question of payment of unemployment
allowance cannot be considered in India
Geography Sem II Unit 1C Correlation of Geography with other school subjectsProfDrShaikhImran
The correlation of school subjects refers to the interconnectedness and mutual reinforcement between different academic disciplines. This concept highlights how knowledge and skills in one subject can support, enhance, or overlap with learning in another. Recognizing these correlations helps in creating a more holistic and meaningful educational experience.
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessMark Soia
Boost your chances of passing the 2V0-11.25 exam with CertsExpert reliable exam dumps. Prepare effectively and ace the VMware certification on your first try
Quality dumps. Trusted results. — Visit CertsExpert Now: https://www.certsexpert.com/2V0-11.25-pdf-questions.html
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetSritoma Majumder
Introduction
All the materials around us are made up of elements. These elements can be broadly divided into two major groups:
Metals
Non-Metals
Each group has its own unique physical and chemical properties. Let's understand them one by one.
Physical Properties
1. Appearance
Metals: Shiny (lustrous). Example: gold, silver, copper.
Non-metals: Dull appearance (except iodine, which is shiny).
2. Hardness
Metals: Generally hard. Example: iron.
Non-metals: Usually soft (except diamond, a form of carbon, which is very hard).
3. State
Metals: Mostly solids at room temperature (except mercury, which is a liquid).
Non-metals: Can be solids, liquids, or gases. Example: oxygen (gas), bromine (liquid), sulphur (solid).
4. Malleability
Metals: Can be hammered into thin sheets (malleable).
Non-metals: Not malleable. They break when hammered (brittle).
5. Ductility
Metals: Can be drawn into wires (ductile).
Non-metals: Not ductile.
6. Conductivity
Metals: Good conductors of heat and electricity.
Non-metals: Poor conductors (except graphite, which is a good conductor).
7. Sonorous Nature
Metals: Produce a ringing sound when struck.
Non-metals: Do not produce sound.
Chemical Properties
1. Reaction with Oxygen
Metals react with oxygen to form metal oxides.
These metal oxides are usually basic.
Non-metals react with oxygen to form non-metallic oxides.
These oxides are usually acidic.
2. Reaction with Water
Metals:
Some react vigorously (e.g., sodium).
Some react slowly (e.g., iron).
Some do not react at all (e.g., gold, silver).
Non-metals: Generally do not react with water.
3. Reaction with Acids
Metals react with acids to produce salt and hydrogen gas.
Non-metals: Do not react with acids.
4. Reaction with Bases
Some non-metals react with bases to form salts, but this is rare.
Metals generally do not react with bases directly (except amphoteric metals like aluminum and zinc).
Displacement Reaction
More reactive metals can displace less reactive metals from their salt solutions.
Uses of Metals
Iron: Making machines, tools, and buildings.
Aluminum: Used in aircraft, utensils.
Copper: Electrical wires.
Gold and Silver: Jewelry.
Zinc: Coating iron to prevent rusting (galvanization).
Uses of Non-Metals
Oxygen: Breathing.
Nitrogen: Fertilizers.
Chlorine: Water purification.
Carbon: Fuel (coal), steel-making (coke).
Iodine: Medicines.
Alloys
An alloy is a mixture of metals or a metal with a non-metal.
Alloys have improved properties like strength, resistance to rusting.
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetSritoma Majumder
Ad
Java Strings methods and operations.ppt
2. ● This module introduces the participants to the string
object.
● Importance of String Objects and How to create them.
● Varioius Constructors that are available to create
Strings.
● Working with methods that are available with strings.
● Understanding Necessity of StringBuffer class.
● Working with methods of StringBuffer class.
● Introduction to StringBuilder class.
● Working with methods of StringBuilder class.
Module Overview
2
3. Uderstand the concept of Strings and create string
objects.
Understand advantages and disadvantages of Strings.
Declare and create Strings using different types of
constructors.
Working with Strings and its different types of
methods.
Determine the usage of String Buffer and
StringBuilder.
Objectives
3
4. String: Strings are a sequence of characters, which are
implemented as objects.
Charecteristics of Strings:
• The String class is immutable,meaning once created
a String object cannot be changed.
• If any modifications is done to the existing string
object a new object is created internally.
• String objects are created by using the new keyword
and a constructor. The String class has eleven
constructors that allow you to provide the initial
value of the string using different sources, such as an
array of characters.
String
4
5. String Declaration
String Declaration: The most direct way to create a
string is as follows;
String greeting = "Hello world!";//String literal
Other Common Declarations:
String helloString = new String(helloArray);
char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
6. Example of String Class.
public class StringDemo{
public static void main(String args[]){
char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
String helloString = new String(helloArray);
String helloString2 = new String(“hello!!!”);
System.out.println( helloString );
}
}
Output:hello.
7. Methods Of String
Accessor:Methods used to obtain information
about an object are known as accessor methods.
One accessor method that you can use with
strings is the length() method, which returns the
number of characters contained in the string
object.
Syntax:
<StringOBject>.length();
Example:
String name = “java”;
int length = name.length();
8. Methods of String(Cont…)
Concatenating Strings:One String can be
concatenated to another string.This will produce
a new string object joining two strings.
Strings are more commonly concatenated with the
+ operator and concat method.
Syntax:
string1.concat(string2);
string1+string2
9. Methods of String(Cont…)
String substring(int beginIndex)
Returns a new string that is a substring of this string.
char[] toCharArray()
Converts this string to a new character array.
String toLowerCase()
Converts all of the characters in this String to lower
case using the rules of the default locale.
String replace(char oldChar, char newChar)
Returns a new string resulting from replacing all
occurrences of oldChar in this string with newChar.
String[] split(String regex)
Splits this string around matches of the given regular
expression.
10. String toString()
This object (which is already a string!) is itself returned.
String toUpperCase()
Converts all of the characters in this String to upper case
using the rules of the default locale.
String trim()
Returns a copy of the string, with leading and trailing
whitespace omitted.
boolean startsWith(String prefix)
Tests if this string starts with the specified prefix.
boolean contentEquals(StringBuffer sb)
Returns true if and only if this String represents the same
sequence of characters as the specified StringBuffer.
Methods of String(Cont…)
11. Working with methods using Strings
Like other values to (parameters)methods, Strings
also can be passed to methods.
Ex:
public String printString(String s) {
System.out.println(s);
return “modified”+s;
}
String newString =printString(new
String(“Java”));//invoking an array
12. Necessity of StringBuffer
String objects are immutable,meaning
modifications to the string object cannot be done
once created. If done a new String Object will be
created in memory.
The StringBuffer and StringBuilder classes are
used when there is a necessity to make alot of
modifications to Strings of characters.
StringBuffer and Stringbuilder can be modified
over and over again with out leaving behind alot
of new unused objects.
13. String Buffers Methods
public StringBuffer append(String s)
Updates the value of the object that invoked the
method. The method takes boolean, char, int,
long, Strings etc.
public StringBuffer reverse()
The method reverses the value of the
StringBuffer object that invoked the method.
public delete(int start, int end)
Deletes the string starting from start index until
end index.
14. String Buffers Methods
void setLength(int newLength)
Sets the length of this String buffer.
int length()
Returns the length (character count) of this string
buffer.
void ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least
equal to the specified minimum.
int capacity()
Returns the current capacity of the String buffer.
15. String Builder Methods
int length()
Returns the length (character count) of this string
buffer.
void ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least
equal to the specified minimum.
int capacity()
Returns the current capacity of the String buffer.
reverse() :Causes this character sequence to be
replaced by the reverse of the sequence.
16. StringBuilder vs StringBuffer
Below is a table that contains differences between
StringBuilder and StringBuffer.
StringBuffer StringBuilder
It is mutable It is mutable
It is
synchronized,provides
ThreadSafety.
It is non
synchronized.Provides no
ThreadSafety.
Capacity increases
automatically .
Capacity increases
automatically .
17. Excercise
Create an application that will convert a given
character array to a string.
Creat an application that will create a reverse of
a string.
Create an application that uses StringBuffer to
concatinate the user input.
Create an application that uses a StringBuilder
and String Buffer and insert one in another.