SlideShare uma empresa Scribd logo
1 de 61
UNIT I
OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
Object Oriented Programming Paradigm - Basic
Concepts of Object Oriented Programming –
Benefits and Applications of OOP – Java Features –
Java Program Structure – Command Line
Arguments – Variables and Data Types – Operators
– Expressions – Arrays - Control Statements –
Selection – Iteration - Jump Statements
OBJECT ORIENTED PROGRAMMING
FUNDAMENTALS
• Object=Data + Methods
Features of OBJECT ORIENTED
PARADIGMS
1. Data
2. Objects
3. Data structures
4. Methods
5. Hidden data
6. Communication
7. Addition of new data
8. Bottom up approach
Basic concepts of OBJECT ORIENTED
PROGRAMMING
I. OBJECTS & CLASSES
II. DATA ABSTRACTION & ENCAPSULATION
III. INHERITANCE
IV. POLYMORPHISM
V. DYNAMIC BINDING
VI. MESSAGE COMMUNICATION
I.OBJECTS & CLASSES
• Object-Basic runtime entity
• Class- Collection of objects of similar type
II.DATA ABSTRACTION &
ENCAPSULATION
• Encapsulation–Wrapping up of data and
methods into single unit(called class).
• Data hiding –Insulation of data from direct
access by program.
• Data abstraction Representing essential
features only.
III.INHERITANCE
• Objects of 1 class acquire the properties of
objects of another class.
IV.POLYMORPHISM
• Ability to take more than one form
V.DYNAMIC BINDING
• Linking of procedure call to code.
• Linking of method call to its corresponding
method definition takes place only during
runtime.
VI.MESSAGE COMMUNICATION
There are 3 steps.
• Class creation
• Object creation
• Establish communication
BENEFITS OF OOP
• Inheritance
• Time saving and high productivity.
• Data hiding
• Multiple objects
• Mapping of objects
• Easy to upgrade
• Communication through messages
• Can manage software complexity easily
APPLICATIONS OF OOP
• Real time systems.
• Simulation & Modelling.
• Object oriented DB
• AI
• Neural networks
JAVA FEATURES
Introduction:-
• Java is an object oriented language developed
by Sun Microsystems.
• Original name was OAK . Later renamed to
JAVA.
• Platform neutral language(platform
independent.)(Java Virtual Machine).
• Java is both compiled and interpreted
language.
Compilation Process
Execution Process
JAVA FEATURES
1. Java is both a compiled and an interpreted language.
2. Platform independent and portable-Write Once Run
Anywhere.
3. Object Oriented.
4. Robust and Secure.
5. Distributed.
6. Automatic Memory Management.
7. Dynamic binding
8. High performance.
9. Multithreading.
Some features in C/C++ are eliminated in java.
They are listed below.
• No Pointers
• No Preprocessor Directives
• No Multiple Inheritance in Classes
• No operator overloading.
• No global variables.
Simple Java Program
class Welcome
{
public static void main(String args[])
{
System.out.println(“Welcome to Java world “);
}
}
JAVA PROGRAM STRUCTURE
Simple Java Program
/* * To change this template, choose Tools | Templates and open the template in the
editor. */
package college;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql;
class sum
{
public static void main(String args[])
{
int i=10,j=25;
k=i+j;
System.out.println(“THE SUM IS “+k);
}
}
Download JDK and install in
Windows10- Use the following
YouTube link.
https://video.search.yahoo.com/search/video?fr
=mcafee&ei=UTF-
8&p=download+jdk&type=E211US1045G0#id=4
&vid=3aa873b105c9f56e6a73b619da6222ba&a
ction=click
Compilation code- javac filename.java
Execution code- java filename
JAVA TOKENS
• In Java every statement is made up of smallest
individual elements called tokens. Tokens in java
include the following:-
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Separators
1. Keywords
• Keywords cannot be redefined by a
programmer
• Keywords cannot be used as identifier name.
Eg: Abstract, Assert, Boolean, Break, Byte, Case.
• Java language has reserved 50 words as
keywords.
2. Identifiers
• Programmer designed tokens. Used for naming
variables, methods, classes etc.
• An identifier can contain alphanumeric
characters, but it should begin with an alphabet.
• Identifiers are case sensitive.
• Underscore and dollar sign are two special
character allowed.
• Eg:A23C
• Bob@gmail - Wrong
3. Literals
• LITERAL is a program element that represents
an exact (fixed) value of a certain type. Java
language supports the following type of
literals.
1. Integer Literals. (Ex. 123)
2. Floating point Literals. (Ex. 88.223)
3. Character Literals. (Ex. ‘.’ , ‘a’ , ‘n’)
4. String Literals. (Ex. “Hello World”)
5. Boolean Literals. (Ex. True,false)
4. Separators
• Symbols used to indicate where group of code
are divided and arranged.
• ()
• {}
• []
• ;
• ,
• .
5. Operators
• Tells the computer to perform certain
mathematical or logical manipulations on data
and variables. Different types are:-
1. Arithmetic Operators.
2. Unary Operators.
3. Assignment Operators.
4. Equality and Relational Operators.
5. Logical and Conditional Operators.
6. Bitwise and Bit Shift Operators.
7. Special operators
1. Arithmetic Operators
Eg: a+b
a-b
a*b
a/b
a%b
2. Unary Operators
Eg: +b
-b
++b
--b
3. Assignment Operators
Eg:a=b+c;
a=a+1; and a+=1; same meaning.
a+=1 is shorthand assignment operator.
4. Equality and Relational Operators
Eg: a==b;
a!=b;
• Value of relational expression is either true or false.
• It is used in decision statements.
Eg: a<b;
a>b;
a<=b;
a>=b;
5. Logical and Conditional Operators.
• Used to form compound conditions by combining 2 or more
relations.
&& -logical AND
|| -logical OR.
! – logical compliment.
Eg: a>b && x==10;
?: - Conditional ternary opeartor(shorthand for if-then-else
statement).
Eg: x=(a>b)?a:b;
6. Bitwise and Bit Shift Operators
~ Unary bitwise complement
<< Signed left shift
>> Signed right sift
>>> Unsigned right shift
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise inclusive OR
7. Special Operators
1. Instanceof operator
Eg: person instanceof student.
• Checks whether object person belongs to class student or not.
• Returns either true or false
2. Dot operator /member selection operator
• Used to access variables and methods of a class object.
Eg: Person1.age;
Person1.salary();
Where person1 is an object .
Age is a variable
Salary() is a method.
Example:Operators
• public class StringLowerUpperExample{
• public static void main(String args[]){
• String s1="JAVATPOINT HELLO stRIng";
• String s1lower=s1.toLowerCase();
• System.out.println(s1lower);
• String s2="hello string";
• String s1upper=s2.toUpperCase();
• System.out.println(s1upper);
• }}
Operator Precedence Table
Operator Precedence
Operators Precedence
postfix expr++ expr--
unary ++expr --expr +expr -expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
EXPRESSIONS
• Java expressions are used to implement some computation.
• Syntax: Variable=Exprerssion;
• Simple Expression : x=a+b;
• Complicated expression : a*(b+c)/(m+n)*f;
In this example,
1. (b+c) or (m+n) executed first since it is written inside
brackets.(From left to right or right to left. Refer operator
precedence table in Unit1Part1.pdf).
2. a*(b+c), or (m+n)*f executes multiplication operation secondly.
3. Finally division operation takes place.
COMMAND LINE ARGUMENTS
• Command line arguments are parameters that are supplied to the
application program at the time of invoking it for execution.
• Eg:- public static void main(String args[]).
• Eg: javac hello.java
java hello 123 abc 12.88
Then,
• args[0] contains 123
• args[1] contains abc
• args[2] contains 12.88
• Wrapper classes are used to convert the string to corresponding
simpler data type.
• ie, static int parseInt(String s)
• For example: int value= Integer.parseInt(“123”)
• Int total=args.length;
• Converts stirng 10 to integer data type.
Fibonacci series
class fib{
public static void main(String args[])
{
int n;
int a=0,b=1,c;
n=Integer.parseInt(args[0]);
for(int i=0;i<n;i++)
{
c=a+b;
System.out.println("The next number is "+c);
a=b;
b=c;
}
}
}
VARIABLES
• Variables refers to names of storage location
which is used to store data vales.
Eg: int i;
int i=3,j=5;
• Can take different values at different times during
execution of the program.
• Similar as identifiers.
• Assignment method
• readline() method.(Type casting)
Variables example- readLine()
import java.io.Console;
class exampleread
{
public static void main(String args[])
{
String str;
Console con = System.console();
if(con == null)
{
System.out.print("No console available");
return;
}
str = con.readLine("Enter your name: ");
con.printf("Here is your name: %sn", str);
}
}
VARIABLES(readLine() & Type casting
using wrapper classes)
import java.io.Console;
class examplereadline
{
try{
public static void main(String args[])
{
int age=0;
Console con = System.console();
age= Integer.parseInt(con.readLine("Enter your age") );
con.printf("Here is your age:%dn", age);
}
}
Catch{
}
}
Scope of variables
• Instance variables - Created when objects are instantiated and
takes different values for each object.
Eg: student s1=new student();
• Each object has its own copy of instance variables.
• Class variables - Available to all methods in a class.
• Local variables – Local to the method inside it is declared.
Scope of variables-Example
// Demonstrate block scope.
class Scope {
public static void main(String args[]) {
int x; // known to all code within main
x = 10;
if(x == 10) { // start new scope
int y = 20; // known only to this block
// x and y both known here.
System.out.println("x and y: " + x + " " + y);
x = y * 2;
}
// y = 100; // Error! y not known here
// x is still known here.
System.out.println("x is " + x);
}
}
CONSTANTS
• Constants refer to values that do not change
during the execution of the program.
• Java supports following types of constants.
• Integer constant. Eg:2021.
• Real/Floating point constant. Eg: 32.567.
• String constant. Eg: “Hello World”.
• Character constant. Eg: ‘a’.
• Final float pi=3.142;
• Apart from these types of constants java also
supports backslash character constants.
BACKSLASH CONSTANT PURPOSE
b Backspace
f Form feed
n New Line
r Carriage return
t Horizontal tab
 Backslash
DATA TYPES
Data types
Integer
char a = 'G';
int i=89;
byte b = 4;
short s = 56;
float f = 4.7333434f;
double d = 4.355453532d;
Data types- Example
class datatypes{
public static void main(String args[]){
char a = 'G';
int i=89;
byte b = 4;
short s = 3;
double d = 4.355453532d;
float f = 4.7333434f;
System.out.println("char: " + a);
System.out.println("integer: " + i);
System.out.println("byte: " + b);
System.out.println("short: " + s);
System.out.println("float: " + f);
System.out.println("double: " + d);
}
}
ARRAYS
• An array is a group of contiguous/related data
items that share a common name.
• Syntax: Data type Arrayname[];
• Eg: int salary[9] or int[] salary;
• 3 steps to create the array.
• 1) Declare the array->Only a reference of array
created.
• 2) Create the memory allocation->
salary=new int[9];
• 3)Putting values to memory location.
Array representation:-
Int a=Arrayname.length; // To find length of the array.
One dimensional Arrays.
Array Literal
In a situation, where the size of the array and variables of
array are already known, array literals can be used.
int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 };
class Testarray{
public static void main(String args[]){
int a[]=new int[5];//declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
//traversing array
for(int i=0;i<a.length;i++)//length is the property of array
System.out.println(a[i]);
}}
Arrays as Parameters
 An entire array can be passed as a parameter to a
method
 Like any other object, the reference to the array is
passed, making the formal and actual parameters aliases
of each other
 Changing an array element within the method changes
the original
 An array element can be passed to a method as well, and
follows the parameter passing rules of that element's
type
class Testarray3{
//creating a method which receives an array as a parameter
static void min(int arr[]){
int min=arr[0];
for(int i=1;i<arr.length;i++)
if(min>arr[i])
min=arr[i];
System.out.println(min);
}
public static void main(String args[]){
int a[]={33,3,4,5};//declaring and initializing an array
min(a);//passing array to method
}}
Two Dimensional Arrays
int[][] intArray = new int[10][20]; //a 2D array
or matrix
Array-Assigning values can be done directly or
using loops.
public static void main(String args[])
{
// declaring and initializing 2D array
int arr[][] = { {2,7,9},{3,6,1},{7,4,2} };
// printing 2D array
for (int i=0; i< 3 ; i++)
{
for (int j=0; j < 3 ; j++)
System.out.print(arr[i][j] + " ");
System.out.println();
}
}
Multi Dimensional Arrays
• int[][][] intArray = new int[10][20][10]; //a 3D
array .
• Known as Jagged Arrays.
• Strings- Character Array or String Objects.
STRINGS
• It is the most common part of many java
programs.
• String represent a sequence of characters.
• The simplest way to represent a sequence of
characters in java is by using a character array.
• Example:
char charArray[ ] = new char[4];
charArray[0] = ‘J’;
charArray[1] = ‘a’;
DECLARATION OF STRING
• Example:
STRING ARRAYS
• Array can be created and used that contain
strings.
• Above statement create following effects:
 In Java, strings are class objects and implemented
using two classes,namely, String and StringBuffer.
 A java string is an instantiated object of the String
class.
 Java string as compared to C strings, are more
reliable and predicable.
 A java string is not a character array and is not
NULL terminated.
STRING METHODS
 String class defines a number of methods that
allow us to accomplish a variety of string
manipulation tasks.
 Eg: 1) s2=s1.toLowercase;
2) s2=s1.toUppercase;
3) s1.compareTo(s2) //To sort array of
strings.
STRING BUFFER CLASS
 StringBuffer is a peer class of String.
 While String creates strings of fixed_length,
StringBuffer creates strings of flexible length that
can be modified in term of both length and content.
 We can insert characters and substrings in the
middle of a string to the end.

Mais conteúdo relacionado

Mais procurados

Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiSowmya Jyothi
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language CourseVivek chan
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab MashaelQ
 
Monadic genetic kernels in Scala
Monadic genetic kernels in ScalaMonadic genetic kernels in Scala
Monadic genetic kernels in ScalaPatrick Nicolas
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2Shameer Ahmed Koya
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)Dushmanta Nath
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Functions
FunctionsFunctions
FunctionsOnline
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers Appili Vamsi Krishna
 
07 control+structures
07 control+structures07 control+structures
07 control+structuresbaran19901990
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)Mansi Tyagi
 

Mais procurados (20)

Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
 
Yacc
YaccYacc
Yacc
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab
 
Code generation
Code generationCode generation
Code generation
 
Monadic genetic kernels in Scala
Monadic genetic kernels in ScalaMonadic genetic kernels in Scala
Monadic genetic kernels in Scala
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2
 
Compiler Design Tutorial
Compiler Design Tutorial Compiler Design Tutorial
Compiler Design Tutorial
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Lexyacc
LexyaccLexyacc
Lexyacc
 
Functions
FunctionsFunctions
Functions
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Handout#10
Handout#10Handout#10
Handout#10
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 

Semelhante a Programming in java basics (20)

02basics
02basics02basics
02basics
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Unit 1
Unit 1Unit 1
Unit 1
 
Java
Java Java
Java
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java Intro
Java IntroJava Intro
Java Intro
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3
 
1_JavIntro
1_JavIntro1_JavIntro
1_JavIntro
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
 
Session 1 of programming
Session 1 of programmingSession 1 of programming
Session 1 of programming
 
Java 8
Java 8Java 8
Java 8
 
C#2
C#2C#2
C#2
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 
Java 101
Java 101Java 101
Java 101
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
C
CC
C
 

Mais de LovelitJose

Professional ethics-Unit5
Professional ethics-Unit5Professional ethics-Unit5
Professional ethics-Unit5LovelitJose
 
Professional ethics-Unit4
Professional ethics-Unit4Professional ethics-Unit4
Professional ethics-Unit4LovelitJose
 
Professional ethics-Unit3
Professional ethics-Unit3Professional ethics-Unit3
Professional ethics-Unit3LovelitJose
 
Professional Ethics Unit2
Professional Ethics Unit2Professional Ethics Unit2
Professional Ethics Unit2LovelitJose
 
Professional ethics PPT unit 1
Professional ethics PPT unit 1Professional ethics PPT unit 1
Professional ethics PPT unit 1LovelitJose
 
Programming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsProgramming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsLovelitJose
 

Mais de LovelitJose (6)

Professional ethics-Unit5
Professional ethics-Unit5Professional ethics-Unit5
Professional ethics-Unit5
 
Professional ethics-Unit4
Professional ethics-Unit4Professional ethics-Unit4
Professional ethics-Unit4
 
Professional ethics-Unit3
Professional ethics-Unit3Professional ethics-Unit3
Professional ethics-Unit3
 
Professional Ethics Unit2
Professional Ethics Unit2Professional Ethics Unit2
Professional Ethics Unit2
 
Professional ethics PPT unit 1
Professional ethics PPT unit 1Professional ethics PPT unit 1
Professional ethics PPT unit 1
 
Programming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsProgramming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-Expressions
 

Último

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 

Último (20)

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 

Programming in java basics

  • 1. UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS Object Oriented Programming Paradigm - Basic Concepts of Object Oriented Programming – Benefits and Applications of OOP – Java Features – Java Program Structure – Command Line Arguments – Variables and Data Types – Operators – Expressions – Arrays - Control Statements – Selection – Iteration - Jump Statements
  • 3. Features of OBJECT ORIENTED PARADIGMS 1. Data 2. Objects 3. Data structures 4. Methods 5. Hidden data 6. Communication 7. Addition of new data 8. Bottom up approach
  • 4. Basic concepts of OBJECT ORIENTED PROGRAMMING I. OBJECTS & CLASSES II. DATA ABSTRACTION & ENCAPSULATION III. INHERITANCE IV. POLYMORPHISM V. DYNAMIC BINDING VI. MESSAGE COMMUNICATION
  • 5. I.OBJECTS & CLASSES • Object-Basic runtime entity • Class- Collection of objects of similar type
  • 6. II.DATA ABSTRACTION & ENCAPSULATION • Encapsulation–Wrapping up of data and methods into single unit(called class). • Data hiding –Insulation of data from direct access by program. • Data abstraction Representing essential features only.
  • 7. III.INHERITANCE • Objects of 1 class acquire the properties of objects of another class.
  • 8. IV.POLYMORPHISM • Ability to take more than one form
  • 9. V.DYNAMIC BINDING • Linking of procedure call to code. • Linking of method call to its corresponding method definition takes place only during runtime.
  • 10. VI.MESSAGE COMMUNICATION There are 3 steps. • Class creation • Object creation • Establish communication
  • 11. BENEFITS OF OOP • Inheritance • Time saving and high productivity. • Data hiding • Multiple objects • Mapping of objects • Easy to upgrade • Communication through messages • Can manage software complexity easily
  • 12. APPLICATIONS OF OOP • Real time systems. • Simulation & Modelling. • Object oriented DB • AI • Neural networks
  • 13. JAVA FEATURES Introduction:- • Java is an object oriented language developed by Sun Microsystems. • Original name was OAK . Later renamed to JAVA. • Platform neutral language(platform independent.)(Java Virtual Machine). • Java is both compiled and interpreted language.
  • 15.
  • 16. JAVA FEATURES 1. Java is both a compiled and an interpreted language. 2. Platform independent and portable-Write Once Run Anywhere. 3. Object Oriented. 4. Robust and Secure. 5. Distributed. 6. Automatic Memory Management. 7. Dynamic binding 8. High performance. 9. Multithreading.
  • 17. Some features in C/C++ are eliminated in java. They are listed below. • No Pointers • No Preprocessor Directives • No Multiple Inheritance in Classes • No operator overloading. • No global variables.
  • 18. Simple Java Program class Welcome { public static void main(String args[]) { System.out.println(“Welcome to Java world “); } }
  • 20. Simple Java Program /* * To change this template, choose Tools | Templates and open the template in the editor. */ package college; import java.io.IOException; import java.io.PrintWriter; import java.sql; class sum { public static void main(String args[]) { int i=10,j=25; k=i+j; System.out.println(“THE SUM IS “+k); } }
  • 21. Download JDK and install in Windows10- Use the following YouTube link. https://video.search.yahoo.com/search/video?fr =mcafee&ei=UTF- 8&p=download+jdk&type=E211US1045G0#id=4 &vid=3aa873b105c9f56e6a73b619da6222ba&a ction=click Compilation code- javac filename.java Execution code- java filename
  • 22. JAVA TOKENS • In Java every statement is made up of smallest individual elements called tokens. Tokens in java include the following:- 1. Keywords 2. Identifiers 3. Literals 4. Operators 5. Separators
  • 23. 1. Keywords • Keywords cannot be redefined by a programmer • Keywords cannot be used as identifier name. Eg: Abstract, Assert, Boolean, Break, Byte, Case. • Java language has reserved 50 words as keywords.
  • 24. 2. Identifiers • Programmer designed tokens. Used for naming variables, methods, classes etc. • An identifier can contain alphanumeric characters, but it should begin with an alphabet. • Identifiers are case sensitive. • Underscore and dollar sign are two special character allowed. • Eg:A23C • Bob@gmail - Wrong
  • 25. 3. Literals • LITERAL is a program element that represents an exact (fixed) value of a certain type. Java language supports the following type of literals. 1. Integer Literals. (Ex. 123) 2. Floating point Literals. (Ex. 88.223) 3. Character Literals. (Ex. ‘.’ , ‘a’ , ‘n’) 4. String Literals. (Ex. “Hello World”) 5. Boolean Literals. (Ex. True,false)
  • 26. 4. Separators • Symbols used to indicate where group of code are divided and arranged. • () • {} • [] • ; • , • .
  • 27. 5. Operators • Tells the computer to perform certain mathematical or logical manipulations on data and variables. Different types are:- 1. Arithmetic Operators. 2. Unary Operators. 3. Assignment Operators. 4. Equality and Relational Operators. 5. Logical and Conditional Operators. 6. Bitwise and Bit Shift Operators. 7. Special operators
  • 28. 1. Arithmetic Operators Eg: a+b a-b a*b a/b a%b 2. Unary Operators Eg: +b -b ++b --b
  • 29. 3. Assignment Operators Eg:a=b+c; a=a+1; and a+=1; same meaning. a+=1 is shorthand assignment operator. 4. Equality and Relational Operators Eg: a==b; a!=b; • Value of relational expression is either true or false. • It is used in decision statements. Eg: a<b; a>b; a<=b; a>=b;
  • 30. 5. Logical and Conditional Operators. • Used to form compound conditions by combining 2 or more relations. && -logical AND || -logical OR. ! – logical compliment. Eg: a>b && x==10; ?: - Conditional ternary opeartor(shorthand for if-then-else statement). Eg: x=(a>b)?a:b;
  • 31. 6. Bitwise and Bit Shift Operators ~ Unary bitwise complement << Signed left shift >> Signed right sift >>> Unsigned right shift & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR
  • 32. 7. Special Operators 1. Instanceof operator Eg: person instanceof student. • Checks whether object person belongs to class student or not. • Returns either true or false 2. Dot operator /member selection operator • Used to access variables and methods of a class object. Eg: Person1.age; Person1.salary(); Where person1 is an object . Age is a variable Salary() is a method.
  • 33. Example:Operators • public class StringLowerUpperExample{ • public static void main(String args[]){ • String s1="JAVATPOINT HELLO stRIng"; • String s1lower=s1.toLowerCase(); • System.out.println(s1lower); • String s2="hello string"; • String s1upper=s2.toUpperCase(); • System.out.println(s1upper); • }}
  • 34. Operator Precedence Table Operator Precedence Operators Precedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
  • 35. EXPRESSIONS • Java expressions are used to implement some computation. • Syntax: Variable=Exprerssion; • Simple Expression : x=a+b; • Complicated expression : a*(b+c)/(m+n)*f; In this example, 1. (b+c) or (m+n) executed first since it is written inside brackets.(From left to right or right to left. Refer operator precedence table in Unit1Part1.pdf). 2. a*(b+c), or (m+n)*f executes multiplication operation secondly. 3. Finally division operation takes place.
  • 36. COMMAND LINE ARGUMENTS • Command line arguments are parameters that are supplied to the application program at the time of invoking it for execution. • Eg:- public static void main(String args[]). • Eg: javac hello.java java hello 123 abc 12.88 Then, • args[0] contains 123 • args[1] contains abc • args[2] contains 12.88 • Wrapper classes are used to convert the string to corresponding simpler data type. • ie, static int parseInt(String s) • For example: int value= Integer.parseInt(“123”) • Int total=args.length; • Converts stirng 10 to integer data type.
  • 37. Fibonacci series class fib{ public static void main(String args[]) { int n; int a=0,b=1,c; n=Integer.parseInt(args[0]); for(int i=0;i<n;i++) { c=a+b; System.out.println("The next number is "+c); a=b; b=c; } } }
  • 38. VARIABLES • Variables refers to names of storage location which is used to store data vales. Eg: int i; int i=3,j=5; • Can take different values at different times during execution of the program. • Similar as identifiers. • Assignment method • readline() method.(Type casting)
  • 39. Variables example- readLine() import java.io.Console; class exampleread { public static void main(String args[]) { String str; Console con = System.console(); if(con == null) { System.out.print("No console available"); return; } str = con.readLine("Enter your name: "); con.printf("Here is your name: %sn", str); } }
  • 40. VARIABLES(readLine() & Type casting using wrapper classes) import java.io.Console; class examplereadline { try{ public static void main(String args[]) { int age=0; Console con = System.console(); age= Integer.parseInt(con.readLine("Enter your age") ); con.printf("Here is your age:%dn", age); } } Catch{ } }
  • 41. Scope of variables • Instance variables - Created when objects are instantiated and takes different values for each object. Eg: student s1=new student(); • Each object has its own copy of instance variables. • Class variables - Available to all methods in a class. • Local variables – Local to the method inside it is declared.
  • 42. Scope of variables-Example // Demonstrate block scope. class Scope { public static void main(String args[]) { int x; // known to all code within main x = 10; if(x == 10) { // start new scope int y = 20; // known only to this block // x and y both known here. System.out.println("x and y: " + x + " " + y); x = y * 2; } // y = 100; // Error! y not known here // x is still known here. System.out.println("x is " + x); } }
  • 43. CONSTANTS • Constants refer to values that do not change during the execution of the program. • Java supports following types of constants.
  • 44. • Integer constant. Eg:2021. • Real/Floating point constant. Eg: 32.567. • String constant. Eg: “Hello World”. • Character constant. Eg: ‘a’. • Final float pi=3.142; • Apart from these types of constants java also supports backslash character constants. BACKSLASH CONSTANT PURPOSE b Backspace f Form feed n New Line r Carriage return t Horizontal tab Backslash
  • 46. Data types Integer char a = 'G'; int i=89; byte b = 4; short s = 56; float f = 4.7333434f; double d = 4.355453532d;
  • 47. Data types- Example class datatypes{ public static void main(String args[]){ char a = 'G'; int i=89; byte b = 4; short s = 3; double d = 4.355453532d; float f = 4.7333434f; System.out.println("char: " + a); System.out.println("integer: " + i); System.out.println("byte: " + b); System.out.println("short: " + s); System.out.println("float: " + f); System.out.println("double: " + d); } }
  • 48. ARRAYS • An array is a group of contiguous/related data items that share a common name. • Syntax: Data type Arrayname[]; • Eg: int salary[9] or int[] salary; • 3 steps to create the array. • 1) Declare the array->Only a reference of array created. • 2) Create the memory allocation-> salary=new int[9]; • 3)Putting values to memory location.
  • 49. Array representation:- Int a=Arrayname.length; // To find length of the array. One dimensional Arrays. Array Literal In a situation, where the size of the array and variables of array are already known, array literals can be used. int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 };
  • 50. class Testarray{ public static void main(String args[]){ int a[]=new int[5];//declaration and instantiation a[0]=10;//initialization a[1]=20; a[2]=70; a[3]=40; a[4]=50; //traversing array for(int i=0;i<a.length;i++)//length is the property of array System.out.println(a[i]); }}
  • 51. Arrays as Parameters  An entire array can be passed as a parameter to a method  Like any other object, the reference to the array is passed, making the formal and actual parameters aliases of each other  Changing an array element within the method changes the original  An array element can be passed to a method as well, and follows the parameter passing rules of that element's type
  • 52. class Testarray3{ //creating a method which receives an array as a parameter static void min(int arr[]){ int min=arr[0]; for(int i=1;i<arr.length;i++) if(min>arr[i]) min=arr[i]; System.out.println(min); } public static void main(String args[]){ int a[]={33,3,4,5};//declaring and initializing an array min(a);//passing array to method }}
  • 53. Two Dimensional Arrays int[][] intArray = new int[10][20]; //a 2D array or matrix
  • 54. Array-Assigning values can be done directly or using loops. public static void main(String args[]) { // declaring and initializing 2D array int arr[][] = { {2,7,9},{3,6,1},{7,4,2} }; // printing 2D array for (int i=0; i< 3 ; i++) { for (int j=0; j < 3 ; j++) System.out.print(arr[i][j] + " "); System.out.println(); } }
  • 55. Multi Dimensional Arrays • int[][][] intArray = new int[10][20][10]; //a 3D array . • Known as Jagged Arrays. • Strings- Character Array or String Objects.
  • 56. STRINGS • It is the most common part of many java programs. • String represent a sequence of characters. • The simplest way to represent a sequence of characters in java is by using a character array. • Example: char charArray[ ] = new char[4]; charArray[0] = ‘J’; charArray[1] = ‘a’;
  • 58. STRING ARRAYS • Array can be created and used that contain strings. • Above statement create following effects:
  • 59.  In Java, strings are class objects and implemented using two classes,namely, String and StringBuffer.  A java string is an instantiated object of the String class.  Java string as compared to C strings, are more reliable and predicable.  A java string is not a character array and is not NULL terminated.
  • 60. STRING METHODS  String class defines a number of methods that allow us to accomplish a variety of string manipulation tasks.  Eg: 1) s2=s1.toLowercase; 2) s2=s1.toUppercase; 3) s1.compareTo(s2) //To sort array of strings.
  • 61. STRING BUFFER CLASS  StringBuffer is a peer class of String.  While String creates strings of fixed_length, StringBuffer creates strings of flexible length that can be modified in term of both length and content.  We can insert characters and substrings in the middle of a string to the end.