SlideShare ist ein Scribd-Unternehmen logo
1 von 23
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

Weitere ähnliche Inhalte

Was ist angesagt?

Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
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 GanesanKavita Ganesan
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in JavaNiloy Saha
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in JavaSpotle.ai
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 

Was ist angesagt? (20)

Method overloading
Method overloadingMethod overloading
Method overloading
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
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 interfaces
Java interfacesJava interfaces
Java interfaces
 
class and objects
class and objectsclass and objects
class and objects
 
Method overriding
Method overridingMethod overriding
Method overriding
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Applets
AppletsApplets
Applets
 
Java Strings
Java StringsJava Strings
Java Strings
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 

Andere mochten auch

String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)Ravi_Kant_Sahu
 
String java
String javaString java
String java774474
 
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 threadingRaja 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 StringsIt 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 operationsTurnToTech
 
Java: strings e arrays
Java: strings e arraysJava: strings e arrays
Java: strings e arraysArthur Emanuel
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in javaHitesh 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 DiscoveryBrightEdge
 
L21 io streams
L21 io streamsL21 io streams
L21 io streamsteach4uin
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keywordtanu_jaswal
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)teach4uin
 

Andere mochten auch (20)

Java String
Java String Java String
Java String
 
String Handling
String HandlingString Handling
String Handling
 
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
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
 
String operation
String operationString operation
String operation
 

Ähnlich wie Strings in Java

javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string classfedcoordinator
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesPrabu U
 
Module-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdfModule-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdflearnEnglish51
 
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
 
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 R20 - UNIT-5.docx
Java R20 - UNIT-5.docxJava R20 - UNIT-5.docx
Java R20 - UNIT-5.docxPamarthi Kumar
 
Strings in c
Strings in cStrings in c
Strings in cvampugani
 
3.7_StringBuilder.pdf
3.7_StringBuilder.pdf3.7_StringBuilder.pdf
3.7_StringBuilder.pdfAnanthi68
 

Ähnlich wie 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
 
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
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Strings in c
Strings in cStrings in c
Strings in c
 
3.7_StringBuilder.pdf
3.7_StringBuilder.pdf3.7_StringBuilder.pdf
3.7_StringBuilder.pdf
 
M C6java7
M C6java7M C6java7
M C6java7
 

Mehr von Abhilash Nair

Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsAbhilash Nair
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineAbhilash Nair
 
VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)Abhilash Nair
 
Introduction to VHDL - Part 1
Introduction to VHDL - Part 1Introduction to VHDL - Part 1
Introduction to VHDL - Part 1Abhilash Nair
 
Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential CircuitsAbhilash Nair
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State MachineAbhilash Nair
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and SynthesisAbhilash Nair
 
Synchronous design process
Synchronous design processSynchronous design process
Synchronous design processAbhilash 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 modelsAbhilash Nair
 
Analysis of state machines
Analysis of state machinesAnalysis of state machines
Analysis of state machinesAbhilash 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
 

Mehr von 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
 

Kürzlich hochgeladen

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 

Kürzlich hochgeladen (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

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