Posts

Showing posts from December, 2020

getMethods and getDeclaredMethods in java

getMethods() and getDeclaredMethods() in java Program : import java.lang.reflect.*; class A { public void show_Of_A() { } public void display_Of_A() { } } class B { public void show_Of_B() { } public void display_Of_B() { } } class Test { public static void main(String args[]) throws Exception { Class cc = Class.forName("A"); Method meth[] = cc.getMethods(); for(Method m:meth) { System.out.println(m); } } } Output :    public void A.show_Of_A() public void A.display_Of_A() public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException public final void java.lang.Object.wait() throws java.lang.InterruptedException public boolean java.lang.Object.equals(java.lang.Object) public java.lang.String java.lang.Object.toString() public native int java.lang.Object.hashCode() public final native java.lang.Class java.lang.Object.getClass() public final native void java.lang...

Reflections in Java

Image
Reflections in Java Reflection enables Java code to discover information about the fields, methods and constructors of loaded classes, and to use reflected fields, methods, and constructors to operate on their underlying counterparts, within security restrictions. The API accommodates applications that need access to either the public members of a target object (based on its runtime class) or the members declared by a given class. It also allows programs to suppress default reflective access control. (Source : Oracle) Our First Program for understanding reflections in Java 1. For using reflections we have to import package names java.lang.reflect  import java.lang.reflect.*; abstract class A { } class DesiExplanation { public static void main(String ar[]) { Class cc=A.class; System.out.println(Modifier.isAbstract(cc.getModifiers())); } } Fun Fact : Java means cup of tea but it isn't everyone's cup of tea ~ Krishan Kumar