I know that a Java web browser is possible, but is it practical? I've seen the Lobo project and must admit I am impressed, but from what I've gathered it seems that development stopped in 2009. Would a browser coded in pure Java (no WebKit java bindings of any type) be able to compete with those among the ranks of Chrome or Firefox, or would it be inherently slower, hindering the user?

share|improve this question
1  
Interesting question because a web browser called HotJava was an early Java demo app. – user16764 Nov 6 '12 at 6:13
1  
It wasn't just a demo app, it was a key part of the late 90's/early 2000 commercial Sun Java strategy, and they pushed it on to partners pretty hard. Add to the list of Java oddities from Sun around the same era: JavaOS/JavaStation. – JustinC Nov 6 '12 at 7:37
1  
Technically speaking, wouldn't the Android versions of Opera, Chrome & FF be written in Java? Haven't tried FF, but given a decent device, Chrome & Opera work pretty well. – TC1 Nov 6 '12 at 14:06
@TC1 I think they are written in C\C++ with the Android Native Development Kit. – wawa Nov 12 '12 at 18:17

5 Answers

The programming language is, most likely, not going to be the stumbling block. The JVM's mandatory memory management may be a disadvantage in some performance-critical parts (e.g. memory hunger; but then, Java's GC might actually be better at preventing memory leaks than anything you could roll yourself), and there are a few extra security concerns, but other than that, I see no obvious show stoppers.

However.

A web browser on the scale of Firefox or Chromium is a massive undertaking, and both projects have a huge body of experience behind them - Mozilla builds upon decades of browser building (and some famous failures), and Chrome/Chromium has both Google and Apple (a major force in the development of WebKit) behind it and absorbed a lot of knowledge and experience from KDE and other large rock-solid Open Source projects. Both additionally make use of dozens of battle-proven libraries, not only render engines, but all sorts of things. Vector graphics, font rendering, parsing, XML DOM Tree manipulation, networking, caching, cryptography, the list goes on and on, and you don't want to reinvent all those wheels yourself, because they are hard to do and easy to get wrong.

In short, building an industry-strength web browser is pretty damn hard, and that's the reason there is only a handful of success stories in this arena. The programming language has relatively little to do with it, although C and C++ are at an advantage, both technically and socially.

share|improve this answer
is that by chance your answer at Workplace.SE? Name is grayed there, but the notice on the question says "migrated from Programmers" – gnat Nov 13 '12 at 13:13

In theory, it could undoubtedly be done. From a practical viewpoint, however, it seems a bit more questionable. lobo isn't even close to the first time it's been tried. In fact, one of the early showcases of the superiority of Java was supposed to be the HotJava browser -- which was going to change the world, and render the "Mosaic generation" browsers obsolete.

Of course, we all know pretty much the opposite is true: HotJava is dead, and was never really a serious competitor in the browser wars (in fact, if you search for "HotJava browser", some of the top hits are for bug reports about how it didn't work quite correctly, even for Sun's own web apps).

Personally, I think wondering about whether it's possible or practical is (mostly) looking and thinking in the wrong direction. The question is not whether Java carries such massive penalties for such a project to be impractical. The question is whether Java has enough advantages to justify such a project.

The simple fact is that webkit (to use your example) is a big, complex piece of code. Even if we assume that Java is so much more wonderful that we could do the same with, say, half the size and complexity, the result is still a pretty big, complex piece of code (likewise V8, etc.)

I think before duplicating that amount of work, most people would want a little more assurance than: "we think our product is likely to be fairly competitive."

If you start from a set of user-visible features for a browser, and then try to determine the most efficient way to produce a browser with those features, "Java" probably won't be part of that answer, except as part of "Javascript". If history had worked out differently, there's probably no reason it couldn't (at least theoretically) be part of the answer, but given current circumstances, it isn't.

Furthermore, I see very little likelihood of that changing. I can barely see it happening if Oracle (or possibly IBM) decided it was useful to maintain Java's competitive stance vs. (for an obvious example) Microsoft .NET, but that seems doubtful unless .NET starts to threaten Java's core market.

Outside of that, any set of features you can imagine (outside of "written in Pure Java" as a feature in itself) can almost certainly be achieved quicker and easier in other ways than by writing a browser entirely in Java.

share|improve this answer
I got the smell of old books in my nose when reading through that HotJava link – Mario De Schaepmeester Nov 6 '12 at 19:49

I honestly believe that a dedicated, knowledgeable team could create a performant web browser in Java. The real question is, why? Having the browser written in a specific language is not really a feature. People will use Chrome because it is fast or Firefox because it is extensible, but they will not use JBrowser just because it happens to be written in Java. So the real question becomes, what problem are you trying to solve?

The next question, assuming you have a reason to write JBrowser is, "does using Java make the task easier or harder?" Google, when making Chrome, wrote it primarily in C/C++ despite the fact that they are a very pro-Java shop. It seems quite likely that they believed that the benefits of Java were not going to bring in a net gain on time.

share|improve this answer

With Nashorn (The Javascript on the JVM replacing Rhino) coming to the JVM as part of Java 8, this is eminently doable. However, as others have noted - there's an awful lot to a modern web browser and it does just seem easier to embed WebKit if you need to host browsing capabilities within a Java app :-).

share|improve this answer

I have to say I’m a little biased here, but here I go. I don’t like the C/C++ preachers, I know there are some incredible good engineered applications out there but its just A tool, often I got the impression, many people only mentioning C/C++ for a solution miss more then A point (http://www.paulgraham.com/avg.html see bulb paradox). I try to look at the facts: Java is as fast C/C++ but requires more memory therefore. Or let me rephrase you can write java code which is as fast as C/C++ but that program will consume more memory. I hope we can agree on this.

If you look at productivity, you can create java solutions for certain problems (say enterprise java) relatively easy, compared to C++ solutions. A web browser is something completely different. I see two/three mayor requirements:

  • It has to conform to huge specifications, HTML, JavaScript, etc. This involves problems like 2D Drawing APIs. Or how do get from a OS system call (as a drawing primitive) to text or font representation (“rendering”). Have a look at libraries like cairo( C ) and other attempts like gezira (www.youtube.com/watch?v=P97O8osukZ0 , https://github.com/damelang/gezira )
  • It has to “feel” fluent, which means certain operations only have ms to be executed.
  • It has to form a UI Concept which form a unique experience, to compete in today’s ‘browser wars’ which is quite challenging.

To sum up: yes you could, you could create browsers in almost any programming language with nearly identical results compared today’s C++ steamships. But to do so you would need quite an extraordinary amount of effort. I don’t know how much ( in the millions) , I would not want to even guess at that. Maybe we could get this bottom line: people don’t like to optimize in high level languages, or maybe its cheaper to get people who like to optimize in C/C++ because there are so many (compared to other language experts who can optimize on a similar level).

share|improve this answer
1  
I'm tempted to down vote because you didn't break your answer into multiple paragraphs. Please break your wall of text up with some white space. – Gilbert Le Blanc Nov 6 '12 at 14:29
Well I write from mobile, and that is the best I can do with mobile interface, sorry – AndreasScheinert Nov 6 '12 at 18:11
Went to a laptop and fixed it. – AndreasScheinert Nov 6 '12 at 18:22
"Or let me rephrase you can write java code which is as fast as C/C++ but that program will consume more memory. I hope we can agree on this." No, we can't, at least not in all cases. Java won't let you implement multiple custom memory managers for different patterns of memory allocation. You can't turn off array bounds checking when you decide it's not necessary, you just have to hope that the JIT will recognize when it's not needed. These issues don't come up in most programs, but they can be crucial in applications that needs every last nanosecond of performance. – Charles E. Grant Nov 6 '12 at 18:43
Your repeating arguments here that garbage collection has some performance implications. I agree with that. But it it's just one aspect. – AndreasScheinert Nov 9 '12 at 13:27

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.