0% found this document useful (0 votes)
51 views8 pages

"Annotations": SJB Institute of Technology

The document discusses Java annotations. It describes the 7 built-in Java annotations, including @Override, @SuppressWarnings, and @Deprecated. It provides examples of using these annotations, such as overriding a method and suppressing deprecation warnings. The presentation aims to explain how built-in Java annotations work and how they can be used in code.

Uploaded by

sridhar naik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views8 pages

"Annotations": SJB Institute of Technology

The document discusses Java annotations. It describes the 7 built-in Java annotations, including @Override, @SuppressWarnings, and @Deprecated. It provides examples of using these annotations, such as overriding a method and suppressing deprecation warnings. The presentation aims to explain how built-in Java annotations work and how they can be used in code.

Uploaded by

sridhar naik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SJB INSTITUTE OF TECHNOLOGY

Project Presentation
On

“Annotations”

By

UMESH M
Asst. Prof.

Department of Information Science and Engineering

10/22/2019 Dept of ISE, SJBIT 1


Annotations
• Built-In Java Annotations
– There are 7 built-in annotations in java. Some annotations are applied to
java code and some to other annotations.
• Built-In Java Annotations used in java code imported
from java.lang
1. @Override
2. @SuppressWarnings
3. @Deprecated
• Built-In Java Annotations used in other annotations
• 4 Annotations imported from java.lang.annotation
1. @Target
2. @Retention
3. @Inherited
4. @Documented

10/22/2019 Dept of ISE, SJBIT 2


class Animal
{
void eatSomething()
{ System.out.println("eating something"); }
}

class Dog extends Animal


{
void eatSomething( )
{ System.out.println("eating foods"); }
}

class TestAnnotation1{
public static void main(String args[ ])
{
Dog a=new Dog();
a.eatSomething();
}
}

10/22/2019 Dept of ISE, SJBIT 3


class Animal
{
void eatSomething()
{ System.out.println("eating something"); }
}

class Dog extends Animal


{
void eatsomething( ) //not overriding
{ System.out.println("eating foods"); }
}

class TestAnnotation1{
public static void main(String args[ ])
{
Dog a=new Dog();
a.eatSomething();
}
}

10/22/2019 Dept of ISE, SJBIT 4


@Override

class Animal
{
void eatSomething()
{ System.out.println("eating something"); }
}

class Dog extends Animal


{
@Override  
void eatsomething( )
{ System.out.println("eating foods"); }
}

class TestAnnotation1{
public static void main(String args[ ])
{
Dog a=new Dog();
a.eatSomething();
}
}
Output:Comple Time Error
10/22/2019 Dept of ISE, SJBIT 5
@Deprecated

class A{  
void m( )
{ System.out.println("hello m") ;}  
  
@Deprecated  
void n( )
{ System.out.println("hello n");}  
}  
  
class TestAnnotation3{  
public static void main(String args[ ])
{  
A a=new A();  
a.n();  
}
}  
At Compile Time:
Note: Test.java uses or overrides a deprecated API.
At Runtime:
hello n
10/22/2019 Dept of ISE, SJBIT 6
@SuppressWarnings
class DeprecatedTest
{
    @Deprecated
    public void Display()
    {
        System.out.println("Deprecatedtest display()");
    }
}
 public class SuppressWarningTest
{
    // If we comment below annotation, program generates
    // warning
    @SuppressWarnings("deprecation")
    public static void main(String args[])
    {
        DeprecatedTest d1 = new DeprecatedTest();
        d1.Display();
    }
}
10/22/2019 Dept of ISE, SJBIT 7
10/22/2019 Dept of ISE, SJBIT 8

You might also like