An iframe (which is shirt for inline frame) is an HTML element which allows an external webpage to be embedded inside an HTML document. Unlike traditional frames, which were used in order to create the structure of a webpage, iframes may be inserted anywhere in a webpage layout.

An inframe may be inserted inside a HTML document using the iframe tag, an example of this is shown below:

<iframe src="http://sharpened.com/example.php" width="728" height="90"></iframe>

The code above would insert the contents of the URL into a 728 x 90 px inline frame inside the webpage. The iframe source (src) is able to reference an external website or another page on the same server, such as src=”/example.php”. The width and height attributes aren’t required, but they are commonly utilized to define the size of the iframe. Other iframe attributes, for instance, marginwidth and marginheight are indeed supported in HTML 4 and earlier, however in HTML 5, CSS is utilized in order to customize the appearance of a certain iframe.

Iframes are used for a multiple of different purposes, for example, online advertising and multimedia. Many ad platforms use iframes in order to display ads on webpages due to the fact they provide more flexibility than an inline script. As iframes may contain an entire webpage, advertisers are able to include extra tracking code inside an iframe that helps make sure accurate reporting for advertiser as well as the publisher.

Iframes are also used for the purpose of displaying types of media inside a webpage. For instance, YouTube videos as well Google Maps windows are often embedded in web pages using iframes. Many web applications use iframes due to the fact they are able to display dynamic content without the need to reload the webpage.

Reflection SandBoxing

https://www.geeksforgeeks.org/reflection-in-java/

Reflection is an API that is used in order to modify or examine the behaviour of methods, classes, interfaces at runtime.

  • The required classes for reflection are given under java.lang.reflect package.
  • Reflection provides us information regarding the class to which an object belongs as well as the methods of that particular class which may be executed via using the object.
  • Through reflection we are able to invoke methods at run time regardless of the access specifier utilized with them.

Reflection may be used to get data about:

  1. Class – The getClass() method is used in order to get the name of the class to which an object belongs. 
  2. Constructors – The get Constructors() method is utilized in order to get the public constructors of the class to which an object belongs too.
  3. Methods – The getMethods() method is used in order to get the public methods of the class to which an object belongs too.
// A simple Java program to demonstrate the use of reflection 
import java.lang.reflect.Method; 
import java.lang.reflect.Field; 
import java.lang.reflect.Constructor;   

// class whose object is to be created 
class Test 
{ 
    // creating a private field 
    private String s; 
  
    // creating a public constructor 
    public Test()  { s = "sourcedefense"; }  
    
    // Creating a public method with no arguments 
    public void method1()  { 
        System.out.println("The string is " + s); 
    }   

    // Creating a public method with int as argument 
    public void method2(int n)  { 
        System.out.println("The number is " + n); 
    } 

    // creating a private method 
    private void method3() { 
        System.out.println("Private method invoked"); 
    } 
} 
  
class Demo 
{ 
    public static void main(String args[]) throws Exception 
    { 
        // Creating object whose property is to be checked 
        Test obj = new Test(); 
  
        // Creating class object from the object using 
        // getclass method 
        Class cls = obj.getClass(); 
        System.out.println("The name of class is " + cls.getName()); 
 
        // Getting the constructor of the class through the 
        // object of the class 
        Constructor constructor = cls.getConstructor(); 
        System.out.println("The name of constructor is " +  constructor.getName()); 
        System.out.println("The public methods of class are : "); 

        // Getting methods of the class through the object 
        // of the class by using getMethods 
        Method[] methods = cls.getMethods();  

        // Printing method names 
        for (Method method:methods) 
            System.out.println(method.getName());   

        // creates object of desired method by providing the 
        // method name and parameter class as arguments to 
        // the getDeclaredMethod 
        Method methodcall1 = cls.getDeclaredMethod("method2", int.class); 
 
        // invokes the method at runtime 
        methodcall1.invoke(obj, 19); 
  
        // creates object of the desired field by providing 
        // the name of field as argument to the  
        // getDeclaredField method 
        Field field = cls.getDeclaredField("s");   

        // allows the object to access the field irrespective 
        // of the access specifier used with the field 
        field.setAccessible(true); 
  
        // takes object and the new value to be assigned 
        // to the field as arguments 
        field.set(obj, "JAVA");  

        // Creates object of desired method by providing the 
        // method name as argument to the getDeclaredMethod 
        Method methodcall2 = cls.getDeclaredMethod("method1"); 
  
        // invokes the method at runtime 
        methodcall2.invoke(obj); 
  
        // Creates object of the desired method by providing 
        // the name of method as argument to the  
        // getDeclaredMethod method 
        Method methodcall3 = cls.getDeclaredMethod("method3");   

        // allows the object to access the method irrespective  
        // of the access specifier used with the method 
        methodcall3.setAccessible(true); 
  
        // invokes the method at runtime 
        methodcall3.invoke(obj); 
    } 
}
Output :
The name of class is Test
The name of constructor is Test
The public methods of class are : 
method2
method1
wait
wait
wait
equals
toString
hashCode
getClass
notify
notifyAll
The number is 19
The string is JAVA
Private method invoked

Critical observations:

  • We can invoke a method via reflection if we know its name as well as its parameter types. We use two methods displayed below for this very purpose.
  • getDeclaredMethod() : To create an object of method to called upon. The syntax for this method is represented by the following: 
  • getDeclaredMethod() : To create an object of method to be invoked. The syntax for this method is:
  • Class.getDeclaredMethod(name, parametertype)
  • name- the name of method whose object is to be created
  • parametertype – parameter is an array of Class objects
  • Invoke () : To call upon a method of class at runtime we use the following method below:
  • Method.invoke(Object, parameter)
  • If the method of the class doesn’t accepts any 
  • parameter then null is passed as argument.

Through the use of reflection we are able to access the private variables and methods of a class with the assistance of its class object and invoke the method by utilizing the object as mentioned above. We can use the two methods below for this very purpose:

Class.getDeclaredField(FieldName) : Used to get the private field. Returns an object of type Field for specified field name.

Field.setAccessible(true) : Allows to access the field irrespective of the access modifier used with the field.

Advantages:

  1. Extensibility features: An application may make use of external, user-defined classes by creating examples of extensibility objects via the use of their fully-qualified names.
  2. Debugging and testing tools: Debuggers utilize the property of reflection in order to examine private members on classes.

Disadvantages:

  1. Performance Overhead: Reflective operations have slower performance than their non-reflective counterparts which, therefore, should be avoided in sections of code that are called often in performance-sensitive applications.
  2. Exposure of Internals: Reflective code breaks abstractions and consequently may change behavior with upgrades of the platform.