Monday, September 9, 2013

HOW JAVA IS PLATFORM INDEPENDENT

HOW JAVA IS PLATFORM INDEPENDENT ?

The developers of java have made compilers and java virtual machines(also known as JVM). The function of compiler is to convert the program written by the programmer in the syntax of java into byte-code. Though the programmers don't have to do anything with the byte-codes so produced by the compilers, but for the sake of general knowledge, the programmer must know that it is the compilers which are platform dependent. You must have noticed while downloading java-sdk kit from the oracle website. The website provides different kinds of compilers for different platforms such as windows, LINUX, UNIX, Machintosh. So, this means java developers bore this extra responsibility of writing different compilers for different platforms, so that you can both write and run a java program on any platform. All you need to worry about is just learning the syntax of java. 

2nd PHASE AFTER BYTE-CODE FORMATION

When compilers perform their part of converting a program written in java to the byte-code, then this byte-code is fed to JVM(Java Virtual Machine) whose function is work on the byte-code and to convert it into such a form which can be understood by the computer hardware or the underlying machine. This form is referred as machine language. Java developers also take care to develop different JVM for different machines. So that your program written in java could run on any hardware. Your computer manufacturer could be any company such as Sony, Samsung, Lenovo, ASUS, etc. So there are JVMs available for all different machines.
The appropriate compilers and JVMs makes life easier for the programmers who write code in java and want their code to run everywhere irrespective of different platforms.
These striking features of java made the founders of java to raise the slogan :
                   "Write once run anywhere"

Friday, September 6, 2013

ACCESS MODIFIERS IN JAVA

WHAT ARE ACCESS MODIFIERS IN JAVA ?

Access modifiers are the special keywords which when applied provide different types of access to the content of the class. By content I mean, the data members/ fields and methods defined in the class. There might come situations where we don't want other classes to access the fields or methods or the class and some situations where we want all the elements of the class to be accessed by any other class.
Therefore, to provide different kinds of access for different kind of situations, Java has Access Modifiers, there are 3 kind of Access Modifiers :
1. public
2. private
3. protected

WHEN 'public' ACCESS MODIFIER IS USED :





DIFFERENCE BETWEEN METHOD OVERRIDING AND METHOD HIDING

METHOD OVERRIDING

When an instance method is written again with the same name, same number and type of parameters and same return type, in the sub-class as that of the parent-class/super-class, then this phenomenon is called as method overriding.

METHOD HIDING

It occurs in case of class-methods( also popularly known as static methods ). When any static-method is written again with the same name, same number and type of parameters and same return type, in the sub-class as that of the parent / super-class, then this phenomenon is called as method hiding.


Thursday, September 5, 2013

INTRODUCTION TO INHERITANCE IN JAVA

INHERITANCE

The concept of inheritance much more similar as in the real world itself. Inheritance means the passing of similar traits and features from older ones to younger ones. This same concept is taken from the real life and applied in the object oriented principles of programming languages too.
Necessity is the mother of invention fits better here, as in the earlier days of programming when there was no inheritance at all, programmers have to rewrite whole of the complex methods again and again which they wrote earlier in some other programme. They felt very exhausted writing these common but complex methods again and again whenever they have to write new code. They started to think of ways :
1. what if they introduce some way , by which they could be able to use previously written methods from previously written codes.
2. what if they find a solution to introduce a link among different piece of codes.
These necessities gave birth to the concept of inheritance.
With the advent of inheritance , the above problems found solutions. Now, if some code has to re-use the previously written methods and fields in some other code, it just inherits all of them by just writing a keyword 'extends'.

The programming life has become much easier with the introduction of inheritance. Java allows only single inheritance, though some other programming languages allow multiple inheritance too(e.g. C++ ).

Single inheritance

when a class can inherit only one other class i.e. having only one parent class. This kind inheritance is called Single inheritance.

Multiple inheritance

when a class inherits more than one class i.e. having multiple parent classes. This kind of inheritance is calles Multiple inheritance.

e.g.

public class Vehicle {
int numOfWheels;
int topSpeed;
int engineCapacity;
int gears;
void shiftGear(int gear) {
/ / / / /
/ / /
}
void speedUpBy(int mark){
/ / / / /
 / / /
}
}

public class Motorbike extends Vehicle{
int seats;
int mileage;
void start() {
/ / / /
/ / /
}
void stop() {
/ / / /
/ / /
}
}

We can clearly see in above example, that Motorbike class extends Vehicle class in its first statement, by doing this, the Motorbike class is able to inherit all the features of Vehicle class, without having it to write all those methods again. This is how inheritance makes the coding easier than before.
Here the Motorbike class is called subclass. 
The Vehicle class is called superclass.


SUB-CLASS

The class that is derived from the another class is called as sub-class (also called as child-class, derived class or extended class).

SUPER-CLASS

The class from which sub-class is derived is called as super-class ( also called as a base-class or a parent class ).


NOTE : there exist

DIFFERENCES AND SIMILARITIES BETWEEN INTERFACES AND ABSTRACT CLASSES

DIFFERENCES BETWEEN INTERFACES AND ABSTRACT CLASSES

Here I have compiled the points of both interfaces and abstract classes, and presented them in the image form . So, that anybody can save it and make it as his/her wallpaper, which enables to see it regularly and revise it.


Wednesday, September 4, 2013

SOLVING ANY PROBLEM FROM THE OBJECT ORIENTED POINT OF VIEW

 Objective: Analysis of the following Case Study from the perspective of Object Oriented Approach


Problem Description: Course Registration System



A Course Registration System needs to be developed for an engineering college. The college wants an automated system to replace its manual system for the purpose of registration of students to branches and calculation of fees for each year. The engineering college provides graduation courses in various branches of engineering.
The system will be used by the admin staff to register students, admitted to the college to the branches, at the time of joining the college and also to calculate the yearly fees for the students. The student has to register every year for the next academic year. The Admin takes care of the yearly registration of the students and the calculation of yearly fees. The system needs to be authenticated with a login id and password.
Registration of a student to a branch is based on the qualifying exam marks and the entrance counseling. For every branch, a yearly branch fee is applicable. Discounts are given to the branch fees of the first year based on the qualifying exam marks. In addition to this, there is a registration fee which is applicable to the first year students. Students can opt to be a day scholar or hostelite. Annual bus fee is applicable to the day scholars based on the distance they travel. Annual hostel fee is applicable for all the hostelites. Annual infrastructure fees and library fee is also applicable to all the students. Admin calculates the yearly college fees for each student and the college fees include all the fees specified earlier based on the type of student. Admin will provide a printed receipt of the fees to the students once the annual college fees have been paid. At the time of registration, student has to provide the permanent address and in case the student is opting to be a day scholar, he/she has to provide the residential address also.

SOLUTION :

Now, after thorough reading the above problem, we need to extract some crucial points, without writing them into sentences again, because those points will take us closer to the object oriented design phase. 
Lets get started :

Step 1 :
First of all we need to extract the purpose from the whole description  given above in just few points, as it will enable us to have a clear cut target. So the purpose of above long description is as follows :

1.  Registration of the students to the available branches.
2. Calculation of annual fees.


Step 2 :
Since, we are seeing the problem from the object oriented point of view, therefore, we need to make out what kind of actors / entities / objects are involved in our problem.

The whole problem revolves around one important object and i.e. 'Student'.

So, 'Student' can be seen as an actor or entity  or an object .

Tuesday, September 3, 2013

TOPIC 3 : INTRODUCTION TO DATA STRUCTURES

3.1 Data structures - Stack

Assignment 3.1.1: Application of Stack Data Structure


Objective: To understand how to apply Stack Data Structure.


Problem Description: Write a pseudo code to find the binary value of a given integer and 
display it.
Hint: Consider the integer 5. To convert 5 to binary, the following procedure needs to be 
adopted.



               2|_5____

               2|_2_-_1_

                   _1__- 0_





Each time, store the remainder in an appropriate data structure and use LIFO to get the 

binary value.