YOUR FIRST JAVA PROGRAM: HELLO WORLD

YOUR FIRST JAVA PROGRAM: HELLO WORLD

Historically, the first program you write while learning a new programming language is the program Hello World.

To start writing a Java program you could use any plain text editor, such as Notepad, TextEdit, or Sublime Text . The file that contains the Java code must be saved in a file with its name ending in .java.

Enter the following code in the text editor.



>
Downloading and installing JAVA

Downloading and installing JAVA

 Download and install JDK for your platform from Oracle’s Java SE Downloads site: http://bit.ly/1OQi4Jz. .
In some literature you see references like JDK 1.8, which is the same as JDK 8. The number 8 is followed by the letter u and a number. For example, JDK 8u91 means that Oracle has released an update number 91 for JDK 8.


JDK and JRE



If you are planning to use a specific computer to develop Java programs, you need to download and install JDK. If you are planning to use this computer only to run Java programs that were compiled somewhere else, you just need the Java Runtime Environment (JRE).

If you have JDK installed on your machine, it includes JRE.

Java’s platform independence comes from the fact that your Java program doesn’t know under which operating system (OS) or on which hardware it’s being executed. It operates inside the pre-installed JRE.

The life cycle of a java program


There are different types of programming languages. In some of them you write the text of the program (aka the source code) and can execute this program right away. These are interpreted languages (for example, JavaScript).

But Java requires the source code of your program to be compiled first. It gets converted to a bytecode that is run by Java Virtual Machine, which may turn some of it into a platform-specific machine code using the so-called Just-In-Time (JIT) compiler.

Not only will the program be checked for syntax errors by a Java compiler, but other libraries of Java code can be added (linked) to your program after the compilation is complete (deployment stage). There are plenty of readily available libraries of reusable components, and a vast majority of them are free of charge.

In this lesson you start with writing a very basic Java program that outputs the words “Hello World” on your computer’s monitor.

Technically you can write the source code of your Java program in any plain text editor that you prefer (Notepad, TextEdit, Sublime Text, vi, and so on), but to compile your program you need additional tools and code libraries that are included in the Java Development Kit (JDK). 

Why learn Java?


The Java programming language was originally created in 1995 by James Gosling from Sun Microsystems (acquired by Oracle Corporation in 2010).
The goal was to provide a simpler and platform-independent alter‐ native to C++. Java programs run inside the Java Virtual Machine (JVM), which is the same on every platform from the application programmer’s perspective.

BUT, WHY JAVA ??

Java is used in all industries for almost any type of application. If you master it, your chances of getting employed as a software developer will be higher than if you specialize in some domain-specific programming languages.

There are more than nine million professional Java developers in the world, and the majority of them are ready to share their knowledge by posting blogs and articles or simply answering technical questions online. If you get stuck solving some problem in Java, the chances are very high that you’ll find the solution on the Internet.

Because the pool of Java developers is huge, project managers of large and small corporations like to use Java for the development of new projects—if you decide to leave the project for whatever reason, it’s not too difficult to find another Java programmer to replace you. This would not be the case if the project were being developed in a powerful, but less popular language, such as Scala. At this point you may ask, “Does that also mean that my Java skills will be easily replaceable?” It depends on you.

Not only is Java open-source, but there are thousands and thousands of open-source projects being developed in Java. Joining one of these projects is the best way to get familiar with the process of project development and secure your very first job without having any prior real-world experience as a programmer.

The Java language is object-oriented (OO), which enables you to easily relate program constructs to objects from the real world. On the other hand, recently added lambda expressions allow you to program in Java in a functional style.

The IT world is changing and people often use more than one language in the same project. Java is not the only language that runs in JVM. Such languages as Scala, Groovy, Clojure, JavaScript and others also run on JVM. So being familiar with the JVM opens the doors to being a polyglot programmer within the same operating envi‐ ronment.

The server-side applications that are deployed in the JVM scale well. The processing of thousands of users requests can be arranged in parallel by splitting the job between rather inexpensive servers in a cluster.

Java as a development platform has many advantages over other environments, which makes it the right choice for many projects.

Kategori

Kategori