Showing posts with label jre. Show all posts
Showing posts with label jre. Show all posts

Tuesday, 7 December 2021

Check whether I have JDK or JRE in my system

JRE vs JDK

JRE is implementation of Java Virtual Machine, Which actually executes Java Programs. JDK is a bundle of software used to develop Java Applications.

 

Usually, when you only care about running Java programs on your browser or computer you will only install JRE. It's all you need. On the other hand, if you are planning to do some Java programming, you will also need JDK.

 


 

To confirm the JDK

Execute the command ‘javac -version’.

$javac -version
javac 1.8.0_251

If you got the java compiler version details, then JDK is installed in your system.

 

To confirm the JRE

If javac command failed to get the compiler version, execute the command ‘java -version’.

$java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

If you got the java runtime environment details, then JRE is installed in your system. If this command failed, then either Java path is not set properly or Java is not installed in your system.



You may like

Interview Questions

Why do we declare logger with static and final?

How to check the type of a variable in Java?

Set a system property in command line

How to get the capacity of ArrayList in Java?

volatile reference vs Atomic references defined in java.util.concurrent.atomic package

Thursday, 1 July 2021

Junit5: @EnabledForJreRange, @DisabledForJreRange: Enable or disable based on Jre

@EnabledForJreRange: Enable test method or test class for a specific range of Java Runtime Environment versions. When applied at the class level, all test methods within that class will be enabled on the same specified JRE versions.

 

@DisabledForJreRange: Disable test method or test class for a specific range of Java Runtime Environment versions. When applied at the class level, all test methods within that class will be enabled on the same specified JRE versions.

 

Example

@DisabledForJreRange(min = JAVA_9, max = JAVA_11)
void notFromJava9to11() {

}

 

Find the below working application.

 

JRESpecificRangeTests.java

 

package com.sample.app;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.condition.JRE.JAVA_11;
import static org.junit.jupiter.api.condition.JRE.JAVA_9;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.EnabledForJreRange;

public class JRESpecificRangeTests {

  @Test
  @EnabledForJreRange(min = JAVA_9, max = JAVA_11)
  void fromJava9to11() {
    assertTrue(true);
  }

  @Test
  @EnabledForJreRange(min = JAVA_9)
  void fromJava9toCurrentJavaFeatureNumber() {
    assertTrue(true);
  }

  @Test
  @EnabledForJreRange(max = JAVA_11)
  void fromJava8To11() {
    assertTrue(true);
  }

  @Test
  @DisabledForJreRange(min = JAVA_9, max = JAVA_11)
  void notFromJava9to11() {
    assertTrue(true);
  }

  @Test
  @DisabledForJreRange(min = JAVA_9)
  void notFromJava9toCurrentJavaFeatureNumber() {
    assertTrue(true);
  }

  @Test
  @DisabledForJreRange(max = JAVA_11)
  void notFromJava8to11() {
    assertTrue(true);
  }
}

When I ran the test class on Java8, following test methods skipped.

a.   notFromJava8to11

b.   fromJava9toCurrentJavaFeatureNumber

c.    fromJava9to11

 


 

 

Previous                                                    Next                                                    Home

Junit5: @EnabledOnJre, @DisabledOnJre : Execute test cases based on jre version

@EnabledOnJre and @DisabledOnJre annotations are used to enable or disable test methods.

 

Example 1: Enable test only on JAVA_8

@Test
@EnabledOnJre(JAVA_8)
void onlyOnJava8() {
  assertTrue(true);
}

 

Example 2: Enable test on JAVA_8 or JAVA_9 or JAVA_10

@Test
@EnabledOnJre({ JAVA_8, JAVA_9, JAVA_10 })
void onJava8or9Or10() {
  assertTrue(true);
}

 

Example 3: Disable test on JAVA_8

@Test
@DisabledOnJre(JAVA_8)
void notOnJava8() {
  assertTrue(true);
}

 

JRESpecificTests.java

package com.sample.app;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.EnabledOnJre;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.condition.JRE.*;

public class JRESpecificTests {
  @Test
  @EnabledOnJre(JAVA_8)
  void onlyOnJava8() {
    assertTrue(true);
  }

  @Test
  @EnabledOnJre({ JAVA_8, JAVA_9, JAVA_10 })
  void onJava8or9Or10() {
    assertTrue(true);
  }

  @Test
  @DisabledOnJre(JAVA_8)
  void notOnJava8() {
    assertTrue(true);
  }
}

 

Run above test class, you can observe test methods may execute or skipped depends on your JRE version.

 

When I ran the test method on Jdk 1.8, ‘notOnJava8’ method is skipped.

 


 

 

 

Previous                                                    Next                                                    Home