COBOL-to-Java Converter and Conversion Tool: Code Examples

SoftwareMining's automated, rule-based COBOL-to-Java converter and conversion tool supports complete application conversion, including COBOL business logic, data structures, and supported CICS, IMS, DB2, VSAM, and JCL dependencies. Generated applications use standard Java project structures together with SoftwareMining runtime libraries where required, and can be maintained using established Java development tools and integrated with existing build, CI/CD, testing, and monitoring processes.

Depending on the target architecture, converted applications can integrate with JDBC, Java application servers (such as Tomcat or WebLogic), JUnit, standard logging frameworks, and enterprise messaging services. Review the complete COBOL-to-Java conversion features and platform support (or view our COBOL-to-C# and .NET code examples ).

What to Expect from COBOL-to-Java Conversion

Rather than relying on probabilistic generative AI models, SoftwareMining's COBOL-to-Java converter utilizes a deterministic, rule-based engine to transform COBOL programs and copybooks into maintainable Java source code. The side-by-side example below shows how data definitions, business logic, and control flow are represented in the generated application.

This output was generated using SoftwareMining's COBOL-to-Java Conversion Tool and illustrates the translation for a single program. Complete applications should be validated against the original COBOL system using functional-equivalence testing .

Evaluate the COBOL-to-Java Converter Using Your Own Code

Source-code conversion is one component of mainframe modernization. A complete COBOL-to-Java migration also addresses application dependencies, files and databases, batch and online services, data migration, and target deployment. For detailed coverage of supported COBOL constructs and platform technologies, see the COBOL-to-Java Conversion Process and Features .

COBOL-to-Java: Side-by-Side Code Comparison

  PROGRAM-ID. LOAN.
  DATA DIVISION.
  FILE SECTION.

  WORKING-STORAGE SECTION.
  01  WS-DATA.
    05 PRINCIPAL          PIC 9(9) VALUE 0.
    05 INTEREST-RATE      PIC 99V99 VALUE 0.
    05 LOAN-LENGTH        PIC 99 VALUE 0.
    05 NEXT-INTEREST      PIC 99V99.
    05 NEXT-YEAR          PIC 99.
  01 CLIENT-RECORD.
    05 NAME               PIC X(20).
    05 ADDRESS            PIC X(20) OCCURS 3 TIMES.
    05 ID                 PIC 9(4) COMP.

  ...
// Sample COBOL to Java translated code

public class Loan extends BaseService  {
  
// Notes: 01 level WS-DATA name is simplified (Optional)
// and converted to a DAO
// The DAO handles REDEFINES, COMP, OCCURS-DEPENDING, ...
  
  private WsData data = new WsData(this);
  
// Client-RECORD has been translated to ClientRecord DAO,
// but since the program does not reference ClientRecord,
// it will automatically be commented out.
  
  
// private ClientRecord clientRecord = new ClientRecord(this);
  
  ...
  * Main entry point to program
   LOAN-MAIN-001.

  *  -
  * CLEAR SCREEN AND READ DATA
  *  -

       IF LOAN-LENGTH > 4 THEN
          COMPUTE START-YEAR = LOAN-LENGTH - 4
       ELSE
          COMPUTE START-YEAR = 0.

       IF INTEREST-RATE > 0.4 THEN
          COMPUTE START-INTEREST = INTEREST-RATE - 0.4
       ELSE
          COMPUTE START-INTEREST = 0
       END-IF

       MOVE 1 TO YEAR-ROW.

  *  -
  * GO THRU THE NUMBER OF YEARS
  *  -

       MOVE "% Rate->" TO DSP-NO-YRS(1).
       MOVE START-YEAR TO NEXT-YEAR
       PERFORM VARYING YEAR-ROW FROM 2 BY 1 UNTIL YEAR-ROW = 11
         PERFORM DO-NEXT-ROW
         ADD 1 TO NEXT-YEAR
       END-PERFORM.

  *  -
  *  AND EXIT
  *  -
       STOP RUN.
/**
 * Main entrance to program
 */
protected void loanMain () {
  //  -
  // CLEAR SCREEN AND READ DATA
  //  -
  if (data.getLoanLength() > 4) {
    data.setStartYear(data.getLoanLength() - 4);
  } else {
    data.setStartYear(0);
  }
  if (data.getInterestRate() > 0.4) {
    data.setStartInterest(data.getInterestRate() - 0.4);
  } else {
    data.setStartInterest(0.0);
  }
  data.setYearRow(1);

  //  -
  // GO THRU THE NUMBER OF YEARS
  //  -
  displayResult.setNoYrs(0, "% Rate->");
  data.setNextYear(data.getStartYear());
  // initialize loop variable
  data.setYearRow(2);
  while (data.getYearRow() != 11) {
    doNextRow();
    data.setNextYear(data.getNextYear() + 1);
    data.setYearRow(data.getYearRow() + 1);
  }

  //  -
  // AND EXIT
  //  -
  stop();
}
  *
  * Calculates values for individual rows
  *
   DO-NEXT-ROW.

       MOVE START-INTEREST TO NEXT-INTEREST

       PERFORM VARYING INTEREST-COL FROM 1 BY 1
         UNTIL INTEREST-COL = 10
         MOVE NEXT-INTEREST TO DSP-RESULT(1, INTEREST-COL)
         PERFORM CALCULATE
         MOVE NEXT-RESULT TO DSP-RESULT(YEAR-ROW, INTEREST-COL)
         ADD 0.1 TO NEXT-INTEREST
       END-PERFORM.
/**
 * Calculates values for individual rows
 */
protected void doNextRow () {
  data.setNextInterest(data.getStartInterest());

  data.setInterestCol(1);
  while (data.getInterestCol() != 10) {
    displayResult.setResult(
      0,
      data.getInterestCol() - 1,
      data.getNextInterest()
    );
    calculate();
    displayResult.setResult(
      data.getYearRow() - 1,
      data.getInterestCol() - 1,
      data.getNextResult()
    );
    data.setNextInterest(data.getNextInterest() + 0.1);
    data.setInterestCol(data.getInterestCol() + 1);
  }
}
  *
  * The next paragraph calculates CELL values
  *
   CALCULATE.
       COMPUTE INTDEC = NEXT-INTEREST / (12.0 * 100.0)
       COMPUTE NUMMONTHS = NEXT-YEAR * 12.0
       ...
/**
 * The next paragraph calculates CELL values
 */
protected void calculate () {
  data.setIntdec(data.getNextInterest() / (12.0 * 100.0));
  data.setNummonths((double) data.getNextYear() * 12.0);
  ...
}

COBOL-to-Java Converter & Conversion Tool vs. Basic Transpiler

A basic transpiler is a source-to-source compiler that converts one programming language into another. Simple mechanical transpilation tends to reproduce the original COBOL structure line-for-line, resulting in generated code that is difficult for Java developers to understand and maintain.

Rather than relying on probabilistic generative AI models or basic transpilers, SoftwareMining's COBOL-to-Java conversion engine analyses COBOL data definitions, business logic, and control flow, restructures complex procedural constructs, identifies unreferenced code, and generates clean, standard Java classes, methods, and data-access components. The examples on this page demonstrate the resulting readability and modern architecture.

COBOL features without direct Java equivalents—including pointers, packed decimals, PICTURE formats, REDEFINES, OCCURS DEPENDING ON, and fixed-length record layouts—are handled automatically through generated structures and SoftwareMining runtime libraries. This keeps compatibility support cleanly separated from your core business logic.

Key COBOL-to-Java Conversion Features

  1. COBOL data structures: 01-level declarations are converted into reusable Java classes while preserving REDEFINES, computational fields, and OCCURS DEPENDING ON clauses.
  2. Data-access classes: FILE SECTION records and WORKING-STORAGE areas utilized by CICS file operations are converted into generated DAO or ORM classes.
  3. Reduced generated-code clutter: Unreferenced declarations are retained as comments, unused DAO references are omitted, and shared data structures are reused wherever possible.
  4. Structured control flow: Legacy GO TO logic is converted into structured IF, switch, and loop constructs where practical. Irreducible paths utilize controlled patterns supported by SoftwareMining runtime libraries.
  5. Batch and online deployment: Batch programs execute cleanly from the command line or enterprise job schedulers, with supported JCL converted into Unix shell scripts or Windows batch files . Online applications run on Java application servers such as Apache Tomcat, Jakarta EE servers, or Spring-based environments and integrate smoothly with standard database, messaging, and security services.


Download Converter | Free Evaluation