In this post, you will see the steps to compile and interpret your first program written in Java programing language. This Java example will set the path to start your learning as Java programmer.
STEP 1: Creating the Source Code
Open Windows Notepad (Start -> All Programs -> Accessories -> Notepad), which you will now use as work editor for its simplicity. Later, you can use a more sophisticated editor.
If you prefer to use another editor at the moment, there is no problem. It does not matter while the content is recorded as ‘plain text” (in ASCII code). Once you have the notepad opened, you we will write your first program, which will show a text “Hello Java” in the DOS console window. To clarify that for the moment, you we should not worry about understanding what you write. Here your goal now is simply to verify that you can run a program written in Java.
Next, you proceed to record your program: click on File -> Save as and you put like name Example.java. You are following a rule dictated by Java, which is the name of the file (Example.java) and the name of the program (which you have defined inside the file after writing public class, and which is also “Example”) are identical. Briefly, you must match file name and program name, both uppercase and lowercase, and the file extension should always be “.java”.
To follow an order and avoid later problems during compilation, you will have to create a folder in C: named “Exercises” and locate the program Sample.java within this folder.
STEP 2: Compilation and Program Execution
You will proceed to the compilation and interpretation of this small Java program. You will do this using the DOS console window. To display this window, proceed as follows: Start -> All Programs -> Accessories -> Command Prompt. On the console window, you will write the command “cd C: \ Exercises” and press enter. This takes you to the folder where your file is located (“Example.java”). If you have successfully entered when typing dir and press enter, you should see the file Example.java.
Now you give the instruction for the program compilation process, for what you write “javac Example.java” where “javac” is the name of the compiler (javac.exe) that will transform the program you have written in Java language to the Java Virtual Machine (bytecode) language, resulting in a new “Example.class” file to be created in this same directory. If you see an error message, check all the previous steps explained above, because it is possible that the environment variables were not created or that the file is not well located, etc. To check if the file has been created, you will write the “dir” command in the console window and will see that two files appear: Example.class (bytecode created by the compiler) and Example.java (source code created by you).
Finally, you are going to ask the interpreter to execute the program, that is, to transform the Java Virtual Machine code into machine code interpretable by your computer and execute it. For this you will write in the console window: java Example.
The result will be that the string “Hello Java” is shown to you. If you can see this text on screen, you have already developed your first program in Java.
In other operating systems the process is similar. If you have problems completing this Java example, do not worry, continue to advance with the contents available on this blog.
Java
Java is object-oriented programming language. It is the result of programming intelligence of James Gosling and his associates at Sun Microsystems in the beginning of 90s. Java programming is compiled into bytecode, which is executed by JVM. Usually, a JIT compiler is used. The language is similar to C and C++, although its object model is simpler, and was also influenced by Smalltalk and Eiffel.
JavaFX
It is a software platform allows the developers to create and run web applications with the ability to run on a variety of devices. It allows to create applications to run on desktops, web browsers and mobiles. In future, it is planned to expand JavaFX to video game consoles, Blu-Ray DVD, among others. The direct competitors of JavaFX are Flash of Adobe and Silverlight from Microsoft. OpenLaszlo was also a competitor to it, but it has been discontinued now.
The Features
- Creating JavaFX applications is through language JavaFX Script.
- Desktop applications can run on Windows XP, Vista and 7, Mac OS, GNU/Linux and OpenSolaris.
- Because of integration with JRE, its applications can run on any browser with JRE, as well as mobile phones with Java ME.
History
- It was announced by Sun Microsystems in May 2007 at the JavaOne Worldwide Java Developer conference.
- Version 1.0 was released on December 4, 2008.
- Version 1.1 was released on February 12, 2009.
- Version 1.2 was released on June 2, 2009, with full support for Linux and Solaris along with improvements in speed.
JavaFX Script
It is a scripting language developed by Sun Microsystems, which is part of the family of JavaFX technologies. JavaFX Script was originally called F3 (Form Follows Function) and was developed by Chris Oliver. In September 2005, his company, SeeBeyond Technology Corporation, was acquired by Sun and Oliver became an employee of Sun. F3 was changed to the current name and became open source in JavaOne in 2007.
F3 was an interpreted language while JavaFX Script focuses primarily as a compiled language. Compiled programs written in JavaFX Script can be run on any platform that has a newly installed Java Runtime.
The Features
- It is a compiled scripting language, with static and declarative typing.
- It provides automatic data hiding.
- It supports vector graphics mode, video and Swing components through its APIs.
- It is possible to use it as an interpreted language.
Many have this notion that JavaFX won’t survive but Oracle does not seem to be convinced with this notion and it working well for its advancements.