Venkatesh Maipathii
Venkatesh Maipathii
(a)Class
=>Based on Security:
ii
(i)Mutable Classes
ath
(ii)Immutable classes
(b)Object
aip
=>Object is a storage related to a class holding Instance members
of class.
hM
=>Based on Security,Objects are categorized into two types:
(i)Mutable Objects
(ii)Immutable Objects
tes
(c)Abstraction
a
nk
process.
(d)Encapsulation
(e)PolyMorphism
ii
form is known as PolyMorphism.
ath
(i)Dynamic PolyMorphism
aip
(ii)Static PolyMorphism
(i)Mutable Objects
(ii)Immutable Objects
tes
(f)Inheritance
known as Inheritance.
=>Types of Inheritances:
Ve
1.Single Inheritance
2.Multiple Inheritance
3.Multi-Level Inheritance
4.Hirarchal Inheritance
5.Hybrid Inheritance
=>According to realtime application development the Inheritances
1.Single Inheritance
===================================================================
=
ii
ath
*imp
Strings in Java:
Ex:
aip
hM
"nit","hyd",...
=>we use the following classes from java.lang package to create string
a
objects:
nk
1.String class
Ve
2.StringBuffer class
3.StringBuilder class
1.String class:
String s1 = "nit";
ii
String s2 = new String("program");
ath
Diagrams:
aip
hM
a tes
nk
Ve
Ex : DemoString1.java
package maccess;
public class DemoString1 {
public static void main(String[] args) {
String s1 = "nit";
int len1 = s1.length();
char ch1 = s1.charAt(1);
System.out.println("****s1****");
System.out.println("s1 : "+s1.toString());
System.out.println("length of s1 : "+len1);
System.out.println("char at index 1 : "+ch1);
String s2 = new String("program");
ii
int len2 = s2.length();
ath
char ch2 = s2.charAt(3);
System.out.println("****s2****");
System.out.println("s2 : "+s2.toString());
System.out.println("length of s2 : "+len2);
aip
System.out.println("char at index 3 : "+ch2);
}
}
hM
o/p:
****s1****
tes
s1 : nit
length of s1 : 3
a
char at index 1 : i
nk
****s2****
Ve
s2 : program
length of s2 : 7
char at index 3 : g
==============================================================
faq:
define toString() method?
syntax:
ii
String dt = obj.toString();
ath
faq:
aip
define length() method?
faq:
index value.
Ve
syntax:
char ch = str.charAt(index);
=================================================================
Assignment:
o/p : egaugnal
==================================================================
Ex-program:
ii
ath
i/p : str = "language"
aip
Vowels : a u a e
Count : 4
hM
a tes
nk
Ve
Program : DemoString2.java
package maccess;
import java.util.*;
public class DemoString2 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
try(s;) {
System.out.println("Enter the String:");
String str = s.nextLine();
int len = str.length();
int count=0;
System.out.print("Vowels : ");
for(int i=0;i<=len-1;i++)
{
char ch = str.charAt(i);//Char from index
switch(ch)
{
case 'a':
ii
case 'A':
ath
System.out.print(ch+" ");
count++;
break;
case 'e':
aip
case 'E':
System.out.print(ch+" ");
count++;
break;
hM
case 'i':
case 'I':
System.out.print(ch+" ");
count++;
break;
tes
case 'o':
case 'O':
System.out.print(ch+" ");
a
count++;
break;
nk
case 'u':
case 'U':
System.out.print(ch+" ");
Ve
count++;
break;
}//end of switch
}//end of loop
System.out.println("\nCount of Vowels :
"+count);
}//end of try with resource
}
}
o/p:
Vowels : a a a u a e o a i
ii
Count of Vowels : 9
ath
===================================================================
Assignment:
aip
wap to raed a String and,display Consonents and count of Consonents?
hM
Assignment:
Update above program displaying Vowels from the String,but display vowels
only once.
tes
===================================================================
faq:
a
nk
and which is unique code generated for each key pressed from the keyboard.
UpperCase Alphabets(A-Z) : 65 to 90
Numbers(0-9) : 48 to 57
Program : DemoString3.java
package maccess;
public class DemoString3
{
public static void main(String[] args)
{
System.out.println("****UserCase Alphabets(A-
ii
Z)****");
for(int i=65;i<=90;i++)
ath
{
char ch = (char)i;//ASCII code to Char
System.out.print(ch+" ");
aip
}
System.out.println("\n****LowerCase
Alphabets(a-z)****");
for(int i=97;i<=122;i++)
hM
{
char ch = (char)i;//ASCII code to Char
System.out.print(ch+" ");
}
System.out.println("\n****Numbers(0-9)****");
tes
for(int i=48;i<=57;i++)
{
char ch = (char)i;//ASCII code to Char
a
System.out.print(ch+" ");
}
nk
}
}
Ve
o/p:
****UserCase Alphabets(A-Z)****
ABCDEFGHIJKLMNOPQRSTUVWXYZ
****LowerCase Alphabets(a-z)****
abcdefghijklmnopqrstuvwxyz
****Numbers(0-9)****
0123456789
===================================================================
=======
ii
ath
aip
hM
a tes
nk
Ve