The document summarizes the String class and its methods in Java. It discusses that String is an immutable sequence of characters represented by the String class. It lists some key methods of the String class like length(), charAt(), equals() for comparing Strings. It also covers String constructors and how to initialize Strings.
The Java I/O package supports Java's basic input/output system for accessing external data from sources like files and networks. It defines streams as logical entities that produce or consume information, with byte streams for binary data and character streams for Unicode text. Streams are linked to physical devices and behave consistently across different types of devices. The package defines hierarchies of input and output stream classes, with abstract base classes like InputStream/OutputStream for bytes and Reader/Writer for characters.
The document provides information about strings in Java including:
1) Strings are objects in Java that are used to hold text data. The String class represents strings and provides various methods to work with strings.
2) There are two ways to create String objects: using string literals or the new keyword. String literals reuse existing objects in the string constant pool.
3) Important String class methods include charAt(), concat(), equalsIgnoreCase(), length(), replace(), substring(), toLowerCase(), toUpperCase(), and trim(). These methods allow manipulating and accessing string values.
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 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.
String is a non-primitive and immutable data type in Java that represents a sequence of characters. It is stored in the String Constant Pool in the heap memory. Methods like equals(), concat(), contains(), indexOf() etc. are used to perform operations on strings. String is immutable to prevent unexpected behavior if the contents of a string are changed.
- Java uses streams to perform input and output operations which allow for fast processing. Streams are sequences of data composed of bytes.
- The main stream classes in Java are InputStream for reading data and OutputStream for writing data. These classes handle byte-oriented input/output.
- FileInputStream and FileOutputStream classes allow reading and writing of data to files by extending InputStream and OutputStream respectively. They are used for file handling operations in Java.
This document discusses string handling in Java. It explains that strings are immutable objects of type String. It describes the four main string classes in Java - String, StringBuffer, StringBuilder, and StringTokenizer. The document outlines various string methods like length(), charAt(), compareTo(), indexOf(), and replace() among others. It also discusses how to create, modify, search and compare strings in Java.
The Java I/O package supports Java's basic input/output system for accessing external data from sources like files and networks. It defines streams as logical entities that produce or consume information, with byte streams for binary data and character streams for Unicode text. Streams are linked to physical devices and behave consistently across different types of devices. The package defines hierarchies of input and output stream classes, with abstract base classes like InputStream/OutputStream for bytes and Reader/Writer for characters.
The document provides information about strings in Java including:
1) Strings are objects in Java that are used to hold text data. The String class represents strings and provides various methods to work with strings.
2) There are two ways to create String objects: using string literals or the new keyword. String literals reuse existing objects in the string constant pool.
3) Important String class methods include charAt(), concat(), equalsIgnoreCase(), length(), replace(), substring(), toLowerCase(), toUpperCase(), and trim(). These methods allow manipulating and accessing string values.
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 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.
String is a non-primitive and immutable data type in Java that represents a sequence of characters. It is stored in the String Constant Pool in the heap memory. Methods like equals(), concat(), contains(), indexOf() etc. are used to perform operations on strings. String is immutable to prevent unexpected behavior if the contents of a string are changed.
- Java uses streams to perform input and output operations which allow for fast processing. Streams are sequences of data composed of bytes.
- The main stream classes in Java are InputStream for reading data and OutputStream for writing data. These classes handle byte-oriented input/output.
- FileInputStream and FileOutputStream classes allow reading and writing of data to files by extending InputStream and OutputStream respectively. They are used for file handling operations in Java.
This document discusses string handling in Java. It explains that strings are immutable objects of type String. It describes the four main string classes in Java - String, StringBuffer, StringBuilder, and StringTokenizer. The document outlines various string methods like length(), charAt(), compareTo(), indexOf(), and replace() among others. It also discusses how to create, modify, search and compare strings in Java.
This document discusses Java string classes and their differences. It provides an overview of strings in Java and describes the String, StringBuffer, and StringBuilder classes. The String class represents immutable strings and stores strings in a constant pool for efficiency. The StringBuffer and StringBuilder classes represent mutable strings but StringBuffer is synchronized for thread-safety while StringBuilder is not.
String objects are stored in the constant string pool and are immutable. StringBuffer and StringBuilder objects are stored in the heap and are mutable. StringBuffer is thread-safe while StringBuilder is non-thread-safe but faster than StringBuffer. The key differences are that String objects cannot be modified, while StringBuffer and StringBuilder can modify their character sequences via append and insert methods. String concatenation involves more steps than StringBuffer concatenation via the append method.
The document discusses String handling in Java. It describes how Strings are implemented as objects in Java rather than character arrays. It also summarizes various methods available in the String and StringBuffer classes for string concatenation, character extraction, comparison, modification, and value conversion. These methods allow extracting characters, comparing strings, modifying strings, and converting between string and other data types.
This document provides an overview of the Java Collections Framework. It discusses core collection interfaces like List, Set, and Map and their common implementations like ArrayList, HashSet, and HashMap. It also covers sorting collections with Comparable and Comparator, searching collections with binary search, and using utility methods in the Collections class. Examples are provided to illustrate usage of various collection classes and methods.
This document discusses Java I/O and streams. It begins by introducing files and the File class, which provides methods for obtaining file properties and manipulating files. It then discusses reading and writing files using byte streams like FileInputStream and FileOutputStream. Character streams like PrintWriter and BufferedReader are presented for console I/O. Other stream classes covered include buffered streams, object streams for serialization, and data streams for primitive types. The key methods of various stream classes are listed.
String objects are immutable in Java, so any operation that modifies a String value actually creates a new String object. The StringBuffer and StringBuilder classes provide mutable alternatives to String that have similar methods but do not create new objects with each modification. When a String literal value is used in code, it is stored in the String constant pool to promote reuse of these immutable objects.
The document discusses various Java I/O streams including input streams, output streams, byte streams, character streams, buffered streams, properties class, print stream, file locking, serialization and print writer class. It provides examples of reading and writing files using FileInputStream, FileOutputStream, FileReader, FileWriter and other stream classes. Methods of different stream classes are also explained along with their usage.
This document discusses the java.util.StringTokenizer class which allows breaking a string into tokens. It describes the constructors and methods of StringTokenizer, including how to count, check for, and retrieve the next token. An example program demonstrates its use by tokenizing a sample string and outputting the results.
This document discusses Java packages, including built-in and user-defined packages, advantages of packages, and how to access classes from other packages. Packages organize classes and interfaces, provide access protection, and avoid naming collisions. There are several ways to access classes from other packages, including importing the entire package, a specific class, or using the fully qualified class name. Subpackages further categorize packages. Class files can be loaded temporarily via the classpath or permanently by modifying environment variables or creating JAR files.
This document discusses exception handling in C++ and Java. It defines what exceptions are and explains that exception handling separates error handling code from normal code to make programs more readable and robust. It covers try/catch blocks, throwing and catching exceptions, and exception hierarchies. Finally, it provides an example of implementing exception handling in a C++ program to handle divide-by-zero errors.
String is an object that represents a sequence of characters. The three main String classes in Java are String, StringBuffer, and StringTokenizer. String is immutable, while StringBuffer allows contents to be modified. Common string methods include length(), charAt(), substring(), indexOf(), and equals(). The StringBuffer class is similar to String but more flexible as it allows adding, inserting and appending new contents.
The document summarizes a presentation on exception handling given by the group "Bug Free". It defines what exceptions are, why they occur, and the exception hierarchy. It describes checked and unchecked exceptions, and exception handling terms like try, catch, throw, and finally. It provides examples of using try-catch blocks, multiple catch statements, nested try-catch, and throwing and handling exceptions.
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.
This document provides an overview of string manipulation in C++. It discusses C-style strings and introduces C++ strings as objects of the string class. It describes various string constructors, functions for comparison, concatenation, insertion, extraction and other operations. Examples are given to demonstrate the use of functions like length(), capacity(), empty(), at(), find(), assign(), begin() and end(). The document is intended as a lecture on object-oriented string handling in C++.
The document discusses several core Java concepts including:
1) Comments in Java code can be single-line or multiline javadoc comments.
2) Classes are fundamental in Java and describe data objects and methods that can be applied to objects.
3) Variables and methods have scopes determined by curly braces and a variable is only available within its scope.
This document summarizes key concepts about packages, classes, and the static keyword in Java. It discusses how packages are used to organize classes and prevent naming conflicts. It also explains that the static keyword in Java is used for memory management and that static variables, methods, blocks, and nested classes belong to the class rather than object instances. The document provides examples of how to define packages and use the static keyword with variables, methods, and blocks in Java programs.
This document provides an overview of Java I/O including different types of I/O, how Java supports I/O through streams and classes like File, serialization, compression, Console, and Properties. It discusses byte and character streams, buffered streams, reading/writing files, and preferences. Key points are that Java I/O uses streams as an abstraction, byte streams operate on bytes while character streams use characters, and buffered streams improve efficiency by buffering reads/writes.
1) A constructor in Java is a special method that is used to initialize objects and is called when an object is created. It can set initial values for object attributes.
2) There are different types of constructors including default, parameterized, and copy constructors. The default constructor takes no parameters, parameterized constructors take parameters to initialize objects with different values, and copy constructors are used to create a copy of an object.
3) Constructor overloading allows a class to have multiple constructors with the same name but different parameters, allowing objects to be initialized in different ways.
Inheritance and polymorphism are key concepts in object-oriented programming that allow for code reuse. Inheritance allows a subclass to inherit attributes and behaviors from a superclass, while also adding its own attributes and behaviors. Polymorphism allows subclasses to override or modify inherited behaviors from the superclass. This allows subclasses to be treated as their superclass type while still maintaining their specific behaviors. The document discusses inheritance in Java including inheriting classes, the super reference, overriding and final methods/classes, abstract classes, and interfaces. It also covers polymorphism, access modifiers, and packages in Java.
This document discusses string handling, multithreaded programming, and Java database connectivity in Java. It covers:
- String classes like String, StringBuffer, StringBuilder and the CharSequence interface. It describes string construction and properties.
- Methods for extracting, comparing, modifying and searching strings. This includes charAt(), equals(), replace(), substring() etc.
- Multithreaded programming concepts like threads, states, priorities and communication.
- JDBC architecture and components. It discusses establishing database connections, result sets, batch processing and transactions.
The document provides examples to explain string handling methods and multithreaded programming concepts in Java. It aims to introduce the topics of string handling, mult
This document outlines the topics of string handling, multithreaded programming, and Java database connectivity in Java. For string handling, it discusses the String, StringBuffer, and StringBuilder classes and their properties like mutability. It also covers string constructors and methods for extracting, comparing, and modifying strings. For multithreaded programming, it lists the need for multiple threads and concepts like thread states, priorities, and inter-thread communication. For Java database connectivity, it mentions the JDBC architecture and tasks like establishing connections, processing result sets, and transactions.
This document discusses Java string classes and their differences. It provides an overview of strings in Java and describes the String, StringBuffer, and StringBuilder classes. The String class represents immutable strings and stores strings in a constant pool for efficiency. The StringBuffer and StringBuilder classes represent mutable strings but StringBuffer is synchronized for thread-safety while StringBuilder is not.
String objects are stored in the constant string pool and are immutable. StringBuffer and StringBuilder objects are stored in the heap and are mutable. StringBuffer is thread-safe while StringBuilder is non-thread-safe but faster than StringBuffer. The key differences are that String objects cannot be modified, while StringBuffer and StringBuilder can modify their character sequences via append and insert methods. String concatenation involves more steps than StringBuffer concatenation via the append method.
The document discusses String handling in Java. It describes how Strings are implemented as objects in Java rather than character arrays. It also summarizes various methods available in the String and StringBuffer classes for string concatenation, character extraction, comparison, modification, and value conversion. These methods allow extracting characters, comparing strings, modifying strings, and converting between string and other data types.
This document provides an overview of the Java Collections Framework. It discusses core collection interfaces like List, Set, and Map and their common implementations like ArrayList, HashSet, and HashMap. It also covers sorting collections with Comparable and Comparator, searching collections with binary search, and using utility methods in the Collections class. Examples are provided to illustrate usage of various collection classes and methods.
This document discusses Java I/O and streams. It begins by introducing files and the File class, which provides methods for obtaining file properties and manipulating files. It then discusses reading and writing files using byte streams like FileInputStream and FileOutputStream. Character streams like PrintWriter and BufferedReader are presented for console I/O. Other stream classes covered include buffered streams, object streams for serialization, and data streams for primitive types. The key methods of various stream classes are listed.
String objects are immutable in Java, so any operation that modifies a String value actually creates a new String object. The StringBuffer and StringBuilder classes provide mutable alternatives to String that have similar methods but do not create new objects with each modification. When a String literal value is used in code, it is stored in the String constant pool to promote reuse of these immutable objects.
The document discusses various Java I/O streams including input streams, output streams, byte streams, character streams, buffered streams, properties class, print stream, file locking, serialization and print writer class. It provides examples of reading and writing files using FileInputStream, FileOutputStream, FileReader, FileWriter and other stream classes. Methods of different stream classes are also explained along with their usage.
This document discusses the java.util.StringTokenizer class which allows breaking a string into tokens. It describes the constructors and methods of StringTokenizer, including how to count, check for, and retrieve the next token. An example program demonstrates its use by tokenizing a sample string and outputting the results.
This document discusses Java packages, including built-in and user-defined packages, advantages of packages, and how to access classes from other packages. Packages organize classes and interfaces, provide access protection, and avoid naming collisions. There are several ways to access classes from other packages, including importing the entire package, a specific class, or using the fully qualified class name. Subpackages further categorize packages. Class files can be loaded temporarily via the classpath or permanently by modifying environment variables or creating JAR files.
This document discusses exception handling in C++ and Java. It defines what exceptions are and explains that exception handling separates error handling code from normal code to make programs more readable and robust. It covers try/catch blocks, throwing and catching exceptions, and exception hierarchies. Finally, it provides an example of implementing exception handling in a C++ program to handle divide-by-zero errors.
String is an object that represents a sequence of characters. The three main String classes in Java are String, StringBuffer, and StringTokenizer. String is immutable, while StringBuffer allows contents to be modified. Common string methods include length(), charAt(), substring(), indexOf(), and equals(). The StringBuffer class is similar to String but more flexible as it allows adding, inserting and appending new contents.
The document summarizes a presentation on exception handling given by the group "Bug Free". It defines what exceptions are, why they occur, and the exception hierarchy. It describes checked and unchecked exceptions, and exception handling terms like try, catch, throw, and finally. It provides examples of using try-catch blocks, multiple catch statements, nested try-catch, and throwing and handling exceptions.
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.
This document provides an overview of string manipulation in C++. It discusses C-style strings and introduces C++ strings as objects of the string class. It describes various string constructors, functions for comparison, concatenation, insertion, extraction and other operations. Examples are given to demonstrate the use of functions like length(), capacity(), empty(), at(), find(), assign(), begin() and end(). The document is intended as a lecture on object-oriented string handling in C++.
The document discusses several core Java concepts including:
1) Comments in Java code can be single-line or multiline javadoc comments.
2) Classes are fundamental in Java and describe data objects and methods that can be applied to objects.
3) Variables and methods have scopes determined by curly braces and a variable is only available within its scope.
This document summarizes key concepts about packages, classes, and the static keyword in Java. It discusses how packages are used to organize classes and prevent naming conflicts. It also explains that the static keyword in Java is used for memory management and that static variables, methods, blocks, and nested classes belong to the class rather than object instances. The document provides examples of how to define packages and use the static keyword with variables, methods, and blocks in Java programs.
This document provides an overview of Java I/O including different types of I/O, how Java supports I/O through streams and classes like File, serialization, compression, Console, and Properties. It discusses byte and character streams, buffered streams, reading/writing files, and preferences. Key points are that Java I/O uses streams as an abstraction, byte streams operate on bytes while character streams use characters, and buffered streams improve efficiency by buffering reads/writes.
1) A constructor in Java is a special method that is used to initialize objects and is called when an object is created. It can set initial values for object attributes.
2) There are different types of constructors including default, parameterized, and copy constructors. The default constructor takes no parameters, parameterized constructors take parameters to initialize objects with different values, and copy constructors are used to create a copy of an object.
3) Constructor overloading allows a class to have multiple constructors with the same name but different parameters, allowing objects to be initialized in different ways.
Inheritance and polymorphism are key concepts in object-oriented programming that allow for code reuse. Inheritance allows a subclass to inherit attributes and behaviors from a superclass, while also adding its own attributes and behaviors. Polymorphism allows subclasses to override or modify inherited behaviors from the superclass. This allows subclasses to be treated as their superclass type while still maintaining their specific behaviors. The document discusses inheritance in Java including inheriting classes, the super reference, overriding and final methods/classes, abstract classes, and interfaces. It also covers polymorphism, access modifiers, and packages in Java.
This document discusses string handling, multithreaded programming, and Java database connectivity in Java. It covers:
- String classes like String, StringBuffer, StringBuilder and the CharSequence interface. It describes string construction and properties.
- Methods for extracting, comparing, modifying and searching strings. This includes charAt(), equals(), replace(), substring() etc.
- Multithreaded programming concepts like threads, states, priorities and communication.
- JDBC architecture and components. It discusses establishing database connections, result sets, batch processing and transactions.
The document provides examples to explain string handling methods and multithreaded programming concepts in Java. It aims to introduce the topics of string handling, mult
This document outlines the topics of string handling, multithreaded programming, and Java database connectivity in Java. For string handling, it discusses the String, StringBuffer, and StringBuilder classes and their properties like mutability. It also covers string constructors and methods for extracting, comparing, and modifying strings. For multithreaded programming, it lists the need for multiple threads and concepts like thread states, priorities, and inter-thread communication. For Java database connectivity, it mentions the JDBC architecture and tasks like establishing connections, processing result sets, and transactions.
Arrays are collections of similar type of elements stored in contiguous memory locations. Java arrays are fixed in size and indexed starting from 0. Arrays allow for random access of elements and code optimization. Common array types include single dimensional and multidimensional arrays. Single dimensional arrays store elements in a linear list while multidimensional arrays can be thought of as tables with rows and columns. Strings in Java are objects that are immutable, meaning their values cannot be modified after creation.
Here are solutions to the exercises:
1. Write a program that reverses a string:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = scanner.nextLine();
String reversed = "";
for (int i = input.length() - 1; i >= 0; i--) {
reversed += input.charAt(i);
}
System.out.println("Reversed string: " + reversed);
}
}
```
2. Write a program to
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 string handling in Java. Some key points:
- Strings are immutable sequences of characters represented by the String class. StringBuffer allows mutable strings.
- Constructors can initialize strings from arrays of characters or other strings. Methods like length(), charAt(), and compareTo() operate on strings.
- Strings can be concatenated, searched, extracted, modified, and converted between cases. StringBuffer supports mutable operations like insertion and deletion.
AMC Squarelearning Bangalore is the best training institute for a career development. it had students from various parts of the country and even few were from West African countries.
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 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.
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.
This document discusses several core Java concepts including comments, classes, objects, scopes, static methods and fields, arrays, and constructors. It provides examples of Java code for classes, methods, and constructors. Key points covered include: javadoc comments generate API documentation; classes describe data and operations on objects; scopes are determined by curly braces; static methods and fields belong to the class not instances; arrays are objects that can be dynamically allocated; and constructors create class instances and invoke superclass constructors.
This document provides an overview of strings in Java. It discusses that a string is a sequence of characters that can be treated as an object with various methods. Some key points include:
- Strings are immutable objects that provide methods for length, character access, concatenation, substring extraction, conversion, matching/replacing patterns, and finding substrings.
- The String class has over 40 methods for manipulating strings including comparing, converting, replacing, and splitting strings.
- Regular expressions can be used with methods like matches, replaceAll, replaceFirst and split to perform powerful pattern matching on strings.
The document discusses Strings in Java. Some key points:
- A String represents a sequence of characters. The String class is used to create string objects which can exist in the string pool or heap.
- Char arrays are preferable over Strings for passwords due to security reasons. Strings can be manipulated more easily.
- The String class has many useful methods like length(), charAt(), indexOf(), replace(), toLowerCase(), substring() etc to work with and manipulate string values.
- StringBuffer is used to create mutable string objects that can be modified after creation using methods like append(), insert(), delete() etc. It is preferable over String for performance reasons while manipulating strings.
This document discusses various string operations in Java, including string concatenation, copy, length, and comparison. It provides examples of how to use the + operator and concat() method to concatenate strings, the length() method to get the length of a string, and the equals(), ==, and compareTo() methods to compare strings. Various string operations like concatenation, copying, finding length, and comparing strings are important functions in many programming languages like Java.
Strings are immutable sequences of characters represented by the System.String class in .NET. The document discusses various methods for manipulating strings such as comparing, concatenating, searching, extracting substrings, splitting, replacing, deleting, changing case, and trimming. It recommends using a StringBuilder for efficient modification and building of strings. Formatting strings can be done using the ToString() and String.Format() methods along with formatting placeholders. Parsing numbers and dates from strings is culture-sensitive.
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.
This document discusses string handling in Java. It covers key topics like:
- Strings are immutable objects in Java
- The String, StringBuffer, and StringBuilder classes can be used to manipulate strings
- Common string methods like length(), concat(), indexOf(), and replace()
- Strings can be compared using equals(), startsWith(), and compareTo()
- Immutability avoids security issues when strings are passed as parameters
The document discusses the fundamentals of computer systems, including definitions, components, and how they work together. It defines a computer as an electronic device that accepts input, processes it, and provides output. The key components are the input and output units, memory unit, CPU (consisting of the ALU and control unit), and secondary storage. The input and output units send and receive data, the memory unit temporarily stores programs and data, the CPU performs arithmetic/logical operations and coordinates tasks, and secondary storage provides long-term storage. Together these components work to accept user input, process the data, and provide the results.
The document discusses fundamental data types in C including integer, floating point, character, and void types. It describes how variables must be declared before use and explains basic type modifiers like short, long, and unsigned. The summary also covers integer storage sizes and ranges, floating point precision and representation, and type conversions in C using casts and arithmetic promotion.
This document provides an introduction and overview of Hibernate, an object-relational mapping tool for Java. It discusses what ORM is, why it is used, and defines key Hibernate concepts like entities, mapping files, configuration files, and the session factory. It also provides an example of creating a basic Hibernate project with an Employee entity class, mapping file, configuration file, and test case to load an employee object by ID from the database.
The document discusses the benefits of exercise for mental health. Regular physical activity can help reduce anxiety and depression and improve mood and cognitive function. Exercise causes chemical changes in the brain that may help protect against mental illness and improve symptoms.
A JDBC type 2 driver converts JDBC API calls to database driver native API calls. It has a two-tier architecture and is faster than other drivers but is database dependent. A type 4 driver converts JDBC calls to database native network calls. It is platform independent, lightweight, and portable but requires implementing network protocols. A type 3 driver converts JDBC calls to database independent network calls and supports three-tier architectures and distributed transactions.
The document discusses the JDBC API and the basic steps for working with it to access a tabular datastore from a Java application. It covers:
1. The JDBC API provides an abstraction layer for Java programs to access database services via JDBC drivers.
2. The basic steps involve obtaining a database connection, executing SQL statements, and processing the results.
3. Obtaining a connection involves instantiating a Driver object, constructing a JDBC URL to identify the database, and passing this along with authentication properties to the Driver's connect method.
The document discusses obtaining a connection to a database in Java using JDBC. It provides code examples of creating a database connection using the DriverManager class and Oracle's JDBC Thin driver. The code inserts a record into an EMP table for demonstration purposes. Best practices for database connectivity in a Java project are then covered, such as using the DAO pattern to separate data access logic from business logic. This improves testability, reusability and flexibility in switching database types.
The document discusses improving the Data Access Object (DAO) design pattern implementation in a project using JDBC for database connectivity. It describes how the current DAO implementation creates a new Driver object on every request, which is inefficient. It recommends using the DriverManager class instead to manage a single Driver instance and create connections. The DriverManager acts as a factory class to centralize the connection creation code and avoid multiple Driver instances, improving performance.
This document describes an example of using URL rewriting and hidden form fields to maintain client state. The Home page links to a Login page containing a form for a username and password. Submitting the form calls the LoginServlet, which validates the credentials against a database using a UserDAO. If valid, the user is redirected to a personalized page welcoming them by name.
This document discusses three ways to set internal styles in HTML:
1) Universal styles that apply to all instances of a tag throughout the page. For example, making all <font> tags bold.
2) Styles using identifiers that allow restricting styles to specific elements. An ID is added and referenced in the style sheet.
3) User-defined styles that can customize styles.
The examples demonstrate applying a green color to all <a> links universally and then using IDs to style two <a> links differently. Internal styles only affect the current page.
The document discusses HTML elements and their structure. It explains that HTML elements contain a start tag, element content, and end tag. Elements can be nested within other elements. Common elements like <p>, <body>, and <html> are used to demonstrate how elements are structured and nested to form an HTML document. The document also covers empty elements, case sensitivity of tags, and the importance of including closing tags.
Attributes provide additional information about HTML elements. They are specified in name/value pairs within start tags. Attribute names and values are case-insensitive but it is recommended to use lowercase according to W3C standards. Common attributes include class, id, style, and title, and attribute values should always be enclosed in single or double quotes.
This document discusses HTML (Hypertext Markup Language), the most widely used language for creating web pages. It describes what HTML is, how it uses markup tags to provide structure and layout for web content. The document also explains how HTML pages are rendered and displayed in web browsers, and provides examples of common HTML tags and elements used to create basic HTML documents.
This document provides information on HTML headings, horizontal lines, and comments. It explains that headings are defined using tags from <h1> to <h6>, with <h1> being the most important and <h6> the least important. Horizontal lines are created using the <hr> tag to separate content. HTML comments are written using <!-- and --> and are ignored by browsers.
HTML forms allow users to enter and submit data to a server. The <form> element is used to create an HTML form, which can contain various input elements like text fields, checkboxes, radio buttons, and submit buttons. Common input element types include text, password, radio buttons, checkboxes, and submit buttons. Radio buttons allow a single selection from options, while checkboxes allow zero or more selections. The submit button submits the form data to the action page specified in the form tag.
1. The document provides an overview of CSS (Cascading Style Sheets) and how it can be used to style web pages by applying styles to HTML elements.
2. Styles can be applied inline, via embedded style blocks, or through external style sheets. External style sheets allow controlling styles across entire websites.
3. CSS properties like font, color, size, and other attributes can be set for elements using selectors like element names, classes, IDs to format text. Additional properties control layout aspects like margins, padding, borders.
VIEWs allow users to select subsets of data from one or more tables. A VIEW acts like a virtual table but contains no data itself - it just represents the result set of a SELECT statement. VIEWs provide a layer of security by restricting access to specific rows, columns, or tables. The CREATE VIEW statement is used to define a new VIEW, ALTER VIEW modifies an existing VIEW definition, and DROP VIEW removes a VIEW.
VIEWs allow users to select subsets of data from one or more tables. A VIEW acts like a virtual table but contains no data itself - it just represents the result set of a SELECT statement. VIEWs provide a layer of security by restricting access to specific rows, columns, or tables. The CREATE VIEW statement is used to define a new VIEW, ALTER VIEW modifies an existing VIEW definition, and DROP VIEW removes a VIEW.
VIEWs allow users to select subsets of data from one or more tables. A VIEW acts like a virtual table but contains no data itself - it just represents the result set of a SELECT statement. VIEWs provide a layer of security by restricting access to specific rows, columns, or tables. The CREATE VIEW statement is used to define a new VIEW, ALTER VIEW modifies an existing VIEW definition, and DROP VIEW removes a VIEW.
JDBC allows Java applications to connect to MySQL databases. The document provides instructions to install MySQL, download the MySQL JDBC driver from online, and select the platform-independent ZIP file version of the driver.
2. Objectives
On completion of this period, you would be able to know
• String class
• Methods of String class
http://improvejava.blogspot.in
3. Recap
In C / C++
• String is collection of characters
• It should be declared like a character array of some size
• Every string ends with a null ( ‘0’ ) character
• Memory is allocated sequentially because it is array
eg. :
char name[5];
strcpy(name,”ramu”);
[0] [1] [2] [3] [4]
name ‘r’ ‘a’ ‘m’ ‘u’ ‘0’
1000 1001 1002 1003 1004
http://improvejava.blogspot.in
3
4. String Class
• String is probably the most commonly used class in java’ class
• Strings are very important part of programming
• Every string you create is actually an object of type String
• Even string constants are actually String objects
• Java language provides a system defined class String in the
java.lang package
http://improvejava.blogspot.in
4
5. String Class contd..
• For example: in the statement
System.out.println(“ this is a string ”);
• The string “ this is a string ” is a String constant
• Java handles String constants in the same way that other computer
languages handle “normal” strings
http://improvejava.blogspot.in
5
6. String Class
• The objects of type Strings are immutable
• Once a String is created, its contents cannot be altered
• This may seem like a serious restriction but we have the following
advantages with this
• If you need to change a string, you can always create a new one
that contains the modifications
• Java defines a peer class of String, called StringBuffer, which
allows strings to be altered
http://improvejava.blogspot.in
6
7. String Class contd..
Strings can be constructed a variety of ways. The easiest is to use a
statement like this
String s = “ Good Morning ”;
“Good Morning”
s
s is the reference Fig 30.1
http://improvejava.blogspot.in
7
8. String Class contd..
• Once you have created a String object, you can use it anywhere
that a string is allowed
• For example, this statement displays cname
System.out.println(cname);
• Java defines ‘+’ operator for String objects
• It is used to concatenate two strings
http://improvejava.blogspot.in
8
9. String Class contd..
• For example, this statement
String cname = “ govt ” + “polytechnic” ;
results in cname containing “govt polytechnic“
• The following program demonstrates the preceding concepts
http://improvejava.blogspot.in
9
10. Example Program: String Class
// Demonstrating Strings
class StringDemo {
public static void main(String args[]) {
String str1 = “one”;
String str2 = “two”
String str3 = str1 + “ and ” + str2’;
System.out.println(“ str1 ”);
System.out.println(“ str2”);
System.out.println(“ str3”);
Output :
} // end of main method
one
two
} // end of class one and two
http://improvejava.blogspot.in
10
11. String Class contd..
• String class contains several methods that you can use
• test two strings for equality by using equals()
boolean equals(String object);
• obtain the length of a string by calling the length().
int length();
• Obtain the character at a specified index within a string by
calling charAt()
char charAT(int index);
http://improvejava.blogspot.in
11
12. Example program
class StringDemo2 {
public static void main(String args[]) { Output :
String str1 = “one”; length of str1 : 3
char at index 2: n
String str2 = “two”;
str1 != str2
String str3 = str1; str1 == str3
System.out.println(“ length of str1 : ”+str1.length());
System.out.println(“ char at index 2 in str1 : ”+str1.charAt(2));
if(str1.equals(str2)) {
System.out.println(“ str1 == str2”);
else
System.out.println(“ str1 != str2”);
if(str1.equals(str3)) {
System.out.println(“ str1 == str3”);
else
System.out.println(“ str1 != str3”);
}
}
http://improvejava.blogspot.in
12
13. The String Constructors
• To create an empty String, you call the default constructor.
For example
String s = new String():
• will create an instance of String with no characters in it
• String class has also parameterized constructors
• If you want to create strings that have initial values. The string
class provides a variety of constructors to handle this
http://improvejava.blogspot.in
13
14. The String Constructors contd..
• To create an empty String initialized by an array of characters,
use the constructor shown here
String(char chars[] )
eg.
char chars[] = {‘a’, ‘b’, ’c’ };
String s = new String(chars);
The constructor initializes s with the string “abc”
http://improvejava.blogspot.in
14
15. The String Constructors contd..
• You can specify a subrange of a character array as an initializer
using the following constructor
String(char chars[] , int startIndex, int numChars)
here, startIndex specifies the index at which the subrange begins,
and numChars specifies the number of characters to use
eg.
char chars[] = {‘a’, ‘b’, ’c’ ,’d’, ’e’, ’f’};
String s = new String(chars,2,3);
this initializes s with the characters cde
http://improvejava.blogspot.in
15
16. The String Constructors Contd..
• You can construct a String object that contains the same character
sequence as another String object using the following constructor
String(String strObj)
here, strObj is a String object
eg.
char chars[] = {‘a’, ‘b’, ’c’ ,’d’, ’e’, ’f’};
String s1 = new String(chars);
String s2 = new String(s1);
String objects s1 and s2 contains same String
http://improvejava.blogspot.in
16
17. The String Methods
• String length
• The length of a string is the number of characters that it
contains. To obtain this value, call the length() method
int length()
• The following fragment prints “3”, since there are three
characters in the string s;
char chars[] = {‘ a ’, ‘ b ’, ‘ c ’};
String s = new String(chars);
System.out.println(s.length());
or
System.out.println(“abc”.length());
http://improvejava.blogspot.in
17
18. The String methods Contd..
• toString() :
• Every class implements toString() because it is defined by
Object
• However, the default implementation of toString() is seldom
sufficient
• The general form of toString() method is
String toString()
class A { class B {
public String toString() { public static void main (String
return “hello”; args[]) {
} A a = new A();
} String s = “hai” + a;
System.out.println(s);
}
}
http://improvejava.blogspot.in
CM602.32 18
19. The String Methods contd..
• Character extraction
• The String class provides a number of ways in which
characters can be extracted from a String object.
• The string index begins at zero
char charAt() : to extract a single character from a String
char ch;
ch =“abc”.charAt(1)
assigns the value “b” to ch
http://improvejava.blogspot.in
19
20. The String Methods contd..
getChars()
If you need to extract more than one character at a time, you can
use the getchars() method, it has this general form
void getChars(int soureStart, int sourceEnd, char target[], int targetStart)
String s = “government polytechnic warangal”;
int start = 10;
int end = 14;
char buf[] = new char[end-start];
s.getShars(start, end,buf,0);
System.out.println(buf);
http://improvejava.blogspot.in
20
21. The String Methods contd..
getBytes()
• It is alternative to getChars() that stores the characters in an
array of bytes
byte[] getBytes()
toCharArray()
• It returns an array of characters for the entire string
char[] toCharArray()
http://improvejava.blogspot.in
21
22. String Comparison
• The String class includes several methods that compare
strings or substrings within strings
equals( )
• two compare two strings for equality, use equals()
boolean equals(Object str)
• Here, str is the string object being compared with the invoking
String object
http://improvejava.blogspot.in
22
23. String Comparison contd..
equalsIgnoreCase( )
• To perform a comparison that ignores case differences
boolean equalsIgnoreCase(String str)
• when it compares two strings, it considers A – Z to be the same
as a – z
• here, str is the String object being compared with the invoking
String object
http://improvejava.blogspot.in
23
25. String Comparison contd..
regionMatches( )
• Compares a specific region inside a string with another specific
region in another string
• There is an overloaded form that allows you to ignore case in
such comparison
boolean regionMatches(int startIndex, String str2, int str2StartIndex, int
numChars)
boolean regionMatches(boolean ignoreCase, int startIndex, String str2,
int str2StartIndex, int numChars)
http://improvejava.blogspot.in
25
26. String Comparison contd..
startsWith( )
• Determines whether a given String begins with a specified
string
boolean startsWith(String str)
eg: “Foobar”.startsWith(“Foo”)
endsWith( )
• Determines whether a given String ends with a specified string
boolean endsWith(String str)
eg: “Foobar”.startsWith(“Foo”)
http://improvejava.blogspot.in
26
27. String Comparison contd..
equals ( ) versus ==
• equals() methods compares the characters inside a String
object
= = operator compares two object references to see whether
they refer to the same instance
class A {
public static void main(String args[]) {
String s1 = “Hello”;
String s2 = new String(s1);
System.out.println(s1.equals(s2));
System.out.println(s1==s2);
}
} http://improvejava.blogspot.in
27
28. String Comparison contd..
compareTo( )
• Used to know two strings are identical, less than, or greater than
the next
• A string is less than another if it comes before the other in
dictionary order
• A string is greater than another if it comes after the other in
dictionary order
int compareTo(String str)
• Here, str is the string being compared with the invoking String
http://improvejava.blogspot.in
28
29. Searching Strings
• The String class provides two methods that allow you to search
a string for a specified character or substring
indexOf() - searches for the first occurrence of a character or
substring.
lastIndexOf() - searches for the last occurrence of a character or
substring
• These two methods are overloaded in several different ways. In
all cases , the methods return the index at which the charcter or
substring was found or -1 returned on failure
http://improvejava.blogspot.in
29
30. Searching Strings contd..
• To search for the first occurrence of a character, use
int indexOf(int ch)
• To search for the last occurrence of a character, use
int lastIndexOf(int ch)
• Here, ch is the character being sought
http://improvejava.blogspot.in
30
31. Searching Strings contd..
• To search for the first or last occurrence of a substring, use
int indexOf(String str)
int lastIndexOf(String str)
• Here, str specifies the substring
• You can specify a starting point for the search using these forms
int indexOf(int ch, int startIndex)
int lastIndexOf(int ch, int startIndex)
int indexOf(String str, int startIndex)
int lastIndexOf(String str, int startIndex)
http://improvejava.blogspot.in
31
32. Modifying a String
replace() - replaces all occurrences of one character in the
invoking string
String replace(char original, char replacement)
String subString(int startIndex, int endIndex)
trim() - returns a copy of the invoking string from which any
leading and trailing white space has been removed
String trim()
http://improvejava.blogspot.in
32
33. Changing the case of characters within a String
toLowerCase() - converts all the characters in a string from
uppercase to lowercase
String toLowerCase()
toUpperCase() - converts all the characters in a string from
lowercase to uppercase
String toUpperCase()
http://improvejava.blogspot.in
33
34. Summary
• We discussed
• String classes
• Uses of string class
• Syntax of string class
• Constructors of String class
• Methods of String class
http://improvejava.blogspot.in
34
35. Assignment
1. Write a class that has String types and also that uses
various String methods to perform operations on the
above data
http://improvejava.blogspot.in
36. Quiz
1. String are
a. mutable
b. immutable
c. none
http://improvejava.blogspot.in
36
37. Quiz contd..
2. String is
a. variable
b. class
c. data type
d. none
http://improvejava.blogspot.in
38. Frequently Asked Questions
1. Explain the use String class
2. Differentiate String and StringBuffer classes
3. Explain various methods in String class with example
programs
http://improvejava.blogspot.in
38