Java SectionJava is a Third Generation Object Oriented Programming language. This means that within the language several objects are defined and these are treated as such. Each object has its own responsibility. The Object Oriented principle is a way of thinking that cannot be explaned in one simple line. This way of thinking can only be achieved by practising a lot and reading many books and code. This page is not meant as a tutorial about the Java language. If you are looking for a tutorial, you might want to take a look at the links to Java Tutorials at the Java Links page. Java is designed to be portable. Java code is compiled into bytecode (and not bit code) using javac. Bit code is machine code and is specific for a certain kind of hardware. Since Java code is compiled into byte code, an interpreter must be used to actually run the Java program. Byte code is not hardware dependent and this makes it possible to run a Java program on different platforms. A Java program can be executed on any platform for which there is a Java interpreter available. Many persons say about Java "Write once, run anywhere". Well this is only true for the platforms for which there is an interpreter, but nowadays for almost any (widely used) platform there is an interpreter available. Java is also a Web language. Most Web browsers are equipped with a Java interpreter and are able to execute Java applets. Applets are small Java programs that can be used in websites. Because of security reasons the permissions of applets are very limited. For instance: they can only connect to the machine where they retrieved from (and where there codebase is). Since Java also is designed to work in an network environment such as the internet, Java treats URLs just as easily as most languages treat files. Java is similar to C++, but:
Hello World ExampleIn almost any programming language the first thing you learn is how to print the text "Hello World". This is also in Java the case. The Hello World program is one of the most basic and simple programs that can be written in the Java language. Example code for this program is listed below.
This file should be saved in a file with the name This class can be run, because it has a method (functions are called methods within Java) with the name "main". This method
takes a It is possible to change the simple program above in such a way that it makes use of the Object Oriented approach. An example of this modification is shown below.
This program also has a When the class above is executed the main method is called. The first thing that the main method does is to create
an object of the type The constructor is used to construct a new instance of the object. This constructor makes a call to the
Program written by PeterTo run the program below your system has to be equipped with a Java engine. Most browsers have a built-in Java Virtual Machine, so in most cases it shouldn't be a problem to load the page linked below. Other browsers will prompt you with a warning that Java needs to be installed and a question if you want to do this. If you are having problems accessing the page below you might want to go to the plugin download page of the Java Sun site to get the Java plugin for your browser. LinksBecause the amount of Java related links on this site a separate Java Links page is available: Contact the author: Send an electronic mail to: pajtroon@dds.nl. This page: Copyright © 2002 Peter A. J. Troon Note: This page is part of the Peter Troon Site. |