3

Possible Duplicate:
How to get started building a web browser?

I have a basic understanding of the Java language and also some knowledge about applets.

I have to develop a basic Web Browser for my college project which can display simple websites along with Javascript components.

Could anyone tell me what are the prerequisites i.e, what topics should I read before doing this and how to do it?

Really appreciate the help

Community
  • 1
  • 1
  • Are you planning to use an existing JavaScript engine and HTML renderer or are you planning to write both yourself? The latter would be a fairly major task, especially the JS. – us2012 Jan 13 '13 at 17:26
  • Developing a web browser with just basic Java skills is going to be a very difficult task. You will need to read up on and become highly versed on Java networking, document parsing, and GUI development. Are you allowed to use pre-existing frameworks. – Perception Jan 13 '13 at 17:27
  • Question asks about Java specifically. Duplicate talks about C# - there is *some* difference, specially regarding libraries that can help you towards the goal... – tucuxi Jan 13 '13 at 18:50

1 Answers1

3

Writing a web browser is a major undertaking, depending on the level of functionality you want to include.

Things that need to go into a browser:

  • An HTTP client that can retrieve the page content from a server. Java includes something very basic inside java.net, but if you can, use the Apache Commons HTTPClient instead. Many browsers also have support for other protocols, such as ftp:// or local files (file://).
  • An HTML parser, which can read the returned HTML (or XHTML) into an in-memory structure. The hard part here is that not only has HTML evolved; there is also a lot of HTML out there that does not conform to any of the multiple HTML standards. People just tend to write something, see if it can be rendered on a specific browser (say, IE), and move on -- and certain browsers can render almost anything. You can use existing parser such as JSoup for this, which also has limited support for fixing mistakes.
  • A rendering engine. This would be, for me, the most complex step. You would need really in-depth reading to get any sort of CSS support working (major browsers had a hard time getting it right too), and even non-css rendering such as nested tables or complex forms would imply hard work (to calculate where each page component goes on the rendered page). There are no add-on rendering libraries that I know of, but there is minimal (HTML 3.2?) HTML rendering support inside the JEditorPane - you may be able to use that (forget about advanced CSS, thouth).
  • Scripting support. This would interpret JavaScript, and make your pages interactive. You can use Rhino for that (maintained by the folks at Mozilla, and very powerful).

(Plus internal caching to avoid making repeated requests; support for saving pages to files; support for 3rd party plugins/extensions such as Flash; security considerations to avoid cross-site scripting attacks on your users ... there are many more components or concerns that I have not bothered to include above).

Since you have only basic understanding of Java, and any of the above components are fairly complex projects in their own right, I would suggest choosing another project or delimiting a very small subset of what a commercial web browser does to try to implement that instead.

tucuxi
  • 17,561
  • 2
  • 43
  • 74