javaexcnotes
javaexcnotes
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic
Simple
Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to Sun,
Java language is a simple programming language because:
o Java syntax is based on C++ (so easier for programmers to learn it after C++).
o Java has removed many complicated and rarely-used features, for example, explicit pointers,
operator overloading, etc.
o There is no need to remove unreferenced objects because there is an Automatic Garbage
Collection in Java.
Object-oriented
Java is an object-oriented programming language. Everything in Java is an object. Object-oriented
we organize our software as a combination of different types of objects that incorporates both data and
behavior.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
1. Object
2. Class
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
Platform Independent
Java is platform independent because it is different from other languages like C, C++, etc. which
are compiled into platform specific machines while Java is a write once, run anywhere language.
A platform is the hardware or software environment in which a program runs.
There are two types of platforms software-based and hardware-based. Java provides a software-based
platform.
The Java platform differs from most other platforms in the sense that it is a software-based platform
that runs on the top of other hardware-based platforms. It has two components:
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
1. Runtime Environment
2. API(Application Programming Interface)
Java code can be run on multiple platforms, for example, Windows, Linux, Sun Solaris, Mac/OS,
etc. Java code is compiled by the compiler and converted into bytecode. This bytecode is a platform-
independent code because it can be run on multiple platforms, i.e., Write Once and Run Anywhere(WORA).
Secured
Java is best known for its security. With Java, we can develop virus-free systems. Java is secured because:
o No explicit pointer
o Java Programs run inside a virtual machine sandbox
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Java language provides these securities by default. Some security can also be provided by an
application developer explicitly through SSL, JAAS, Cryptography, etc.
Robust
Robust simply means strong. Java is robust because:
Architecture-neutral
Java is architecture neutral because there are no implementation dependent features, for example,
the size of primitive types is fixed.
In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory
for 64-bit architecture. However, it occupies 4 bytes of memory for both 32 and 64-bit architectures in Java.
Portable
Java is portable because it facilitates you to carry the Java bytecode to any platform. It doesn't require
any implementation.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
High-performance
Java is faster than other traditional interpreted programming languages because Java bytecode is
"close" to native code. It is still a little bit slower than a compiled language (e.g., C++). Java is an
interpreted language that is why it is slower than compiled languages, e.g., C, C++, etc.
Distributed
Java is distributed because it facilitates users to create distributed applications in Java. RMI and EJB are
used for creating distributed applications. This feature of Java makes us able to access files by calling the
methods from any machine on the internet.
Multi-threaded
A thread is like a separate program, executing concurrently. We can write Java programs that deal with
many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn't
occupy memory for each thread. It shares a common memory area. Threads are important for multi-media,
Web applications, etc.
Dynamic
Java is a dynamic language. It supports dynamic loading of classes. It means classes are loaded on demand.
It also supports functions from its native languages, i.e., C and C++.
Java supports dynamic compilation and automatic memory management (garbage collection).
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a software development
environment which is used to develop java applications and applets. It physically exists. It contains JRE
+ development tools.
JDK is an implementation of any one of the below given Java Platforms released by Oracle corporation:
The JDK contains a private Java Virtual Machine (JVM) and a few other resources such as an interpreter/
loader (Java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc) etc. to complete
the development of a Java Application.
Components of JDK
Following is a list of primary components of JDK:
appletviewer: This tool is used to run and debug Java applets without a web browser.
idlj: An IDL-to-Java compiler. This utility generates Java bindings from a given Java IDL file.
jabswitch: It is a Java Access Bridge. Exposes assistive technologies on Microsoft Windows systems.
java: The loader for Java applications. This tool is an interpreter and can interpret the class
files generated by the javac compiler. Now a single launcher is used for both
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
development and deployment. The old deployment launcher, jre, no longer comes with
Sun JDK, and instead it has been replaced by this new java loader.
javac: It specifies the Java compiler, which converts source code into Java bytecode.
jar: The specifies the archiver, which packages related class libraries into a single JAR file.
This tool also helps manage JAR files.
javah: the C header and stub generator, used to write native methods.
jinfo: This utility gets configuration information from a running Java process or crash dump.
jmap: Oracle jmap - Memory Map- This utility outputs the memory map for Java and can print
shared object memory maps or heap memory details of a given process or core dump.
jps: Java Virtual Machine Process Status Tool lists the instrumented HotSpot Java Virtual
Machines (JVMs) on the target system.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
jstack: It is a utility that prints Java stack traces of Java threads (experimental).
Policytool: It specifies the policy creation and management tool, which can determine policy for a
Java runtime, specifying which permissions are available for code from various sources.
VisualVM: It is a visual tool integrating several command-line JDK tools and lightweight [clarification
needed] performance and memory profiling capabilities
xjc: It is the part of the Java API for XML Binding (JAXB) API. It accepts an XML schema and
generates Java classes.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
C++ vs Java
Mainly used C++ is mainly used for system Java is mainly used for application programming.
for programming. It is widely used in window, web-based,
enterprise and mobile applications.
Design Goal C++ was designed for systems and Java was designed and created as an interpreter
applications programming. It was an for printing systems but later extended as a
extension of C programming support network computing. It was designed
language. with a goal of being easy to use and accessible to
a broader audience.
Goto C++ supports the goto statement. Java doesn't support the goto statement.
Multiple C++ supports multiple inheritance. Java doesn't support multiple inheritance
inheritance through class. It can be achieved by interfaces in
java.
Operator C++ supports operator overloading. Java doesn't support operator overloading.
Overloading
Pointers C++ supports pointers. You can Java supports pointer internally. However, you
write pointer program in C++. can't write the pointer program in java. It means
java has restricted pointer support in java.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Compiler and C++ uses compiler only. C++ is Java uses compiler and interpreter both. Java
Interpreter compiled and run using the source code is converted into bytecode at
compiler which converts source compilation time. The interpreter executes this
code into machine code so, C++ is bytecode at runtime and produces output. Java
platform dependent. is interpreted that is why it is platform
independent.
Call by Value C++ supports both call by value and Java supports call by value only. There is no call
and Call by call by reference. by reference in java.
reference
Structure and C++ supports structures and unions. Java doesn't support structures and unions.
Union
Thread Support C++ doesn't have built-in support Java has built-in thread support.
for threads. It relies on third-party
libraries for thread support.
Documentation C++ doesn't support documentation Java supports documentation comment (/** ...
comment comment. */) to create documentation for java source
code.
Virtual C++ supports virtual keyword so Java has no virtual keyword. We can override all
Keyword that we can decide whether or not non-static methods by default. In other words,
override a function. non-static methods are virtual by default.
unsigned right C++ doesn't support >>> operator. Java supports unsigned right shift >>> operator
shift >>> that fills zero at the top for the negative
numbers. For positive numbers, it works same
like >> operator.
Inheritance C++ creates a new inheritance tree Java uses a single inheritance tree always
Tree always. because all classes are the child of Object class in
java. The object class is the root of
the inheritance tree in java.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
o Object
o Class
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Object
Any entity that has state and behavior is known as an object. For example, a chair, pen, table,
keyboard, bike, etc. It can be physical or logical.
An Object can be defined as an instance of a class. An object contains an address and takes up
some space in memory. Objects can communicate without knowing the details of each other's data or code.
The only necessary thing is the type of message accepted and the type of response returned by the objects.
Example: A dog is an object because it has states like color, name, breed, etc. as well as behaviors like
wagging the tail, barking, eating, etc.
Class
Collection of objects is called class. It is a logical entity.
A class can also be defined as a blueprint from which you can create an individual object.
Inheritance
When one object acquires all the properties and behaviors of a parent object, it is known as inheritance.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Polymorphism
If one task is performed in different ways, it is known as polymorphism. For example: to convince the
customer differently, to draw something, for example, shape, triangle, rectangle, etc.
Another example can be to speak something; for example, a cat speaks meow, dog barks woof, etc.
Abstraction
Hiding internal details and showing functionality is known as abstraction. For example phone call,
we don't know the internal processing.
Encapsulation
Binding (or wrapping) code and data together into a single unit are known as encapsulation.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
A java class is the example of encapsulation. Java bean is the fully encapsulated class
because all the data members are private here.
In this page, we will learn how to write the simple program of java. We can write a simple hello java
program easily after installing the JDK.
To create a simple java program, you need to create a class that contains the main method. Let's
understand the requirement first.
class Simple
{
public static void main(String args[])
{
System.out.println("Hello Java");
}
}
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Output:Hello Java
Compilation Flow:
When we compile Java program using javac tool, java compiler converts the source code
into byte code.
The core advantage of the static method is that there is no need to create an object to invoke
the static method. The main method is executed by the JVM, so it doesn't require to create an
object to invoke the main method. So it saves memory.
o void is the return type of the method. It means it doesn't return any value.
o main represents the starting point of the program.
o String[] args is used for command line argument. We will learn it later.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
o System.out.println() is used to print statement. Here, System is a class, out is the object of
PrintStream class, println() is the method of PrintStream class. We will learn about the internal
working of System.out.println statement later.
To write the simple program, you need to open notepad by start menu -> All Programs ->
Accessories -> notepad and write a simple program as displayed below:
As displayed in the above diagram, write the simple program of java in notepad and saved it as
Simple.java. To compile and run this program, you need to open the command prompt by
start menu -> All Programs -> Accessories -> command prompt.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
To compile and run the above program, go to your current directory first;
my current directory is c:\new. Write here:
1) By changing the sequence of the modifiers, method prototype is not changed in Java.
2) The subscript notation in Java array can be used after type, before the variable or
after the variable.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
3) You can provide var-args support to the main method by passing 3 ellipses (dots)
Let's see the simple code of using var-args in the main method. We will learn about var-args later in Java New
Features chapter.
class A{
static public void main(String... args){
System.out.println("hello java4");
}
};
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Java Variables
A variable is a container which holds the value while the Java program is executed.
Variable is a name of memory location. There are three types of variables in java: local, instance and static.
There are two types of data types in Java: primitive and non-primitive.
Variable
Variable is name of reserved area allocated in memory. In other words, it is a name of memory
location. It is a combination of "vary + able" that means its value can be changed.
Types of Variables
There are three types of variables in Java:
o local variable
o instance variable
o static variable
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
1) Local Variable
A variable declared inside the body of the method is called local variable.
You can use this variable only within that method and the other methods in the class aren't even
aware that the variable exists.
2) Instance Variable
A variable declared inside the class but outside the body of the method, is called instance variable.
It is called instance variable because its value is instance specific and is not shared among instances.
3) Static variable
You can create a single copy of static variable and share among all the instances of the class.
Memory allocation for static variable happens only once when the class is loaded in the memory.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Output:
20
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
1. Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and
double.
2. Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.
These are the most basic data types available in Java language.
Java is a statically-typed programming language. It means, all variables must be declared before its use.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Operators in Java
Operator in Java is a symbol which is used to perform operations. For example: +, -, *, / etc.
There are many types of operators in Java which are given below:
o Unary Operator,
o Arithmetic Operator,
o Shift Operator,
o Relational Operator,
o Bitwise Operator,
o Logical Operator,
o Ternary Operator and
o Assignment Operator.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Java Keywords
Java keywords are also known as reserved words. Keywords are particular words which
acts as a key to a code. These are predefined words by Java so it cannot be used as a variable or
object name.
1. abstract: Java abstract keyword is used to declare abstract class. Abstract class can provide the
implementation of interface. It can have abstract and non-abstract methods.
2. boolean: Java boolean keyword is used to declare a variable as a boolean type. It can hold True
and False values only.
3. break: Java break keyword is used to break loop or switch statement. It breaks the current flow
of the program at specified condition.
4. byte: Java byte keyword is used to declare a variable that can hold an 8-bit data values.
5. case: Java case keyword is used to with the switch statements to mark blocks of text.
6. catch: Java catch keyword is used to catch the exceptions generated by try statements.
7. char: Java char keyword is used to declare a variable that can hold unsigned 16-bit Unicode
characters
8. class: Java class keyword is used to declare a class.
9. continue: Java continue keyword is used to continue the loop. It continues the current flow
of the program and skips the remaining code at the specified condition.
10. default: Java default keyword is used to specify the default block of code in a switch statement.
11. do: Java do keyword is used in control statement to declare a loop. It can iterate a part of the
program several times.
12. double: Java double keyword is used to declare a variable that can hold a 64-bit floating-point
numbers.
13. else: Java else keyword is used to indicate the alternative branches in an if statement.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
14. enum: Java enum keyword is used to define a fixed set of constants. Enum constructors are
always private or default.
15. extends: Java extends keyword is used to indicate that a class is derived from another class or
interface.
16. final: Java final keyword is used to indicate that a variable holds a constant value. It is applied
with a variable. It is used to restrict the user.
17. finally: Java finally keyword indicates a block of code in a try-catch structure. This block is always
executed whether exception is handled or not.
18. float: Java float keyword is used to declare a variable that can hold a 32-bit floating-point number.
19. for: Java for keyword is used to start a for loop. It is used to execute a set of instructions/functions
repeatedly when some conditions become true. If the number of iteration is fixed,
It is recommended to use for loop.
20. if: Java if keyword tests the condition. It executes the if block if condition is true.
21. implements: Java implements keyword is used to implement an interface.
22. import: Java import keyword makes classes and interfaces available and accessible to the current
source code.
23. instanceof: Java instanceof keyword is used to test whether the object is an instance of the
specified class or implements an interface.
24. int: Java int keyword is used to declare a variable that can hold a 32-bit signed integer.
25. interface: Java interface keyword is used to declare an interface. It can have only abstract
methods.
26. long: Java long keyword is used to declare a variable that can hold a 64-bit integer.
27. native: Java native keyword is used to specify that a method is implemented in native code
using JNI (Java Native Interface).
28. new: Java new keyword is used to create new objects.
29. null: Java null keyword is used to indicate that a reference does not refer to anything.
It removes the garbage value.
30. package: Java package keyword is used to declare a Java package that includes the classes.
31. private: Java private keyword is an access modifier. It is used to indicate that a method or variable
may be accessed only in the class in which it is declared.
32. protected: Java protected keyword is an access modifier. It can be accessible within package and
outside the package but through inheritance only. It can't be applied on the class.
33. public: Java public keyword is an access modifier. It is used to indicate that an item is accessible
anywhere. It has the widest scope among all other modifiers.
34. return: Java return keyword is used to return from a method when its execution is complete.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
35. short: Java short keyword is used to declare a variable that can hold a 16-bit integer.
36. static: Java static keyword is used to indicate that a variable or method is a class method.
The static keyword in Java is used for memory management mainly.
37. strictfp: Java strictfp is used to restrict the floating-point calculations to ensure portability.
38. super: Java super keyword is a reference variable that is used to refer parent class object.
It can be used to invoke immediate parent class method.
39. switch: The Java switch keyword contains a switch statement that executes code based on
test value. The switch statement tests the equality of a variable against multiple values.
40. synchronized: Java synchronized keyword is used to specify the critical sections or methods in
multithreaded code.
41. this: Java this keyword can be used to refer the current object in a method or constructor.
42. throw: The Java throw keyword is used to explicitly throw an exception.
The throw keyword is mainly used to throw custom exception. It is followed by an instance.
43. throws: The Java throws keyword is used to declare an exception. Checked exception can be
propagated with throws.
44. transient: Java transient keyword is used in serialization. If you define any data member as
transient, it will not be serialized.
45. try: Java try keyword is used to start a block of code that will be tested for exceptions.
The try block must be followed by either catch or finally block.
46. void: Java void keyword is used to specify that a method does not have a return value.
47. volatile: Java volatile keyword is used to indicate that a variable may change asynchronously.
48. while: Java while keyword is used to start a while loop. This loop iterates a part of the program
several times. If the number of iteration is not fixed, it is recommended to use while loop.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
It checks boolean condition: true or false. There are various types of if statement in Java.
o if statement
o if-else statement
o if-else-if ladder
o nested if statement
It is like if-else-if ladder statement. The switch statement works with byte, short, int, long,
enum types, String and some wrapper types like Byte, Short, Int, and Long. Since Java 7,
you can use strings in the switch statement.
In other words, the switch statement tests the equality of a variable against multiple values.
Points to Remember
o There can be one or N number of case values for a switch expression.
o The case value must be of switch expression type only. The case value must be literal or constant.
It doesn't allow variables.
o The case values must be unique. In case of duplicate value, it renders compile-time error.
o The Java switch expression must be of byte, short, int, long (with its Wrapper type), enums and
string.
o Each case statement can have a break statement which is optional. When control reaches to break
statement, it jumps the control after the switch expression. If a break statement is not found,
it executes the next case.
o The case value can have a default label which is optional.
Syntax:
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
switch(expression){
case value1:
//code to be executed;
break; //optional
case value2:
//code to be executed;
break; //optional
......
default:
code to be executed if all cases are not matched;
}
Loops in Java
In programming languages, loops are used to execute a set of instructions/functions
repeatedly when some conditions become true. There are three types of loops in Java.
o for loop
o while loop
o do-while loop
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Java Arrays
Normally, an array is a collection of similar type of elements which has contiguous memory location.
Java array is an object which contains elements of a similar data type. Additionally, The elements
of an array are stored in a contiguous memory location. It is a data structure where we store similar
elements. We can store only a fixed set of elements in a Java array.
Array in Java is index-based, the first element of the array is stored at the 0th index, 2nd element is
stored on 1st index and so on.
Unlike C/C++, we can get the length of the array using the length member.
In Java, array is an object of a dynamically generated class. Java array inherits the Object class, and
implements the Serializable as well as Cloneable interfaces. We can store primitive values or objects in an
array in Java. Like C/C++, we can also create single dimentional or multidimentional arrays in Java.
Moreover, Java provides the feature of anonymous arrays which is not available in C/C++.
Advantages
o Code Optimization: It makes the code optimized, we can retrieve or sort the data efficiently.
o Random access: We can get any data located at an index position.
Disadvantages
o Size Limit: We can store only the fixed size of elements in the array. It doesn't grow its size at
runtime. To solve this problem, collection framework is used in Java which grows automatically.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
arrayRefVar=new datatype[size];
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
Output:
10
20
70
40
50
In such case, data is stored in row and column based index (also known as matrix form).
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
}
}}
Output:
1 2 3
2 4 5
4 4 5
Java String
In Java, string is basically an object that represents sequence of char values.
char[] ch={'j','a','v','a','t','p','o','i','n','t'};
String s=new String(ch);
same as:
String s="javatpoint";
Java String class provides a lot of methods to perform operations on strings such as
compare(), concat(), equals(), split(), length(), replace(), compareTo(), intern(), substring() etc.
Once string object is created its data or state can't be changed but a new string object is created.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
2. trim() method
The string trim() method eliminates white spaces before and after string.
3. charAt() method
The string charAt() method returns a character at specified index.
4. length() method
The string length() method returns length of the string.
5. valueOf() method
The string valueOf() method coverts given type such as int, long, float, double, boolean, char and
6. replace() method
The string replace() method replaces all occurrence of first sequence of character with second sequence
of character.
www.dacc.edu.in
PROF . SUPRIYA MANE
DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45
The StringBuffer class in java is same as String class except it is mutable i.e. it can be changed.
www.dacc.edu.in
PROF . SUPRIYA MANE