• Getting Started

    In order to learn Java, you need the Java Development Kit and NetBeans or Eclipse IDE. JDK contains basic classes needed in developing java applications. NetBeans or Eclipse are IDEs that will aid you in creating applications. In this tutorial, we will use NetBeans instead of Eclipse but its up to you what IDE you want to use.

    You can download the NetBeans IDE Bundle which includes the JDK so you do not need to download and install one by one. Download it here and choose to download NetBeans with JDK. Run and finish the installation.

    Creating New Project

    Open your NetBeans and go to File> New Project. In the New Project dialog, choose Java in categories and Java Application in Projects. Click Next.
    Next, type your desired project name. The project location has been preconfigured to the default location. Change it if you want to save your project in different location. Uncheck Create Main Class option, we will create our own main class later. Click Finish.

    Creating New Package

    A package is just a folder of related classes. It was used so that the project is organized and the java classes can be found easily. It is like in Windows, for example the My Documents folder contains your document files, the My Picture folder contains pictures and the My Music folder contains your music files. In creating a package, dot (.) was used to separate the folders. Like for example, a package com.javapointers.javacore can be found in your projects folder/com/javapointers/javacore. Create new package by right clicking  the Source Packages>New>Java Package.
    In the dialog that pops up, type your desired package name. In my case, i named it com.javapointers.javacore. Click Finish.

    Creating a Class

    Java Classes are where you will write your codes. Create one by right-clicking your package that was created earlier > New > Java Class.
    Name your class anything you want. I have named my class to Main. Click Finish and you will see the main window of your NetBeans will be like this.

    Creating Main Method

    All projects in java contains at least one method. A class that has a main method is called the main class. For the rest of the tutorial, you will be required to create a main method in order for your application to run. The main method is like this:

    public static void main(String[] args){
    
    
    }
    Take note that your main method should be inside the curly braces {} of your class.

    The System.out.println() method

    The System.out.println() method is use to print a String to the console. This was the very basic method and you may encounter this method for the rest of the trails. Let’s try to output some string in the console. Copy the code below to your project:

    public static void main(String[] args){
         //This program will output Hi JavaPointers! in the console.
         System.out.println("Hi JavaPointers!");
    }
    or your class should be something like this:

    To run the program, hit F6 on your keyboard. In case it ask for a main class, try first SHIFT + F6. At the lower part of NetBeans, you can see the output ‘Hi JavaPointers!’.

    Next tutorial will be about Fields and Methods.

    Related Post