Java Annotations - Override
Annotaion @Override indicates that the method is going to be overridden by the method of the super class. If we used @Override and does not override by the super class gives compilation error. The following example demonustrate @Override.
Super Class:
package examples;
/**
*
* @author raghava
*/
public class SuperClass {
int add(int a,int b){
return a + b;
}
}
Sub Class
/**
* @author raghava
*/
public class SubClass extends SuperClass{
@Override
public int add(int a,int b){
return a + b;
}
}
Here @Override indicates the add method of the sub class is going to override by the super class.
If SuperClass does not contain the override method then the compiler gives the below error.
"method does not override or implement a method from a super type"
Categories
- ant (1)
- books (2)
- Design Patterns (4)
- eclipse (3)
- ecllipse plug-ins (2)
- EJB (2)
- EJB Interview questions (1)
- exam simulator (1)
- groovy (2)
- hibernate (4)
- hibernate books (1)
- Hibernate interview questions (1)
- interview questions (13)
- j2ee (2)
- j2ee books (1)
- java (18)
- java annotations (1)
- java books (1)
- java examples (11)
- java io (1)
- java script (1)
- java servlets (1)
- java tutorials (25)
- java videos (24)
- javaDoc (1)
- javaee (1)
- jquery (1)
- JSF (3)
- jsp (3)
- JSTL (1)
- junit (1)
- scjp 5 (3)
- scjp 6 (1)
- SCJP Books (1)
- SCJP Dumps (9)
- Servlets (1)
- Servlets and JSP Books (5)
- Slides (13)
- Springs (8)
- struts (2)
- struts 2 (1)
- Struts books (2)
- Sun Tech Days (2)
- threads (2)
Blog Archive
-
▼
2009
(196)
-
▼
June
(12)
- Java Annotations - @Override Example
- Overriding - Access Specifier can not be more rest...
- What is the difference between doGet() and doPost(...
- NavigableSet - pollFirst and pollLast example
- Java Concurrency Gotchas
- Read System Environment variables using JAVA
- Java 6 - NavigableSet -headSet and tailSet Example...
- JAVA Email Validation using Regex
- Creating a thread using Runnable interface - Examp...
- Creating a thread by extendingThread class - Exam...
- Implementing Singletonton Design Pattern using pri...
- Java Script Date difference in Days
-
►
May
(9)
- Difference between == and .equals()
- Checkstyle development tool for Java
- Difference between Vector and ArrayList
- Difference between HashMap and Hashtable
- Different ways of creating a Thread
- What is the difference between an Interface and an...
- Generics Tutorial
- Manning - JUnit in Action
- JAutodoc - Eclipse Plugin for automatic adding Jav...
-
►
March
(46)
- SCJP 5 Exam Simulator - Full Version - Free downlo...
- Difference between SCJP 5 and SCJP 6
- 10 Commandments for Java Developers
- Beginners Java Tutorials – Programming
- Some Rules for Safer Java Programming
- Java Programming Examples
- Hibernate Relational Mapping
- Hibernate Step by Step
- Introduction to Spring 2.5
- Real Life Groovy
- Spring and EJB Transaction strategies
- JSP Tutorial
- Struts2
- EJB Interview Questions
- Java Reflection Explained Simply
- Clean Code
- Array Initialization - Simple Question
- Polymorphism
- Under what situations do you obtain a default cons...
- What does the zeroth element of the string array p...
- Correct declaration for a main() method
- What is the correct ordering for the import, class...
- JSP Basics
- Servlet Basics
-
▼
June
(12)
Saturday, June 27, 2009
Java Annotations - @Override Example
Posted by
raghava
at
Saturday, June 27, 2009
0
comments
Links to this post
Labels: java, java annotations, java examples
Wednesday, June 24, 2009
Overriding - Access Specifier can not be more restrictive
When we are overiding methods, we need to follow some rules. While overriding the access specifier can not be more restrictive.
The following are the allowed access specifiers when we are overriding.
Super class - Sub Class
---------------------------------------------------------
protected - protected,default and public
default - default and public
public - public
Posted by
raghava
at
Wednesday, June 24, 2009
0
comments
Links to this post
Labels: java
Saturday, June 20, 2009
What is the difference between doGet() and doPost() methods?
- In doGet (), the parameters are appended to the URL and sent along with header information. In doPost() parameters are sent in separate line in the body
- In doGet (), parameters are not encrypted but in doPost () parameters are not encrypted.
- doGet() is faster compared to doPost()
- doGet should be idempotent. i.e. doGet () should be able to be repeated safely many times. doPost method does not need to be idempotent. Operations requested through POST can have side effects for which the user can be held accountable.
- The amount of data which we send is limited in doGet () where as in doPost () it is not limited. In doGet (), maximum size of data that can be sent is 240 bytes. In doPost () there is no maximum size of data
Posted by
raghava
at
Saturday, June 20, 2009
0
comments
Links to this post
Labels: interview questions, java, java servlets
Friday, June 19, 2009
NavigableSet - pollFirst and pollLast example
pollFirst(), pollLast() methods of NavigableSet can be used to remove first and last element of the Set respectively. The below program explains the pollFirst() and pollLast()
package examples;
import java.util.NavigableSet;
import java.util.TreeSet;
/**
*
* @author Net4JAVA
*/
public class NavigableSetExample {
public static void main(String args[]){
NavigableSet
navigableSet.add(1);
navigableSet.add(2);
System.out.println("Set : " + navigableSet);
navigableSet.pollFirst();
System.out.println("Set After pollFirst " + navigableSet);
navigableSet.add(3);
navigableSet.add(4);
System.out.println("Set " + navigableSet);
navigableSet.pollLast();
System.out.println("Set after pollLast " +navigableSet);
}
}
output:
Set : [1, 2]
Set After pollFirst [2]
Set [2, 3, 4]
Set after pollLast [2, 3]
Posted by
raghava
at
Friday, June 19, 2009
0
comments
Links to this post
Labels: java, java examples