Why Is Java So Popular for Developers and Programmers

Source: Internet
Author: User
Keywords java tutorial advanced java tutorial java programming java programmer

What Is Java?

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let application developers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. The syntax of Java is similar to C and C++, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities (such as reflection and runtime code modification) that are typically not available in traditional compiled languages. As of 2019, Java was one of the most popular programming languages in use according to GitHub, particularly for client-server web applications, with a reported 9 million developers.

 

Why is Java so popular for developers and programmers?

One of the biggest reasons why Java is so popular is the platform independence. Programs can run on several different types of computer; as long as the computer has a Java Runtime Environment (JRE) installed, a Java program can run on it.

Most types of computers will be compatible with a JRE including PCs running on Windows, Macintosh computers, Unix or Linux computers, and large mainframe computers, as well as mobile phones.

Since it has been around for so long, some of the biggest organisations in the world are built using the language. Many banks, retailers, insurance companies, utilities, and manufacturers all use Java.

Java is fundamentally object-oriented. The code is so robust because Java objects contain no references to data external to themselves. The language is considered to be very simple; however, it comes with a library of classes that offer commonly used utility functions that most Java programs can’t work without.

Java API, the class library, is as much a part of Java as the language itself. In actuality, the genuine challenge of learning how to use Java isn’t learning the language, but learning the API. The language consists of 50 keywords, but the Java API has thousands of classes with tens of thousands of methods you can use in your programs.

 

How to Create Your First Java Program?

Write the Java Source Code

#1 Write the Java Source Code

All Java programs are written in plain text — therefore you don't need any special software. For your first program, open up the simplest text editor you have on your computer, likely Notepad.

 

The entire program looks like this:

While you could cut and paste the above code into your text editor, it’s better to get into the habit of typing it in. It will help you learn Java more quickly because you will get a feel for how programs are written, and best of all, you will make mistakes! This may sound odd, but each mistake you make helps you to become a better programmer in the long run. Just remember that your program code must match the example code, and you’ll be fine.

 

Note the lines with "//" above. These are comments in Java, and the compiler ignores them.

1.         Line //1 is a comment, introducing this program.

2.         Line //2 creates a class HelloWorld. All code needs to be in a class in order for the Java runtime engine to run it. Note that the entire class is defined within enclosing curly braces (on line /2 and line //6).

3.         Line //3 is the main() method, which is always the entry point into a Java program. It also is defined within curly braces (on line //3 and line //5). Let's break it down:

4.         public: This method is public and therefore available to anyone.

5.         static: This method can be run without having to create an instance of the class HelloWorld.

6.         void: This method does not return anything.

7.         (String[] args): This method takes a String argument.

8.         Line //4 writes "Hello World" to the console.


#2 Save the File

Save your program file as "HelloWorld.java". You might consider creating a directory on your computer just for your Java programs.

It’s very important that you save the text file as "HelloWorld.java". Java is picky about filenames. The code has this statement:

This is an instruction to call the class "HelloWorld". The filename must match this class name, hence the name "HelloWorld.java". The extension ".java" tells the computer that it’s a Java code file.

#3 Open a Terminal Window

Most programs that you run on your computer are windowed applications; they work inside a window that you can move around on your desktop. The HelloWorld program is an example of a console program. It does not run in its own window; it has to be run through a terminal window instead. A terminal window is just another way of running programs.

To open a terminal window, press the "Windows key" and the letter “R”.

You will see the "Run Dialog Box". Type "cmd" to open the command window, and press "OK".

A terminal window opens on your screen. Think of it as a text version of Windows Explorer; it will let you navigate to different directories on your computer, look at the files they contain, and run programs. This is all done by typing commands into the window.

#4 The Java Compiler

Another example of a console program is the Java compiler called "javac." This is the program that will read the code in the HelloWorld.java file, and translate it into a language your computer can understand. This process is called compiling. Every Java program you write will have to be compiled before it can be run.

 

To run javac from the terminal window, you first need to tell your computer where it is. For example, it might be in a directory called "C:\Program Files\Java\jdk\1.6.0_06\bin". If you don’t have this directory, then do a file search in Windows Explorer for "javac" to find out where it lives.

 

Once you’ve found its location, type the following command into the terminal window:

 

E.g.,

Press Enter. The terminal window will just return to the command prompt. However, the path to the compiler has now been set.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.