SlideShare a Scribd company logo
TEST (MODULE:- 1 and 2)
 What are command line arguments? Write a program in JAVA to print

  Fibonacci series using command line arguments?      [10]

 Create a class employee with data members empid, empname, designation

  and salary. Write methods for:-                     [10]

  get_employee()- To take user input.

  show_grade()- To display grade of employee based on salary.

  show_employee()- To show employee details.

 Write a note on:-                                   [10]
   Java Virtual Machine.

   Nesting of Methods with example
STRINGS
   IN
 JAVA
          - Ankita Karia
STRINGS
 Strings represent a sequence of characters.
 The easiest way to represent a sequence of characters in
  JAVA is by using a character array.
 char Array[ ] = new char [5];             Character arrays are
                                              not good enough to
                                             support the range of
                                             operations we want to
                                              perform on strings.


    In JAVA strings are class objects and implemented using
    two classes:-
        String
        StringBuffer.
    In JAVA strings are not a character array and is not NULL
    terminated.
DECLARING & INITIALISING

•   Normally, objects in Java are created with the new keyword.

    String name;
     name = new String("Craig");

                                OR
     String name= new String("Craig");


•   However, String objects can be created "implicitly":
                 String name;
                 name = "Craig";
The String Class


String objects are handled specially by the compiler.
 String is the only class which has "implicit" instantiation.
The String class is defined in the java.lang package.
Strings are immutable.
 The value of a String object can never be changed.
 For mutable Strings, use the StringBuffer class.
DYNAMIC INITIALIZATION
           OF STRINGS
BufferedReader br = new BufferedReader(new
 InputStreamReader(System.in));

    String city = br.readLine();    Give throws
                                    IOException
                                       beside
                                      function
                                        name

Scanner sc=new Scanner(System.in);
    String state=sc.nextLine();
   String state1=sc.next();
STRING CONCATENATION
    JAVA string can be concatenated
     using + operator.
 String name="Ankita";
 String surname="Karia";
 System.out.println(name+" "+surname);

STRING Arrays
•An array of strings can also be created
        String cities [ ] = new String[5];
• Will create an array of CITIES of size 5 to
hold string constants
String Methods
   The String class contains many useful methods for string-
    processing applications.
    ◦ A String method is called by writing a String object, a dot, the name of
      the method, and a pair of parentheses to enclose any arguments

    ◦ If a String method returns a value, then it can be placed anywhere that a
      value of its type can be used

      String greeting = "Hello";         String method
      int count = greeting.length();
      System.out.println("Length is " + greeting.length());

    ◦ Always count from zero when referring to the position or index of a
      character in a string
String Indexes
Some Methods in the Class String (Part 1
of 8)




                        1-10
Some Methods in the Class String (Part 2
of 8)
Some Methods in the Class String (Part 3
of 8)
Some Methods in the Class String (Part 4 o
8)
Some Methods in the Class String (Part 5 o
8)
Some Methods in the Class String (Part 6
of 8)
Some Methods in the Class String (Part 7 o
STRING BUFFER

               CLASS
    STRINGBUFFER class creates strings flexible length that
    can be modified in terms of both length and content.

   STRINGBUFFER may have characters and substrings
    inserted in the middle or appended to the end.

   STRINGBUFFER automatically grows to make room for
    such additions

                      Actually STRINGBUFFER has more
                     characters pre allocated than are actually
                        needed, to allow room for growth
STRING BUFFER
              CONSTRUCTORS
   String Buffer():- Reserves room fro 16 characters
    without reallocation


   StringBuffer(int size):- Accepts an integer argunent
    that explicilty sets the size of the buffer


   StringBuffer(String str):- Accepts STRING argument
    that sets the initial contents of the STRINGBUFFER and
    allocated room for 16 additional characters.
STRING BUFFER FUNCTIONS
   length():-Returns the current length of the string.

   capacity():- Returns the total allocated capacity.

   void ensureCapacity():- Preallocates room for a certain

                    number of characters.
   void setLength(int len):- Sets the length of the string s1
                              to len.
               If len<s1.length(), s1 is truncated.
               If len>s1.length(), zeros are added to s1.
   charAt(int where):- Extracts value of a single character.

   setCharAt(int where, char ch):- Sets the value of character

                     at specified position.
STRING BUFFER FUNCTIONS
   append(s2):- Appends string s2 to s1 at the end.

   insert(n,s2 ):- Inserts the string s2 at the position n of the
    string s1

   reverse():- Returns the reversed object on when it is called.

   delete(int n1,int n2):- Deletes a sequence of characters
    from the invoking object.

                 n1      Specifies index of first character to remove

                          Specifies index one past the lastcharacter to
                  n2      remove

   deleteCharAt(int loc):- Deletes the character at the index
    specified by loc.
STRING BUFFER FUNCTIONS
   replace(int n1,int n2,String s1):- Replaces one set of
    characters with another set.

   substring(int startIndex):- Returns the substring that starts
    at starts at startIndex and runs to the end.

   substring(int startIndex, int endIndex):- Returns the
    substring that starts at starts at startIndex and runs to the
    endIndex-1




VECTOR

More Related Content

What's hot

Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
Spotle.ai
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
Shraddha
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
Arzath Areeff
 
String in java
String in javaString in java
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 
Applets
AppletsApplets
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Lovely Professional University
 
Files in java
Files in javaFiles in java
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
RahulAnanda1
 
Threads in JAVA
Threads in JAVAThreads in JAVA

What's hot (20)

Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
OOP java
OOP javaOOP java
OOP java
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Java threads
Java threadsJava threads
Java threads
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
String in java
String in javaString in java
String in java
 
Applets in java
Applets in javaApplets in java
Applets in java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
Applets
AppletsApplets
Applets
 
Java input
Java inputJava input
Java input
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Files in java
Files in javaFiles in java
Files in java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 

Viewers also liked

Java String
Java String Java String
Java String
SATYAM SHRIVASTAV
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita Ganesan
Kavita Ganesan
 
Java strings
Java   stringsJava   strings
Java strings
Mohammed Sikander
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)Ravi_Kant_Sahu
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
Intelligo Technologies
 
String java
String javaString java
String java
774474
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++Fahim Adil
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
Raja Sekhar
 
Chapter 3:Programming with Java Operators and Strings
Chapter 3:Programming with Java Operators and  StringsChapter 3:Programming with Java Operators and  Strings
Chapter 3:Programming with Java Operators and Strings
It Academy
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20myrajendra
 
Strings and common operations
Strings and common operationsStrings and common operations
Strings and common operations
TurnToTech
 
Java: strings e arrays
Java: strings e arraysJava: strings e arrays
Java: strings e arrays
Arthur Emanuel
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Hitesh Kumar
 
Save Time, Money and Bloodshed with Soft System Discovery
Save Time, Money and Bloodshed with Soft System DiscoverySave Time, Money and Bloodshed with Soft System Discovery
Save Time, Money and Bloodshed with Soft System Discovery
BrightEdge
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
teach4uin
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
tanu_jaswal
 

Viewers also liked (20)

Java String
Java String Java String
Java String
 
Java Strings
Java StringsJava Strings
Java Strings
 
String Handling
String HandlingString Handling
String Handling
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita Ganesan
 
Java strings
Java   stringsJava   strings
Java strings
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
 
Strings
StringsStrings
Strings
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
String java
String javaString java
String java
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Chapter 3:Programming with Java Operators and Strings
Chapter 3:Programming with Java Operators and  StringsChapter 3:Programming with Java Operators and  Strings
Chapter 3:Programming with Java Operators and Strings
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
 
Strings and common operations
Strings and common operationsStrings and common operations
Strings and common operations
 
Java: strings e arrays
Java: strings e arraysJava: strings e arrays
Java: strings e arrays
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Save Time, Money and Bloodshed with Soft System Discovery
Save Time, Money and Bloodshed with Soft System DiscoverySave Time, Money and Bloodshed with Soft System Discovery
Save Time, Money and Bloodshed with Soft System Discovery
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 

Similar to Strings in Java

javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
fedcoordinator
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and Interfaces
Prabu U
 
Module-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdfModule-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdf
learnEnglish51
 
Day_5.1.pptx
Day_5.1.pptxDay_5.1.pptx
Day_5.1.pptx
ishasharma835109
 
StringBuffer.pptx
StringBuffer.pptxStringBuffer.pptx
StringBuffer.pptx
meenakshi pareek
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
Infoviaan Technologies
 
package
packagepackage
package
sweetysweety8
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)
teach4uin
 
String handling
String handlingString handling
String handling
ssuser20c32b
 
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
hossamghareb681
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arraysphanleson
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
Indu32
 
Java
JavaJava
Chapter 7 String
Chapter 7 StringChapter 7 String
Chapter 7 String
OUM SAOKOSAL
 
Java R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdfJava R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdf
Pamarthi Kumar
 
Java R20 - UNIT-5.docx
Java R20 - UNIT-5.docxJava R20 - UNIT-5.docx
Java R20 - UNIT-5.docx
Pamarthi Kumar
 
Charcater and Strings.ppt Charcater and Strings.ppt
Charcater and Strings.ppt Charcater and Strings.pptCharcater and Strings.ppt Charcater and Strings.ppt
Charcater and Strings.ppt Charcater and Strings.ppt
mulualem37
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 

Similar to Strings in Java (20)

javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and Interfaces
 
07slide
07slide07slide
07slide
 
Module-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdfModule-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdf
 
Day_5.1.pptx
Day_5.1.pptxDay_5.1.pptx
Day_5.1.pptx
 
StringBuffer.pptx
StringBuffer.pptxStringBuffer.pptx
StringBuffer.pptx
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
package
packagepackage
package
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)
 
String handling
String handlingString handling
String handling
 
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
 
Java
JavaJava
Java
 
Chapter 7 String
Chapter 7 StringChapter 7 String
Chapter 7 String
 
Java R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdfJava R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdf
 
Java R20 - UNIT-5.docx
Java R20 - UNIT-5.docxJava R20 - UNIT-5.docx
Java R20 - UNIT-5.docx
 
Charcater and Strings.ppt Charcater and Strings.ppt
Charcater and Strings.ppt Charcater and Strings.pptCharcater and Strings.ppt Charcater and Strings.ppt
Charcater and Strings.ppt Charcater and Strings.ppt
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Strings in c
Strings in cStrings in c
Strings in c
 

More from Abhilash Nair

Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip Flops
Abhilash Nair
 
VHDL Part 4
VHDL Part 4VHDL Part 4
VHDL Part 4
Abhilash Nair
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
Abhilash Nair
 
MSI Shift Registers
MSI Shift RegistersMSI Shift Registers
MSI Shift Registers
Abhilash Nair
 
VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)
Abhilash Nair
 
VHDL - Part 2
VHDL - Part 2VHDL - Part 2
VHDL - Part 2
Abhilash Nair
 
Introduction to VHDL - Part 1
Introduction to VHDL - Part 1Introduction to VHDL - Part 1
Introduction to VHDL - Part 1
Abhilash Nair
 
Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential Circuits
Abhilash Nair
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State Machine
Abhilash Nair
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
Abhilash Nair
 
Synchronous design process
Synchronous design processSynchronous design process
Synchronous design process
Abhilash Nair
 
Analysis of state machines & Conversion of models
Analysis of state machines & Conversion of modelsAnalysis of state machines & Conversion of models
Analysis of state machines & Conversion of models
Abhilash Nair
 
Analysis of state machines
Analysis of state machinesAnalysis of state machines
Analysis of state machines
Abhilash Nair
 
Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)
Abhilash Nair
 
Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)
Abhilash Nair
 
FPGA
FPGAFPGA
FPLDs
FPLDsFPLDs
CPLDs
CPLDsCPLDs
CPLD & FPLD
CPLD & FPLDCPLD & FPLD
CPLD & FPLD
Abhilash Nair
 
CPLDs
CPLDsCPLDs

More from Abhilash Nair (20)

Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip Flops
 
VHDL Part 4
VHDL Part 4VHDL Part 4
VHDL Part 4
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
 
MSI Shift Registers
MSI Shift RegistersMSI Shift Registers
MSI Shift Registers
 
VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)
 
VHDL - Part 2
VHDL - Part 2VHDL - Part 2
VHDL - Part 2
 
Introduction to VHDL - Part 1
Introduction to VHDL - Part 1Introduction to VHDL - Part 1
Introduction to VHDL - Part 1
 
Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential Circuits
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State Machine
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
 
Synchronous design process
Synchronous design processSynchronous design process
Synchronous design process
 
Analysis of state machines & Conversion of models
Analysis of state machines & Conversion of modelsAnalysis of state machines & Conversion of models
Analysis of state machines & Conversion of models
 
Analysis of state machines
Analysis of state machinesAnalysis of state machines
Analysis of state machines
 
Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)
 
Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)
 
FPGA
FPGAFPGA
FPGA
 
FPLDs
FPLDsFPLDs
FPLDs
 
CPLDs
CPLDsCPLDs
CPLDs
 
CPLD & FPLD
CPLD & FPLDCPLD & FPLD
CPLD & FPLD
 
CPLDs
CPLDsCPLDs
CPLDs
 

Recently uploaded

How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 

Recently uploaded (20)

How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 

Strings in Java

  • 1. TEST (MODULE:- 1 and 2)  What are command line arguments? Write a program in JAVA to print Fibonacci series using command line arguments? [10]  Create a class employee with data members empid, empname, designation and salary. Write methods for:- [10] get_employee()- To take user input. show_grade()- To display grade of employee based on salary. show_employee()- To show employee details.  Write a note on:- [10]  Java Virtual Machine.  Nesting of Methods with example
  • 2. STRINGS IN JAVA - Ankita Karia
  • 3. STRINGS  Strings represent a sequence of characters.  The easiest way to represent a sequence of characters in JAVA is by using a character array. char Array[ ] = new char [5]; Character arrays are not good enough to support the range of operations we want to perform on strings. In JAVA strings are class objects and implemented using two classes:- String StringBuffer. In JAVA strings are not a character array and is not NULL terminated.
  • 4. DECLARING & INITIALISING • Normally, objects in Java are created with the new keyword. String name; name = new String("Craig"); OR String name= new String("Craig"); • However, String objects can be created "implicitly": String name; name = "Craig";
  • 5. The String Class String objects are handled specially by the compiler. String is the only class which has "implicit" instantiation. The String class is defined in the java.lang package. Strings are immutable.  The value of a String object can never be changed. For mutable Strings, use the StringBuffer class.
  • 6. DYNAMIC INITIALIZATION OF STRINGS BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String city = br.readLine(); Give throws IOException beside function name Scanner sc=new Scanner(System.in); String state=sc.nextLine(); String state1=sc.next();
  • 7. STRING CONCATENATION  JAVA string can be concatenated using + operator. String name="Ankita"; String surname="Karia"; System.out.println(name+" "+surname); STRING Arrays •An array of strings can also be created String cities [ ] = new String[5]; • Will create an array of CITIES of size 5 to hold string constants
  • 8. String Methods  The String class contains many useful methods for string- processing applications. ◦ A String method is called by writing a String object, a dot, the name of the method, and a pair of parentheses to enclose any arguments ◦ If a String method returns a value, then it can be placed anywhere that a value of its type can be used String greeting = "Hello"; String method int count = greeting.length(); System.out.println("Length is " + greeting.length()); ◦ Always count from zero when referring to the position or index of a character in a string
  • 10. Some Methods in the Class String (Part 1 of 8) 1-10
  • 11. Some Methods in the Class String (Part 2 of 8)
  • 12. Some Methods in the Class String (Part 3 of 8)
  • 13. Some Methods in the Class String (Part 4 o 8)
  • 14. Some Methods in the Class String (Part 5 o 8)
  • 15. Some Methods in the Class String (Part 6 of 8)
  • 16. Some Methods in the Class String (Part 7 o
  • 17.
  • 18. STRING BUFFER  CLASS STRINGBUFFER class creates strings flexible length that can be modified in terms of both length and content.  STRINGBUFFER may have characters and substrings inserted in the middle or appended to the end.  STRINGBUFFER automatically grows to make room for such additions Actually STRINGBUFFER has more characters pre allocated than are actually needed, to allow room for growth
  • 19. STRING BUFFER CONSTRUCTORS  String Buffer():- Reserves room fro 16 characters without reallocation  StringBuffer(int size):- Accepts an integer argunent that explicilty sets the size of the buffer  StringBuffer(String str):- Accepts STRING argument that sets the initial contents of the STRINGBUFFER and allocated room for 16 additional characters.
  • 20. STRING BUFFER FUNCTIONS  length():-Returns the current length of the string.  capacity():- Returns the total allocated capacity.  void ensureCapacity():- Preallocates room for a certain number of characters.  void setLength(int len):- Sets the length of the string s1 to len. If len<s1.length(), s1 is truncated. If len>s1.length(), zeros are added to s1.  charAt(int where):- Extracts value of a single character.  setCharAt(int where, char ch):- Sets the value of character at specified position.
  • 21.
  • 22. STRING BUFFER FUNCTIONS  append(s2):- Appends string s2 to s1 at the end.  insert(n,s2 ):- Inserts the string s2 at the position n of the string s1  reverse():- Returns the reversed object on when it is called.  delete(int n1,int n2):- Deletes a sequence of characters from the invoking object. n1 Specifies index of first character to remove Specifies index one past the lastcharacter to n2 remove  deleteCharAt(int loc):- Deletes the character at the index specified by loc.
  • 23. STRING BUFFER FUNCTIONS  replace(int n1,int n2,String s1):- Replaces one set of characters with another set.  substring(int startIndex):- Returns the substring that starts at starts at startIndex and runs to the end.  substring(int startIndex, int endIndex):- Returns the substring that starts at starts at startIndex and runs to the endIndex-1 VECTOR