The Artima Developer Community
Sponsored Link

Java Buzz Forum
What is Java Reflection API | Java Reflection | Reflection in java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ram N

Posts: 2777
Nickname: ramram
Registered: Jul, 2014

Ram N is Java Programmer
What is Java Reflection API | Java Reflection | Reflection in java Posted: Oct 23, 2017 11:19 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ram N.
Original Post: What is Java Reflection API | Java Reflection | Reflection in java
Feed Title: JAVA EE
Feed URL: http://ramj2ee.blogspot.com/feeds/posts/default?alt=rss
Feed Description: This blog has viedo tutorials and Sample codes related to below Technologies. 1.J2EE 2.Java 3.Spring 4.Hibernate 5.Database 6.Oracle 7.Mysql 8.Design Patterns
Latest Java Buzz Posts
Latest Java Buzz Posts by Ram N
Latest Posts From JAVA EE

Advertisement

Click here to watch in Youtube :
https://www.youtube.com/watch?v=IjgnkMgkRVg&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
What is Java Reflection API | Java Reflection | Reflection in java
Student.java
public class Student
{
private String name;
private int age;

public Student(String name, int age)
{
super();
this.name = name;
this.age = age;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public int getAge()
{
return age;
}

public void setAge(int age)
{
this.age = age;
}

}
ReflectionDemo.java
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectionDemo
{
public static void main(String[] args)
{
Student student = new Student("Peter", 25);

/*
* Returns: The Class object that represents the runtime class
* of this object.
*
*/

Class<? extends Student> studentClass = student.getClass();

/*
* Returns: the array of Method objects representing the
* public methods of this class
*/

Method[] methodArray = studentClass.getMethods();

for (Method method : methodArray)
{
System.out.println(method.getName());
}

System.out.println("----------------------------------");

/*
* Returns:the array of Field objects representing all the
* declared fields of this class
*/

Field[] fieldArray = studentClass.getDeclaredFields();

for (Field field : fieldArray)
{
System.out.println(field.getName());
}

}

}
Output
getName
setName
getAge
setAge
wait
wait
wait
equals
toString
hashCode
getClass
notify
notifyAll
----------------------------------
name
age

Refer:
https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html

https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/package-summary.html

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/ReflectionDemo_Intro.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ReflectionDemo_Intro

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/921a65d57c0ec8a07d5edae78f1552619b89e108/BasicJava/ReflectionDemo_Intro/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Read: What is Java Reflection API | Java Reflection | Reflection in java

    Topic: AWS Certified SysOps Administrator – Associate Examination Previous Topic   Next Topic Topic: Enabling Two-Factor Authentication For Your Web Application

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use