Java is an OOP (Object Oriented Programming) language i,e Java has classes.
A class is a description of an object
An object contains data and methods (We can call it instructions)
An object is like a special purpose computer.
A class is like the specs of the object computer.
There are 3 kinds of classes:
(I) Main class: contains the main method i,e, the start instruction
(II) Utility class: general tools
(III) Data class: used and defined by programmer i,e, custom class
A data type is a collection of values and operations on those values. Example: A class
Primitive types in Java:
int:
values: 37, -4, 0
operations: +, -, *, /, %
double:
values: 37.0, 14.99, -3.2
operations: +, -, *, /
char:
values: 'a', '3', '\', '\\'
boolean:
values: true, false
operations: !, &&, ||
To create an object of a class use the class constructor.
Classes have descriptions of methods.
A description has the following form:
return-type name(input)
or
void name(input)
NOTE:
pricePerItem -> method
PricePerItem -> class
String class
An object of the String class is a list (or sequence) of characters. The positions are 0, 1, 2, 3...
Example: "house" where h is at position 0, o at position 1, etc.
Some methods are:
char charAt(int position);
int indexOf(char ch);
int indexOf(String s);
boolean contains(String s);
String substring(int first, int last);
String replace(s1, s2); //replaces instances of s1 by s2
End of class 1, if questions or would like to give feedback, please, comment.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment