4 ms·
> In its general syntax, Java is very much like C++. But it does introduce some changes that (depending on your perspective) correct some flaws of C++ or botch
by sagartewari01 8y ago
> In its general syntax, Java is very much like C++. But it does introduce some changes that (depending on your perspective) correct some flaws of C++ or botch up some features.
Are you sure about that? Was java really like C++ during it's earlier years?
- meddlepal 8y agoJava was designed to have a syntax familiar to C++ programmers as its original intended use case was on embedded devices where C++ was king. What about the language design makes you think it _is not_ influenced heavily by C++?
- pjmlp 8y agoInterfaces are based on Objective-C protocols. The class reflection, dynamic loading, JIT come from Smalltalk. Checked exceptions from CLU, Modula-3. Packages from Modula-2, Mesa, Ada,... GC from Lisp, Mesa/Cedar, Similar, Smalltalk,...
- mcv 8y agoJava takes a lot of features from a lot of different languages, but I too remember Java being intended as an improved C++, by keeping most of the syntax, while adding some badly needed features like memory management, exceptions, more consistent standard classes (at the time; it's turned into a mess now) etc.
- pjmlp 8y agoJust like it happened with Go, around 20 years later. However the similarities are only superficial, given the semantic differences. Here are some nice links regarding it. https://cs.gmu.edu/~sean/stuff/java-objc.html https://cs.gmu.edu/~sean/stuff/java-objc.html https://www.artima.com/intv/gosling1P.html https://www.artima.com/intv/gosling1P.html
- sagartewari01 8y agoJust about everything other than the syntax, and even that is similar to that C++ only at the method level.
- dnautics 8y agoOk so not exactly the "early days", but I learned java in 2009 around when android came out; most of my heavy duty c++ experience was with the beos API, and there were some initially confusing concepts (like the factory pattern) but my first impression was "oh, this is what object oriented programming is supposed to be like". The syntax was very easy to understand and I was able to teach myself java and turn around an Android app in about 5 weeks.
- pjc50 8y agoThey are both ALGOL derived languages with braces and the "class" keyword, but that's a bit like both being Abrahamic religions.
- Elrac 8y agoAround the time of the article (1996) I was faced with learning either C++ or Java. When I picked up any C++ book, chances are half the text would be about how to wrestle with memory. I decided C++ wasn't for me. Java was (and still is) a C-like language with objects and fully automatic memory management. Its standard library was a lot less efficient than that of C++ but generally more pleasant to use. Another plus was the inclusion of a (bizarrely stunted pre-Swing, but still) GUI API in the standard library. The price to be paid was program startup time rivalling C++ compile times. In the early days, Java didn't have generics or containers comparable to what you see in Boost or the STL. Hash maps were there, though, and very versatile if a bit slow.
- rwallace 8y agoNot sure why you were downvoted; it's a fair question. To understand the answer, you have to realize that idiomatic C++ has changed over the years. Back in the nineties, it still placed a lot of emphasis on object-oriented programming with inheritance, polymorphism - ah, even writing those words now brings back memories! - and explicit heap allocation, which in turn meant a lot of manual freeing of memory. So yes, Java had much of the same flavor except you didn't have to manually free memory or deal with five different string classes. It was an easy sell.
- rkangel 8y agoIf you look at the design of java (the fundamental basics at least), it makes sense as lets take C++, but design it again from scratch with the problems fixed: * Syntax is fine, keep it * Mixed C heritage creates confusion, lets double down on OO and make everything an object * Mistakes in managing heap memory (allocating, freeing, ownership changes) are the cause of lots of bugs, so we'll do that automatically (GC) * Overrunning arrays is bad so we'll prevent that * Exceptions are great, but sometimes it's unexpected that a function is going to throw one - put it in the type signature * Having to compile for lots of different targets is a pain, so lets provide one common abstraction layer so that our code will run anywhere (multiple desktop OS's, Web, embedded)