Can anyone help comparing and contrasting between Java and cobol in terms of technical differences as well as architectural design styles
-
Man... where to start! This question is going to have a giant answer. – Kris Krause Jan 10 '10 at 02:14
-
@dragthor: How about ENVIRONMENT DIVISION? :) – t0mm13b Jan 10 '10 at 02:16
-
1Possible duplicate: http://stackoverflow.com/questions/2026857/porting-from-cobol-to-java – pavium Jan 10 '10 at 02:17
-
1+1 a huge potential for funny stuff – Itay Moav -Malimovka Jan 10 '10 at 02:53
-
Asked earlier today, apparently by the same person: http://stackoverflow.com/questions/2029397 (but slightly better worded this time) – kdgregory Jan 10 '10 at 03:00
-
+1 for a fun question .. if a bit of a troll :) – Larry Watanabe Jan 10 '10 at 03:05
6 Answers
Similarities
Cobol and Java were going to change the world and solve the problem of programming.
Neither lived up to the initial hype.
There are now very large, bloated Cobol and Java programs that are used by banks and are "legacy" ... too large and critical to rewrite or throw away.
Cobol introduce the idea of having long, readable names in their code. Java recommends long, readable names.
Differences
Cobol was invented by an American, Grace Murray Hopper, who received the highest award by the Department of Defense, the Defense Distinguished Service Medal.
Java was invented by a Canadian, James Gosling, who received Canada's highest civilian honor, an Officer of the Order of Canada.
3 COBOL convention uses a "-" to separate words in names, Java convention uses upper/lower CamelCase.

- 10,126
- 9
- 43
- 46
COBOL was popular for the simple reason, to develop business applications.
Since the syntax was so clear and human-like, written in procedural style, it was for that reason, that made adapting to the changes in the business environment much easier, for example, to assign a value of pi to a variable, and then subtract zero from it - simple example to show the actual COBOL statements/sentences (it is years since I last programmed in Cobol)
MOVE 3.14 INTO VARPI. SUBTRACT ZERO FROM VARPI GIVING VARPIRESULT. IF VARPIRESULT AND ZERO EQUALS VARPI THEN DISPLAY 'Ok'.
If I remember, the COBOL sentences have to be at column 30...
And it is that, hence easier to troubleshoot because any potential business logic error can be easily pin-pointed as a result. Not alone that, since COBOL ran on mainframe systems, it was for a reason, the data transfer from files were shifted at a speed that is light-years ahead of the other systems such as PC's and that is another reason why data processing in COBOL was blindingly fast.
I have worked on the Y2k stuff on the mainframe (IBM MVS/360) and it was incredible at the dawn of the 21st century, praying that the fixes I put in wouldn't bring the business applications to their knees...that was hype, aside from that..to this day, it is still used because of the serious transfer speed of data shuffling around within mainframes and ease of maintainability.
I know for starters, Java would not just be able to do that, has Java got a port available for these mainframes (IBM MVS/360, 390, AS400)?
Now, businesses cannot afford to dump COBOL as they would effectively be 'committing suicide' as that is where their business applications resides on, which is the reason why the upgrade, migration, porting to a different language is too expensive and would cause a serious headache in the world of businesses today...
Not alone that, imagine having to rewrite procedural code which are legacy code and could contain vital business logic, to take advantage of the OOP style of Java, the end result would be 'lost in translation' and requiring a lot of patience, stress and pressure.
Imagine, a healthcare system (I have worked for one, which ran on the system I mentioned above), was to ditch all their claims processing,billing etc (written in COBOL) to Java, along with the potential for glitches and not to mention, serious $$$ amount of money to invest which would cost the healthcare company itself far more, the end result would be chaos and loss of money, and customers (corporations that offer employee benefits) would end up dumping the company for a better one.
So to answer your question, I hope I have illustrated the differences - to summarize:
COBOL is:
- Procedural language
- Simple human like syntax
- very fast on mainframe systems
- Easy to maintain code due to syntax
In contrast,
Java is:
- Object Oriented
- Syntax can get complicated
- Requires a Java Virtual Machine to run and execute the compiled bytecode.
Hope this helps,

- 34,087
- 8
- 78
- 110
-
There is a project going on at this moment at my client's place where a decade old COBOL app running on a mainframe is being retired and replaced with a Java based alternative that was written in about 6 months simply because maintaining the mainframe is proving to be way too expensive. At first everybody was a little worried (and probably still are) at replacing a system that has "evolved" over many years into a humongous blob with God knows that logic and validations! But the new system seems to be showing promise. But you're right, we never heard of perf problems with the mainframe. – Raj Jan 10 '10 at 03:33
-
@Ranju V: Wow! Good luck with the migration strategy...Hope it all works out, that must have been a big risky business decision... fingers crossed..I would love it if you could post back here on how it goes and that would be invaluable for others to read up on... :) – t0mm13b Jan 10 '10 at 03:46
-
All of the IBM OS offerings have long had Java ports available to them. And IBM Enterprise Cobol interoperates nicely with Java through cross inheritance. I would disagree with you on the syntax though -- Cobol, with its 1,000-odd reserved words and context dependant grammar, has a very twisted and hard to deal with syntax, though it happens to be one that most English speakers kinda get. Java on the other hand, with its mere handful of reserved words and a context free grammar is beautifully terse. – Joe Zitzelberger Mar 28 '11 at 21:35
-
@Joe: Obviously you do not appreciate the fact that the syntax of COBOL is what is the underpinnings of enabling changes to business logic in a manner that is simplified and easier to understand... that's the point I was making... try explaining using java iterators and enumerators, generics to someone who has to make a change to the existing business logic - that's another reason why big companies cannot afford to ditch it as it *is* the backbone of their business! – t0mm13b Mar 28 '11 at 23:49
It is easier to point out what they have in common instead of listing their differences.
So here is the list:
- You can use both to make the computer do things
- They both get compiled to yet a different language (machine code, byte-code)
- That is it!

- 644
- 4
- 7
-
5
-
Differences: the language names don't share any letters. Does that help? – Ira Baxter Nov 03 '22 at 20:18
Similarities:
- Both extremely verbose and created with pointy-haired bosses, not programmers, in mind.
- Both used primarily for boring business software.
- Both have huge legacy and are going to be around a while.

- 67,514
- 53
- 213
- 334
-
Program -> Service; JCL -> XML; Copybooks -> Beans; and so on. I wonder how many Java programs end up being LONGER than equivalent COBOL programs (systems)? – Roboprog Apr 12 '19 at 02:07
Cobol is a pure procedural language, not even functions in it (I used cobol in the 90s, so it might have changed since).
Java is OO (Although I heared there is a OO version for Cobol too), Oh...And the syntax is different.
Excelent list of similarities and differences : http://www.jsrsys.com/jsrsys/s8383sra.htm
It'swhat we do! COBOL: COBOL Concept Description Java: Java/OO Similar Concept ++: What Java/OO adds to Concept When I began Java, I used to think the OO (Object Orientation) was "just like" good programming practices, except it was more formal, and the compiler enforced certain restrictions.
I no longer think that way. However, when you are beginning I think certain "is similar to" examples will help you grasp the concepts.
COBOL: Load Module/Program Java: Class
COBOL: PERFORM Java: method ++: can pass parameters to method, more like FUNCTION other programs/classes can call methods in different classes if declared public. public/private gives designer much control over what other classes can see inside a class.
COBOL: Working Storage, statically linked sub-routine Java: instance variables ++: (see next)
COBOL: Working Storge, dynamically loaded sub-routine Java: Class variables ++: Java can mix both Class variables (called static, just the reverse of our COBOL example, and instance variables (the default). Class variables (static) occur only once per Class (really in one JVM run-time environment). Instance variables are unique to each instance of a class. Here is an example from class JsrSysout. From my COBOL background I like to debug my code by DISPLAYing significant data to the SYSOUT data set. There is a Java method for this, System.out.prinln(...). The problem with this method is that the data you want just scrolls off the Java console, the equivalent of SYSOUT or perhaps DISPLAY UPON CONSOLE if you had your own stand-alone machine. I needed a way to easily do displays that would stop when the screen was full. Since there is only one Java console, the line-count for the screen clearly needs to be a class variable, so all instances (each program/class that logs here has its own instance of JsrSysout) stop at the bottom of the screen.
Multiple Instances of same class: One (calling program) class can create multiple instances of the same class. Why would you want to do this? One good COBOL example is I/O routines. In COBOL you would need to code one I/O routine for each file you wish to access. If you want to open a particular file twice in one run-time environment you would need a different I/O routine with a different name, even if the logic was identical.
With Java you could code just one class for a particular logical file type. Then for each file you wish to read (or write) you simply create another instance of that class using the new operator. Here are some snippets of code from program IbfExtract that do exactly that. This program exploits the fact that I have written a class for Line Input, and another class for Line Output. These are called JsrLineIn and JsrLineOut.
This illustrates another dynamic feature of Java. When output is first created, it is an array of null pointers, it takes very little space. Only when a new object is created, and the pointer to it implicitly put in the array does storage for the object get allocated. That object can be anything from a String to an very complex Class.
COBOL: PICTURE Java: No real equivalent. I therefore invented a method to mymic a ZZZ,ZZZ,... mask for integer input. I have generally grouped my utility functions in JsrUtil. These are methods that really don't related to any type of object. Here is an example of padLeft that implements this logic. padLeft is also a good example of polymorphism. In COBOL, if you have different parameter lists you need different entry points. In Java, the types of parameters are part of the definition. For example:
COBOL: Decimal arithmetic Java: Not in native Java, but IBM has implemented some BigDecimal classes. I consider this the major weakness of Java for accounting type applications. I would have liked to see the packed decimal data type as part of the native JVM byte architecture. I guess it is not there because it is not in C or C++. I have only read about the BigDecimal classes, so I can't realy comment on their effectiveness.
COBOL: COPY or INCLUDE Java: Inheritance ++: Much more powerfull! In COBOL, if you change a COPY or INCLUDE member, you must recompile all the programs that use it. In Java, if program B inherits from program A, a change in program A is automatically inherited by program B without recompiling! Yes, this really works, and lends great power to Java applications. I exploited this for my Read/Sort/Report system. Class IbfReport contains all the basic logic common to the report programs. It has appropriate defaults for all of its methods. Classes IbfRP#### extend IbfReport, and contain only those methods unique to a particular report. If a change is made in IbfReport, it is reflected in the IbfRP#### programs (classes) the next time they are run.
COBOL: ON EXCEPTION Java: try/throw/catch ++: can limit scope of error detection (see following)
COBOL: OPEN Java: Input Streams ++: Automatic error detection, both a blessing and a curse.
COBOL: WRITE Java: write (yes, really).
COBOL: CLOSE Java: close method
COBOL: READ Java: read...

- 52,579
- 61
- 190
- 278
-
1Cobol has the nested subprogram, which operates exactly like a C function or a pascal function/procedure. – Joe Zitzelberger Mar 11 '11 at 18:54
-
@Joe Zitzelberger It has been more than 10 years since I touched Cobol, but aren't all variables there in the global scope? – Itay Moav -Malimovka Mar 12 '11 at 02:01
-
Not at all. Cobol 85 allows the nested subprogram which can limit all scope to the enclosing subprogram. Variables can be shared with all enclosed subprograms using the GLOBAL keyword, and subprograms can be shared using the COMMON keyword. Nested subprograms offer nicely restricted scope. I admit that there are some Cobol programmers that still like writing their code in Cobol 74 style with everything global, but there is nothing it the language that prevents a conscientious programmer from writing nicely encapsulated Cobol code. – Joe Zitzelberger Mar 14 '11 at 04:47
-
FWIW, I think alot of the problem is that Cobol does not make a distinction between a "program" and a "function", it calls them both "programs". So yes, everything is global to a "program", but a "program" can contain an infinite amount of "programs" that limit scope and are only known to the parent "program" -- e.g. what other languages call a function or procedure. – Joe Zitzelberger Mar 14 '11 at 04:49
-
Both languages target the "Write Once, Run Anywhere" idea. If vendor specific extensions are avoided, Cobol is very portable.
Cobol is very much a procedural language, while Java is very much an object oriented language. That said, there have been vendor specific OO extensions to Cobol for decades, and the new specification contains a formal specification. It is also possible to write procedural code in Java, you can easily make a program out of a single main() method.
Both are widely used in enterprise computing for their relative ease of use. Both languages are somewhat hard to shoot yourself in the foot with, compared with other common languages like C and C++.
The most significant difference is that Cobol supports native fixed point arithmetic. This is very important when dealing with financals. Most languages, Java included, only support this via add on libraries, thus they are many orders of magnitude slower when dealing with fixed point data and prone to (potentially very expensive) errors in that library code.

- 4,238
- 2
- 28
- 42
-
You can easily use long integers in Java, scaled by a power of 10 (e.g., 1000) to represent decimal quantities. Adding decimal numbers represented that wasy with the same scale factor takes 1 machine clock on modern CPUs. That outruns a mainframe. – Ira Baxter Nov 03 '22 at 20:21
-
You are correct, technically. And scaling integers does work, but it is prone to much failure, both with programmers that don't grok what is going on as well as passing integers to other bits of software that might not scale them the same. I get it, I know it works, and I've done it, but it isn't anywhere near as great as native fixed point support defined in a shared copybook. – Joe Zitzelberger Nov 04 '22 at 02:32
-
If you are coding in Java or C#, you don't have copybooks. You can package the scaled int in a class whose methods handle the scaling automatically. "Other bits of software might not scale them the same": shame on other bits of software. Like all other programming APIs, if you use them correctly they work. If you don't, you get bugs. (We happen to use this in Java or C# programs created by automatic translation from legacy Cobol. The translator generates the correct code). – Ira Baxter Nov 04 '22 at 18:07