The Java Sampler is a powerful means of testing just about anything. The big advantages are that variables can be taken from the JMeter script (such as thread number, or user name, or whatever you want) and that results can contain a specific error code as well as custom messages and data – more importantly, you can control when the timer for the test starts and finishes.
Testing the API or Website using JMeter is quite easy, but if you have to load the java class directly, you may be in a situation. This post described how to test the loading of a java class. We'll write a java program and load it with JMeter Java Sampler.
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>3.0</version>
</dependency>