Sample code for 30+ languages & platforms
Java

Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem

See more OpenSSL Examples

How to output the public part of a private key: Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkPrivateKey pkey = new CkPrivateKey();

    // Load the private key from an PEM file:
    success = pkey.LoadPemFile("private.pem");
    if (success == false) {
        System.out.println(pkey.lastErrorText());
        return;
        }

    CkPublicKey pubKey = new CkPublicKey();
    pkey.ToPublicKey(pubKey);

    success = pubKey.SavePemFile(false,"pubKey.pem");
    if (success != true) {
        System.out.println(pubKey.lastErrorText());

        return;
        }

    System.out.println("Success.");
  }
}