Getting started with Java using NetBeans

Hello Everyone,
This is Saif, enjoying cool breez here in Karachi and coming up with another tutorial titled as ‘Getting Started with Java using NetBeans’. This article is for beginners who want to get their journey started in programming world using Java. It will also be helpful for those who are already familiar with some other programming language and wants to learn Java.

After basic introduction to Java, this article will guide step by step how to write first program in Java using Netbeans as an IDE. Let’s Begin.

Basic Introduction of Java

Java is a general-purpose, high-level, statically typed, platform independent programming language. Java files have .java extension.

Java Virtual Machine (JVM) is the environment where java programs are executed. Java is not compiled into platform specific machine code, rather to platform independent byte code which is interpreted by JVM.

Applications

Now a days, java is used for designing different types of applications including:

  • Web based applications
  • Desktop based GUI Applications
  • Mobile Applications
  • Gaming applications
  • Embedded systems
  • Distributed Enterprise Applications
  • and many more..

IDEs  (Integrated Development Environments) Used for Java

  • NetBeans
  • Visual Studio
  • Eclipse
  • IntelliJ IDEA
  • JDeveloper
  • and Others

Getting Started with NetBeans

  1. Download and install Java from heredownload java
  2. Download and install NetBeans from here
  3. Open NetBeans and Create a new projectnew project
  4. Select java -> Java Application from the dialog and then click nextjava Application
  5. Name your new program and click on finishname new program
  6. You will see that your first program file is open in an editor and also visible in top left window under the projects tab inside the package “myfirstprogram”. main window

Writing the First Java Program

After installing IDE and creating out first project, it’s time to write our first Java Program.

Before directly jumping into the code, let me introduce you with some new terms.

Package

For the time being consider a Package as a folder containing the collection of related files.

Class

As Java is Object Oriented Language, all the code is enclosed inside a class. You can see a class name as ‘MyFirstProgram’ by default. It is called Driver or Test class. Driver class contains the ‘main‘ method. When the program is executed, Test or Driver Class is always executed first (if there are more than one classes in the program).
Note: Name of the program file and the class name should be the sameclass and program name should be the same

Main Function

It is important to know that every Java program always contain a ‘main‘ function and the program starts executing form this function. Main function is placed inside the Driver class. In Java main function is defined as:
public static void main(String args[]) {
// function body
}
public means this function is accessible from out side the class.
void mean the function does not return any thing.

Terminator ( semicolon ) – The Important Thing

Like C++, In Java it is required to use semicolon (;) to terminate a statement. Forgetting semicolon will result in errors in your program.

Delimiter Brackets

Delimiter brackets ‘{ }’ are use to indicate beginning and closing of a function or other code blocks like if, else, for, while etc.

Basic Program Structure

program structure

Comments: From line 1-5, the text with gray is actually a multi-line comment. Comments are not the part of program, they are just uses to explain the code.

System.out.print(): This function is used to display something on screen as output

System.out.println():  It is the same as above but gives a line break (simply change the line).

Executing the Program:

Press F6 or click on Debug Project to execute the program or simply click the green button.

press F6 to debug

After executing the above code you will get the following in output window

output

Congratulations 🙂
We are done with setting up Java and netbeans and successfully executing our first program.

Stay with Protorials for more tutorials.
Have a nice day!

Advertisements

2 thoughts on “Getting started with Java using NetBeans”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s