Download ArticleDownload Article

Java (not to be confused with the Javascript) is one of the most popular programming languages. Java is a high-level programming language that can be used to develop apps for multiple operating systems, including Windows, macOS, Linux, and Android. The way Java works is you download the Java Development Kit (JDK), which is used to develop Java code. The code is then compiled into bytecode that the computer can understand using the Java Runtime Environment (JRE).[1] With Java, you can develop apps for multiple operating systems with minimal work. This How.com.vn teaches you the basics of how to get started programming with Java.

Part 1
Part 1 of 2:

Installing What You Need

Download Article
  1. How.com.vn English: Step 1 Download and install Java Runtime Environment.
    Java Runtime Environment is the software layer that is used to run Java applications. It contains the libraries, Java Virtual Machine (JVM), and other components needed to run Java applications.[2] You may already have it installed. If not, used the following steps to download and install the latest version of Java Runtime Environment on your computer:
    • Go to https://www.java.com/en/download/ in a web browser.
    • Click Java Download.
    • Click Agree and start free download.
    • Open the installer file in your web browser or Downloads folder.
    • Follow the instructions to complete the installation.
  2. How.com.vn English: Step 2 Download and install Java Development Kit.
    While Java Runtime Environment contains the software needed to run Java applications on your computer, it does not contain the tools needed to write and compile Java code into Java class applications. For that, you will need Java Development Kit. Use the following steps to download and install Java Development Kit:
    • Go to https://www.oracle.com/java/technologies/javase-downloads.html in a web browser.
    • Click Download JDK below the latest version of Java Development Kit.
    • Scroll down and click the file name that is appropriate for your operating system (i.e. Windows Installer, macOS installer)
    • Open the downloaded installer file in your web browser or Downloads folder.
    • Follow the instructions to complete the installation.
    Advertisement
  3. How.com.vn English: Step 3 Download and install a Java IDE.
    IDE stands for Integrated Development Environment. These are programs you can use to compose, debug, and compile code. The two most common IDEs are Eclipse and Netbeans. You can also use Android Studio to develop apps for Android devices in Java. Use one of the following lines to download an install an IDE for Java.
  4. Advertisement
Part 2
Part 2 of 2:

Creating a "Hello World" Program in Java

Download Article
  1. How.com.vn English: Step 1 Open your Java IDE.
    Open whichever IDE you chose to download. You can open apps in the Windows Start menu, or Applications folder on Mac.
  2. How.com.vn English: Step 2 Create a new Java project.
    You may be given the option to create a new project when you first open your IDE. If not, click File in the menu bar at the top, and then click the option to create a new Java project or new java application.
  3. How.com.vn English: Step 3 Give your project a name.
    When you create a new Java application or project, you will then be asked to give your project a name. Use the field at the top to type a name for your project. You can name it something like "Hello" or "Hello_World" or anything you want.
  4. How.com.vn English: Step 4 Create a new Java class.
    When you create a new project in your IDE, locate the Package Explorer panel, which is generally to the left. This is where you can find all the files related to your project. To create a new class for your project, right-click your project name and click New class or click New followed by Class. Type a name for the class in the "Name" field and click Finish.
    • A Java class is like constructor or blueprint for Java objects. A java class can contain one or more objects with their own unique properties called "Members".
    • The code to create a new class looks something like public class Hello { . The keyword "public" is the access modifier. This tells dictates what can access the class or object within the program. The keyword "class" indicates that this is a new class. They keyword "Hello" is the name of the class. Finally, the curly-bracket "{" at the end opens the class. You'll probably notice a closing curly-bracket "}" a couple lines down. All code that is part of this class goes in between these two curly brackets.
  5. How.com.vn English: Step 5 Indent the next line and type public static void main(String[] args) {  in the next line.
    This line is used to create a new member. A member is a feature of a class. A member that contains code with specific instructions is called a "method". Methods can be called and ran at later instances in the code. All Java programs need to have a method called "main". This indicates where the program starts. The keyword "Public" is the access modifier.[3]
    • The keyword "public" again is the access modifier. Since it is set to "public" this means this method can be called anywhere in the program. If it were set to "private", this would mean the method could only be accessed within the class.
    • The keyword "static" indicates that this member can be accessed before any other objects in the class and without referencing any other objects or instances.
    • The keyword "void" is the return value of the method. This indicates that it does not return any values. If it were to return a number, the would be changed to "int" or "float" or "double", depending on the type of value you wanted to return.
    • The keyword "main" is simply the name of the member. All Java programs need to have a method called "main" to indicate where the program starts.
    • Whenever you have any text in between parenthesis (i.e. String[] args{}), it is called an argument. An argument can be many things like an integer, double, float or string. This line of code is indicating that the method is an expecting an argument of type array (a list of objects) which contains strings.[4]
    • Indenting when you code isn't necessarily required, but it helps keep your code organized and indicates which lines of code are part of which class, member, or method. Indent each line of code any time you create a new class, member, or method. Or after each instance of a new curly-bracket
  6. Step 6 Indent the next line and type System.out.println("Hello World");.
    This line is used to print the words "Hello World" as a string.
    • The keyword "System" indicates that this part of the System class.[5]
    • The keyword "out" indicates that this is an output.
    • The keyword "printlin" tells the program to print something in the output panel, terminal, or command line.
    • Since "Hello World" is in parenthesis, this is an example of an argument. In this case, the argument is a string that says "Hello World".
  7. How.com.vn English: Step 7 Test your program.
    Testing in an integral part of programming. This is how you make sure your program is working properly. To test in Eclipse or Netbeans, simply click the green 'Play' triangle at the top of the screen. You should see it say "Hello World" in the output panel at the bottom of the screen. If it does not, you'll need to do some troubleshooting to fix the problem. Your entire code should look something like this:
    public class MyProgram {public static void main(String[] args) {System.out.println("Hello World");}}
    • Check the syntax for all the code and make sure it is enter properly. Make sure the keywords are in the proper order and spelled correctly, including the capitalization.
    • Make sure that each open curly-bracket for each class and method has a corresponding closing curly-bracket at after the method or class.
    • Google any error message you receive and see if there is a fix. Sometimes it may be a problem with the system. You may need to delete a file, or even reinstall Java.
  8. Advertisement

Video

Community Q&A

Search
Add New Question
  • Question
    How do I easily learn Java programming?
    How.com.vn English: Community Answer
    Community Answer
    It really depends on how interested you are and how much time you spend learning. It also depends on if you have a programming background. There are many courses you can take online or at local colleges.
  • Question
    How do I use set and get in Java?
    How.com.vn English: Community Answer
    Community Answer
    You need to create a class and define a variable. If you are using Eclipse IDE, then right click and select 'generate setter and getter,' and it will be generated.
  • Question
    How do I solve an error that says "this class doesn't have a man.method" when I am coding in Java?
    How.com.vn English: Community Answer
    Community Answer
    It is presumed that you mean "main method." All Java programs have a main method as that is where the program execution begins. You'll just have to create the main method. public static void main (String [] args) { }.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Tips

      • Keep your code organized and add lots of comments for easy reading, recalling, and updating.
      • After you get some experience, try to get official programmer certification from Sun Microsystems itself. This is a lot more serious than any other certification you can get from the third parties.
      • Learn technologies in which Java is strong: network communication, database connection, web development, etc.
      Show More Tips
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      Warnings

      • It is usually not necessary to pay for Java courses that may be very expensive and offer little value. Unless you want to learn something specific, it is frequently better just to do more programming yourself, and learn from other people's open-source programs.
      Advertisement

      About This Article

      How.com.vn English: Stan Kats
      Written by:
      Cybersecurity Expert
      This article was written by Stan Kats and by How.com.vn staff writer, Travis Boylls. Stan Kats is the COO and Chief Technologist for The STG IT Consulting Group in West Hollywood, California. Stan provides comprehensive technology & cybersecurity solutions to businesses through managed IT services, and for individuals through his consumer service business, Stan's Tech Garage. Stan has over 7 years of cybersecurity experience, holding senior positions in information security at General Motors, AIG, and Aramark over his career. Stan received a BA in International Relations from The University of Southern California. This article has been viewed 686,032 times.
      How helpful is this?
      Co-authors: 80
      Updated: February 23, 2023
      Views: 686,032
      Categories: Java
      Thanks to all authors for creating a page that has been read 686,032 times.

      Reader Success Stories

      • How.com.vn English: Nagasairam Mekala

        Nagasairam Mekala

        Jul 5, 2016

        "good explanation."
      Share your story

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement