Professional Documents
Culture Documents
TYPES OF PROGRAMMING
2. High-level language
a) Procedural-Oriented language
b) Problem-Oriented language
c) Natural language
DISADVANTAGES OF FUNCTIONAL PROGRAMMING
o Writing pure functions is easy, but combining them into a complete application is where
things get hard
o For many people, recursion doesn’t feel natural
o Pure functions and I/O don’t mix
o Purely functional vocabularies work slower than the hash tables,
not suitable for algorithms in graphs (due to slow work)
CLASS & OBJECTS
What is Object?
o In real-world an entity that has state and its behavior is known as an object
For Example
o A Car is an object. It has states (name, color, model) and its behavior (changing gear,
applying brakes)
What is Class?
o A class is a template or blueprint that is used to create objects
o Class representation of objects and the sets of operations that can be applied to such
objects
o A class consists of data members and methods
DEFINING A CLASS IN JAVA
Syntax Example
public class class_name { public class Car {
Data Members; double color;
Methods; double model;
} }
CLASS MEMBERS
Example
o Using Class.forName()
MyObject object = (MyObject)
Class.forName("subin.rnd.MyObject").newInstance();
o Using clone()
MyObject anotherObject = new MyObject();
MyObject object = (MyObject) anotherObject.clone();
Example:01 Example:02
public class Myclass { public class Main {
int x; int x;
} public static void main(String[] args) {
class Main { Main myObj1 = new Main();
public static void main(String[] Main myObj2 = new Main();
args) { myobj1.x = 24;
Myclass myObj = new Myclass(); myobj2.x = 55;
myobj.x = 40; System.out.println(myObj1.x);
System.out.println(myObj.x); System.out.println(myObj2.x);
} }
} }
CREATE AN OBJECT
Myclass.java Mainclass.java
public class Myclass { class Main {
int x = 5; public static void main(String[] args) {
} MyClass myObj = new MyClass();
System.out.println(myObj.x);
}
}
3 WAYS TO INITIALIZE OBJECT
o By reference variable
o By method
o By constructor
3 WAYS TO INITIALIZE OBJECT
Example:01 Example:02
public class Myclass { public class Main {
int x = 10; final int x = 10;
} public static void main(String[] args)
class Main { {
public static void main(String[] args) Main myObj = new Main();
{ myObj.x = 25; // error
Main myObj = new Main(); System.out.println(myObj.x);
myObj.x = 25; }
System.out.println(myObj.x); }
}
}
LOGICAL SNIPPETS
class Test {
void start() {
String stra = "do";
String strb = method(stra);
System.out.print(": " + stra + strb);
}
String method(String stra) {
stra = stra + "good";
System.out.print(stra);
return " good";
}
}
class Main {
public static void main(String[] args) {
Test obj = new Test();
obj.start();
}
}