Tuesday, 30 August 2011
Tuesday, 23 August 2011
Monday, 22 August 2011
Exceptions
Exceptions and Errors in Java
To start with exceptions, we have to understand the difference between the Exceptions and Errors in java.
In Java, Error and Exception can be differentiated based on the program control. Error cannot be controlled by the programmer whereas Exceptions are those that can be guessed and also handled easily.
For example,
The OutOfMemory error that occurring due to large size of input is an error and it can be handled only by the system dynamically.
In other case, consider accessing an array value that is out of range can be guessed by the programmer and handled using ArrayOutOfBoundsException.
How to sort an ArrayList in Java???
As we know, ArrayList in Java is used to hold any type of data in an array. ArrayList can be sorted easily using the sort() that is defined in the Collections class. Since the method is static, we can call the sort method as follows:
Collections.sort();
For e.g.
ArrayList<String> arr=new ArrayList<String>;
Collections.sort(arr);
Collections.sort();
For e.g.
ArrayList<String> arr=new ArrayList<String>;
Collections.sort(arr);
Thursday, 18 August 2011
Wednesday, 17 August 2011
Tuesday, 16 August 2011
Wednesday, 10 August 2011
Things Learnt from given Assignment
StringTokenizer and StringBuffer
StringTokenizer is in java.util package which is used to separate the given string into individual tokens. The difference here is that
StringBuffer is also in java.util package. It differs from the String by its mutable character. That is, the string's length and content stored in it can be changed in course of time.
ArrayList
ArrayList in java.util package which is advantageous because of its capability to store any kind of object. It is similar to array but the difference comes when efficiency(in storing the contents) is required.
StringTokenizer is in java.util package which is used to separate the given string into individual tokens. The difference here is that
StringTokenizer methods do not distinguish among identifiers, numbers, and quoted strings. Also they wont recognize and skip comments. That is, it even takes the commented lines in your program also String.StringBuffer is also in java.util package. It differs from the String by its mutable character. That is, the string's length and content stored in it can be changed in course of time.
ArrayList
ArrayList in java.util package which is advantageous because of its capability to store any kind of object. It is similar to array but the difference comes when efficiency(in storing the contents) is required.
Monday, 1 August 2011
Interface in Java
What is Interface in Java?
In laymen term, Interface can be said as a medium that serves to connect two or more unrelated entities. For example, keyboard is an interface between you and the computer. Telephone cables are interface between two people speaking over phone. The Language English is another easy example for an interface which is a universal communicating language.
Now considering with respect to Java, an interface is a group of related methods with empty bodies.
Why Interface?
It is something that is more useful Multiple inheritance comes into picture as JAVA does not support multiple inheritance.
Syntax for Interface:
interface ICalculator
In laymen term, Interface can be said as a medium that serves to connect two or more unrelated entities. For example, keyboard is an interface between you and the computer. Telephone cables are interface between two people speaking over phone. The Language English is another easy example for an interface which is a universal communicating language.
Now considering with respect to Java, an interface is a group of related methods with empty bodies.
Why Interface?
It is something that is more useful Multiple inheritance comes into picture as JAVA does not support multiple inheritance.
Syntax for Interface:
interface ICalculator
- here interface is the keyword
- ICalculator is the name of the interface. Here Calculator is the Interface name and letter 'I' is added for easy understanding of the programmer that it is an interface.
- It is not mandatory to have letter 'I' as starting letter.
A class must have the following syntax to make use of that particular interface as below.
class Classname implements ICalculator
class Classname implements ICalculator
- Here implements is the keyword
- ICalculator is the interface name
- Classname is the class that implementing that interface
Subscribe to:
Posts (Atom)