0% found this document useful (0 votes)
9 views13 pages

Java Classes and Methods Overview

This document summarizes a lecture on object-oriented programming concepts in Java, including classes, objects, methods, and the String class. It defines a class called Man with attributes like hair, eyes, and methods like walk() and talk(). It provides examples of using methods and explains that methods are declared within classes. Finally, it discusses the String class and some useful methods it contains for manipulating and comparing strings, like compareTo(), concat(), and indexOf().

Uploaded by

sukhna lake
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views13 pages

Java Classes and Methods Overview

This document summarizes a lecture on object-oriented programming concepts in Java, including classes, objects, methods, and the String class. It defines a class called Man with attributes like hair, eyes, and methods like walk() and talk(). It provides examples of using methods and explains that methods are declared within classes. Finally, it discusses the String class and some useful methods it contains for manipulating and comparing strings, like compareTo(), concat(), and indexOf().

Uploaded by

sukhna lake
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

NLP-AI

Java Lecture No. 9

Satish Dethe
<satishd@[Link]>
08 Oct 2004
Contents

• Objects & Class (Revision)


• Methods
• String Class

08 Oct 2004
nlp-ai@[Link]
Object & Class

Examples :

Class : Object :
Man Abdul Kalam
Fruit Banana
Language Java, Marathi
Car Maruti 800, Santro
Fort Lohgadh, Raigadh
Software Lab CFILT, TCS, CFDVS
Shooter Major Rajvardhan Singh Rathore

08 Oct 2004
nlp-ai@[Link]
Object & Class ….

These objects have different colors, locations & sizes.


Do they belong to the same class?
08 Oct 2004
nlp-ai@[Link]
Object & Class ….

• Class denotes category of objects, and act as blueprint for


creating such objects.
• Object of same class have same structure, it exhibits
properties & behaviors defined by its class.
• Properties is also called as attributes/fields & behaviors as
methods/operations.

08 Oct 2004
Class & Objects …
Class :
Attributes:
Hair, eyes, face, Neck,
torso, hands, legs.
Fingers, height, weight,
age.
Methods:
walk(), talk(), point(),
Laugh(), cry(), dance(),
steady()
[Definition of Class Man]
[Link]
08 Oct 2004
Object & Class …

08 Oct 2004
nlp-ai@[Link]
Method
• Need for Method
• General Syntax
<return type><method name>(<parameter list>)
{ //method body
<statement(s)>
}
NOTE: Methods are always declared inside class.
Return type is void if not returning anything, else concern data-
type.
Modify [Link]

08 Oct 2004
nlp-ai@[Link]
Method Examples
void hello(String guest){
//not returning anything
[Link](“Oh! Hello ” + guest);
}
int ReturnSquare (int a_number){
//returning data of type int
int square = a_number * a_number;
return square;
}
Refer : [Link]
08 Oct 2004
nlp-ai@[Link]
String Class

• String is a very special class in Java.


• Strings are constants, their values cannot be changed after they
are created. But they can be reinitialize.
String here=“I am here”;
here=“I am there”;//previous one is completely deleted
• Our rules and dictionaries can be stored string class.
• This class is armed with useful methods….
compareTo(String str), concate(String str), endsWith(String str),
indexOf(int ch), length(), startsWith(String str),
lastIndexOf(String str).

08 Oct 2004
nlp-ai@[Link]
String Class…

String machine = “pentium”;


int comp = [Link](“pentium”); //comp=0;
String lab= “Language”;
lab=[Link](“ Technology”); //lab=“Language Technology”;
int ind = [Link](‘t’);
boolean start = [Link](“pen”); //true
boolean end = [Link](“um”); //true
String part1=[Link](0,3); //part1=“pen”;
String part2=[Link](5);//part2=“um”;
Refer [Link], [Link]
08 Oct 2004
nlp-ai@[Link]
Assignments

• Mention your own class with some attributes & methods.(do


not implement).
• Enhance [Link]’s code to accept a string only of characters
from A to Z. (all in Upper case.)
Example:
AHCD is accepted.
A3HCD is rejected.
43534 is rejected.

08 Oct 2004 nlp-ai@[Link]


End

Thank You!

08 Oct 2004
nlp-ai@[Link]

You might also like