Concept of Object Oriented Programming is built around four basic ideas of inheritance, polymorphism, abstraction, and encapsulation. These ideas were not new when Java was introduced, programming language like C++ did support it very well but one can say that C++ was not a "strong" object oriented language. It was still possible to write logic(code) without OOP concepts. Java is one of its kind, it enforces programmer to use certain OOP constructs. Right now Java is widely used for internet(web) programming, embedded systems, desktop programming etc. It being an open source language supported by many application and web servers it becomes a strong candidate for enterprise level applications.
The language is built around basic concepts of Classes and Objects, a concept so simple yet powerful. Concept of classification is not unknown in science, we classify objects sharing similar attributes and name them. For example we classify living beings as mammals, reptiles etc or cars as sedan, SUVs, coupe. Similarly we classify programming constructs which are similar.
For example any web site where a user have to login can have a class named User. Reasons are simple, all the users will have First Name, Last Name, Password and so forth this means that we can design a class that will carry these properties and when we will instantiate this class it will have values for each of the property. See the following pseudo code example for clarity.
Instance sapan of the Class User: {FirstName=Sapan,LastName=parikh,password=sapankumar}
In the example above class users have certain properties and then we make a copy of it which actually have some certain values. These copies with definitive values are called objects, object of class User or Objects of type User.
We can translate above example to Java, we can create a class named User and then we will make its objects and then print the values of these objects.
int id;
String firstName;
String lastName;
String password;
}
This is the most simple possible definition of a class in Java.
Id, firstName, lastName and password are the variables of class User. These variable should acquire some values when we instantiate this class but the question still persists, how do we instantiate this class?
We will add the following code to the class so that we can instantiate the class and at the same time we can also assign values to these variables.
int id;
String firstName;
String lastName;
String password;
public User(String fName,String lastName,String pass){
firstName = fName;
lastName = lName;
password = pass;
}
}
Some code has been added so that the class is "instantiatable" but still we have not created any instance of the class User. We will do that next.
public class User{
int id;
String firstName;
String lastName;
String password;
public User(int i, String fName,String lastName,String pass){ //3
id = i; //4
firstName = fName; //5
lastName = lName; //6
password = pass; //7
}
public static void main(String args[]){ //1
User u = new User(1,"Nishith","Desai","********"); //2
System.out.println(u.firstName+" "+u.lastName+" "+u.password); //8
}
}
Now class above actually creates an instance of itself, let us see how. For any Java program to run the "main" function is needed which is defined above as "public static void main(String args[])" this one line means as an entry point to Java programs. This is the line from where Java compiler says "let there be light." To comment a line in Java one can use two slashes "//"
Comments in the above program actually shows the order of the statements executed in the program. "System.out.println" will print the attribute values of the class User when the program is ran. Only prerequisite to run a Java program is to have a JDK. Install your JDK from http://java.sun.com or download the NetBeans IDE and follow the guide given bellow to run your first program.
For example any web site where a user have to login can have a class named User. Reasons are simple, all the users will have First Name, Last Name, Password and so forth this means that we can design a class that will carry these properties and when we will instantiate this class it will have values for each of the property. See the following pseudo code example for clarity.
Example:
Class User: properties {FirstName, LastName,Password};Instance sapan of the Class User: {FirstName=Sapan,LastName=parikh,password=sapankumar}
In the example above class users have certain properties and then we make a copy of it which actually have some certain values. These copies with definitive values are called objects, object of class User or Objects of type User.
We can translate above example to Java, we can create a class named User and then we will make its objects and then print the values of these objects.
Java Example:
public class User{int id;
String firstName;
String lastName;
String password;
}
This is the most simple possible definition of a class in Java.
Id, firstName, lastName and password are the variables of class User. These variable should acquire some values when we instantiate this class but the question still persists, how do we instantiate this class?
We will add the following code to the class so that we can instantiate the class and at the same time we can also assign values to these variables.
Java Example:
public class User{int id;
String firstName;
String lastName;
String password;
public User(String fName,String lastName,String pass){
firstName = fName;
lastName = lName;
password = pass;
}
}
Some code has been added so that the class is "instantiatable" but still we have not created any instance of the class User. We will do that next.
public class User{
int id;
String firstName;
String lastName;
String password;
public User(int i, String fName,String lastName,String pass){ //3
id = i; //4
firstName = fName; //5
lastName = lName; //6
password = pass; //7
}
public static void main(String args[]){ //1
User u = new User(1,"Nishith","Desai","********"); //2
System.out.println(u.firstName+" "+u.lastName+" "+u.password); //8
}
}
Now class above actually creates an instance of itself, let us see how. For any Java program to run the "main" function is needed which is defined above as "public static void main(String args[])" this one line means as an entry point to Java programs. This is the line from where Java compiler says "let there be light." To comment a line in Java one can use two slashes "//"
Comments in the above program actually shows the order of the statements executed in the program. "System.out.println" will print the attribute values of the class User when the program is ran. Only prerequisite to run a Java program is to have a JDK. Install your JDK from http://java.sun.com or download the NetBeans IDE and follow the guide given bellow to run your first program.
...To Be Continued






Frank
Invite as author
Smalltalk ?
Smalltalk is a much more dynamic language and much better suited for rapid development than Java. Have a look at VisualWorks Smalltalk !
Also, Java does have strong drawbacks compared to C++ when it comes to runtime efficiency.
Well, I think he speaks here about Java, not about why is Java bad and the rest of the world good. People use Java because is intuitive, it allows the development of complex solutions at a lower cost comparing with C++/Smalltalk. If performance is a decisive issue, you may use C++/Smalltalk, although such requirements go beyond C++/Smalltalk language, they involve usage of special SMP configurations and access to computation dedicated hardware.
You may write about C++ and Smalltalk or even compare them if you wish. Or even compare them with Java. I would be very interested to review your methodology for comparisons you will do.
How many IDEs are available for Smalltalk? How many GUI libraries are available? Why not Cocoa or ObjectiveC, it runs great on Mac and I don't care the rest? VisualWorks is exactly so powerful as the company behind it, Cincom.
C++ have strong drawback compared to C with BLAS / Cuda / CTM when it comes to runtime efficiency.
EditSaveCancelDeleteDeleteBlock this userReport abusive commentHide report window
EditSaveCancelDeleteDeleteBlock this userReport abusive commentHide report window