SlideShare a Scribd company logo
5
Most read
7
Most read
9
Most read
IDEAL EYES BUSINESS COLLEGE
A
PRESENTATION
STRING IN
JAVA LANGUAGE
1
PERSENTED BY:- VIVEK KUMARPERSENTED TO:- PANKAJ SIR
String
 Generally string is a sequence of characters. But in java,
string is an object.
 String class is used to create string object.
 string is a 16-bit Unicode character .
There are two ways to create String object:
1. By string literal 2. By new keyword
string literal
For example:-
String s1="Welcome";
String s2="Welcome"; //no new object will be created
Note:- String objects are stored in a special memory area known as
string constant pool inside the Heap memory.
String literal is create by double quote.
Each time you create a string literal, the JVM checks the string
constant pool first. If the string already exists in the pool, a
reference to the pooled instance returns. If the string does not
exist in the pool, a new String object instantiates, then is
placed in the pool
In the above example only one object will be created . First time JVM will find no string object with
the name "Welcome" in string constant pool , so it will create a new object . Second time it will find
the string with the name "Welcome" in string constant pool , so it will not create new object
whether will return the reference to the same instance.
By string literal
class String _literal
{
public static void main(String args[])
{
String x ="java";
String x1="java";
System.out.println( "x="+x);
}
}
By new keyword
In such case, JVM will create a new String object in normal (
nonpool ) Heap memory and the literal "Welcome" will be
placed in the string constant pool . The variable s will refer to
the object in Heap( nonpool ).
String s=new String("Welcome");
//creates two objects and one reference variale
For example:-
By new keyword
1. class new_keyword
2. {
3. public static void main(String args[])
4. {
5. String x ="java";
6. String s=new String("Welcome");
7. System.out.println( "x="+s);
8. System.out.println( "x="+x);
9. }
10. }
Methods of String class
java.lang.String class provides a lot of methods to work on string. Let's see the
commonly used methods of String class.
1. charAt() Returns the character located at the specified index
2. concat() Appends one String to the end of another ( "+" also works)
3. equalsIgnoreCase() Determines the equality of two Strings, ignoring case
4. length() Returns the number of characters in a String
5. replace() Replaces occurrences of a character with a new character
6. substring() Returns a part of a String
7. toLowerCase() Returns a String with uppercase characters converted
8. toString() Returns the value of a String
9. toUpperCase() Returns a String with lowercase characters converted
10.trim() Removes whitespace from the ends of a String
IMPORTANT METHODS IN THE STRING CLASS
charAt() method
class charAt
{
public static void main(String args[])
{
String s="Sachin";
System.out.println(s.charAt(5));
System.out.println(s.charAt(3));
}
}
toUpperCase() and toLowerCase() method
class low_upper
{
public static void main(String args[])
{
String s="Sachin";
System.out.println(s.toUpperCase());
System.out.println(s.toLowerCase());
System.out.println(s);
}
}
JAVA IS EVERYWHERE

More Related Content

PPTX
I/O Streams
PPS
String and string buffer
PPTX
String, string builder, string buffer
PPTX
Java Foundations: Methods
PPTX
Strings in Java
PPTX
Java string handling
PDF
I/O Streams
String and string buffer
String, string builder, string buffer
Java Foundations: Methods
Strings in Java
Java string handling

What's hot (20)

PPT
Exception Handling in JAVA
PPTX
Type casting in java
PPS
Java Exception handling
PDF
Arrays in Java
PPTX
Java Strings
PPTX
Classes objects in java
PPTX
Java exception handling
PPTX
Arrays in java
PPT
Java multi threading
PPTX
Super Keyword in Java.pptx
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
Data types in java
PDF
PPT
Method overriding
PPTX
C# classes objects
PPTX
Control Statements in Java
PPT
Java Threads
PDF
Class and Objects in Java
PPT
Java Networking
Exception Handling in JAVA
Type casting in java
Java Exception handling
Arrays in Java
Java Strings
Classes objects in java
Java exception handling
Arrays in java
Java multi threading
Super Keyword in Java.pptx
Basic Concepts of OOPs (Object Oriented Programming in Java)
Data types in java
Method overriding
C# classes objects
Control Statements in Java
Java Threads
Class and Objects in Java
Java Networking
Ad

Viewers also liked (15)

PPTX
Java strings
PPTX
String java
PPTX
Java String
PDF
String handling(string class)
PPT
String Handling
PPTX
Introduction to Java Strings, By Kavita Ganesan
PPTX
String Builder & String Buffer (Java Programming)
PPTX
05 Java Language And OOP Part V
PPT
8. String
PPTX
Final keyword in java
PDF
Arrays string handling java packages
ODP
Java 06 Strings Arrays
PDF
[Curso Java Basico] Exercicios Aulas 16 17
PPT
Object Oriented Programming with Java
PDF
Core java complete notes - Contact at +91-814-614-5674
Java strings
String java
Java String
String handling(string class)
String Handling
Introduction to Java Strings, By Kavita Ganesan
String Builder & String Buffer (Java Programming)
05 Java Language And OOP Part V
8. String
Final keyword in java
Arrays string handling java packages
Java 06 Strings Arrays
[Curso Java Basico] Exercicios Aulas 16 17
Object Oriented Programming with Java
Core java complete notes - Contact at +91-814-614-5674
Ad

Similar to String in java (20)

PPTX
Java Strings.pptxJava Strings.pptxJava Strings.pptx
PPTX
Day_5.1.pptx
PPTX
What is String in Java?
PDF
Java - Strings Concepts
PPT
Strings in javamnjn ijnjun oinoin oinoi .ppt
PPTX
3.1 STRINGS (1) java jksdbkjdbsjsef.pptx
PPSX
Java String class
PDF
Java Presentation on the topic of string
PPTX
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
PPT
Text processing
PDF
Java R20 - UNIT-5.pdf
DOCX
Java R20 - UNIT-5.docx
PDF
PPTX
1st.pptx
PPTX
String.pptx
PPTX
Introduction java string
PPT
String classes and its methods.20
PDF
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
PPT
Java™ (OOP) - Chapter 9: "Strings and Text I/O"
Java Strings.pptxJava Strings.pptxJava Strings.pptx
Day_5.1.pptx
What is String in Java?
Java - Strings Concepts
Strings in javamnjn ijnjun oinoin oinoi .ppt
3.1 STRINGS (1) java jksdbkjdbsjsef.pptx
Java String class
Java Presentation on the topic of string
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
Text processing
Java R20 - UNIT-5.pdf
Java R20 - UNIT-5.docx
1st.pptx
String.pptx
Introduction java string
String classes and its methods.20
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java™ (OOP) - Chapter 9: "Strings and Text I/O"

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
master seminar digital applications in india
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Lesson notes of climatology university.
PDF
Trump Administration's workforce development strategy
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Computing-Curriculum for Schools in Ghana
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Supply Chain Operations Speaking Notes -ICLT Program
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
master seminar digital applications in india
UNIT III MENTAL HEALTH NURSING ASSESSMENT
What if we spent less time fighting change, and more time building what’s rig...
Final Presentation General Medicine 03-08-2024.pptx
Lesson notes of climatology university.
Trump Administration's workforce development strategy
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Structure & Organelles in detailed.
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Computing-Curriculum for Schools in Ghana
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Weekly quiz Compilation Jan -July 25.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Paper A Mock Exam 9_ Attempt review.pdf.
Chinmaya Tiranga quiz Grand Finale.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Supply Chain Operations Speaking Notes -ICLT Program

String in java

  • 1. IDEAL EYES BUSINESS COLLEGE A PRESENTATION STRING IN JAVA LANGUAGE 1 PERSENTED BY:- VIVEK KUMARPERSENTED TO:- PANKAJ SIR
  • 2. String  Generally string is a sequence of characters. But in java, string is an object.  String class is used to create string object.  string is a 16-bit Unicode character . There are two ways to create String object: 1. By string literal 2. By new keyword
  • 3. string literal For example:- String s1="Welcome"; String s2="Welcome"; //no new object will be created Note:- String objects are stored in a special memory area known as string constant pool inside the Heap memory. String literal is create by double quote. Each time you create a string literal, the JVM checks the string constant pool first. If the string already exists in the pool, a reference to the pooled instance returns. If the string does not exist in the pool, a new String object instantiates, then is placed in the pool
  • 4. In the above example only one object will be created . First time JVM will find no string object with the name "Welcome" in string constant pool , so it will create a new object . Second time it will find the string with the name "Welcome" in string constant pool , so it will not create new object whether will return the reference to the same instance.
  • 5. By string literal class String _literal { public static void main(String args[]) { String x ="java"; String x1="java"; System.out.println( "x="+x); } }
  • 6. By new keyword In such case, JVM will create a new String object in normal ( nonpool ) Heap memory and the literal "Welcome" will be placed in the string constant pool . The variable s will refer to the object in Heap( nonpool ). String s=new String("Welcome"); //creates two objects and one reference variale For example:-
  • 7. By new keyword 1. class new_keyword 2. { 3. public static void main(String args[]) 4. { 5. String x ="java"; 6. String s=new String("Welcome"); 7. System.out.println( "x="+s); 8. System.out.println( "x="+x); 9. } 10. }
  • 8. Methods of String class java.lang.String class provides a lot of methods to work on string. Let's see the commonly used methods of String class. 1. charAt() Returns the character located at the specified index 2. concat() Appends one String to the end of another ( "+" also works) 3. equalsIgnoreCase() Determines the equality of two Strings, ignoring case 4. length() Returns the number of characters in a String 5. replace() Replaces occurrences of a character with a new character 6. substring() Returns a part of a String 7. toLowerCase() Returns a String with uppercase characters converted 8. toString() Returns the value of a String 9. toUpperCase() Returns a String with lowercase characters converted 10.trim() Removes whitespace from the ends of a String IMPORTANT METHODS IN THE STRING CLASS
  • 9. charAt() method class charAt { public static void main(String args[]) { String s="Sachin"; System.out.println(s.charAt(5)); System.out.println(s.charAt(3)); } }
  • 10. toUpperCase() and toLowerCase() method class low_upper { public static void main(String args[]) { String s="Sachin"; System.out.println(s.toUpperCase()); System.out.println(s.toLowerCase()); System.out.println(s); } }