java

  • 28
    Jun

    Proxy design pattern with Java Reflection

    The two important tasks of proxy are interface implementation and delegation. Interface implementation means the proxy class need to implement all the interfaces the target class implements, and delegation...

    Read More
  • 26
    Jun

    Java Reflection – checking if a field is public / private or protected

    Class cls = Class.forName(“JavaReflectionExamples.BaseClass”); Field f = cls.getDeclaredField(fieldName); System.out.println(Modifier.toString(f.getModifiers())); Output: Public, if field is public Pls. note using .isAccessible() returns the value of the object’s accessible flag AccessibleObject sampleField...

    Read More
  • 26
    Jun

    Java Reflection – working with class, methods, superclass and much more

    Java Reflection provides ability to inspect and modify the runtime behavior of application. Reflection in Java is one of the advance topic of core java. Using java reflection we...

    Read More
  • 25
    Jun

    Execute a constructor with Java Reflection APIs

    Invoke constructor and other methods via JavaReflection Step 1: Create a class with constructor / methods: =================================================== package com.mypackage.bean; public class Dog { private String name; private int age;...

    Read More
  • 25
    Jun

    Execute a method with Java Reflection

    Following code snippet demonstrates “execute a method” with Java Reflections ============================================================================== Step 1: Create a class with methods/functions as follow ========================================================= package JReflection; public class Operations { public double...

    Read More
  • 25
    Jun

    Java tutorials on Reflection API – Oracle

    https://docs.oracle.com/javase/tutorial/reflect/index.html https://www.javaworld.com/article/2074753/object-hacking-in-java—power-of-reflection.html Applying Java reflection to Ioc and AOP (2) http://tutorials.jenkov.com/java-reflection/index.html Dynamic Proxies in Java

    Read More
  • 20
    Jun

    Starting standalone server with timeout settings

    Java property flags must be specified before the “-jar” command line option… java -Dwebdriver.server.session.timeout=7200 -jar selenium-server-standalone-2.44.0.jar Be aware that the timeout is in seconds. ========================================

    Read More
  • 12
    Jun

    Getter dependency for Cucumber scenarios with Picocontainer

    Step 1: Create Maven project with following POM.xml =================================================== UTF-8 UTF-8 1.8 1.8 4.2.6 3.141.59 6.5.1 io.cucumber cucumber-picocontainer 4.3.1 test org.testng testng ${testng.version} test io.cucumber cucumber-java ${cucumber.version} test io.cucumber...

    Read More
  • 12
    Jun

    Dependency injection with Guice

    Step 1: ======= public interface Discountable { double getDiscount(); } Step 2: Implement above interface =================================== public class EarlyBirdDiscount implements Discountable { @Override public double getDiscount() { return .25;...

    Read More
  • 11
    Jun

    Java code to checkout git code

    jars dependency: ================== jsch-0.1.42.jar org-eclipse-jgit.jar slf4j-api-1.7.26.jar slf4j-simple-1.7.26.jar Code snippet: ============== import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; public class abc { private static String...

    Read More