Programming Shortcut - c, c++, java, SQL, online tutorials
No Result
View All Result
  • Home
  • About us
  • Programs in c
  • Programs in cpp
  • Programs in java
  • .Net
  • Privacy Policy
  • Contact Us
  • Home
  • About us
  • Programs in c
  • Programs in cpp
  • Programs in java
  • .Net
  • Privacy Policy
  • Contact Us
No Result
View All Result
Programming Shortcut - c, c++, java, SQL, online tutorials
No Result
View All Result
Home Programming Language

How to Write a Simple Java Program

admin by admin
February 9, 2020
Reading Time:2min read
0

RELATED POSTS

Java program to find quotient and remainder

Java program to solve mathematical expressions

Difference and similarities between java and c++

 Java is an object-oriented language similar to C++. But it is designed to be simplified to eliminate the possibility of creating common programming errors, such as memory corruption, pointer or reference errors.Before you start to write a Java program, you have to select your development environment:

Use Java Software Development Kit (SDK) and a text editor, such as Notepad, EditPlus.
Use an Integrated Development Environment (IDE), such as NetBeans, Eclipse.
Now let’s see source code of the simplest Java program which simply displays a message to the console window:

Source Code
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println(“Hello World!”);
}
}

How run the java program ?

If you’re using a text editor, you have to named the file as same as class name which is ‘HelloWorld’, with the extension.java appended. Then, compile the file by run this command:
$javac HelloWorld.java

After you’ve compiled the file, the Java compiler creates a bytecode file ‘HelloWorld.class’ from the source code. This file will be used to run by the Java interpreter. To run this, type this command:
$java HelloWorld

You will see output on console window:

Hello World!

If you’re using an IDE, you can run this source code by click on Start Debugging. The IDE will compile, run source code and display an output as above.

Code explanation:

You have successfully written your first Java program. Now let’s look at this source code line by line:

public class HelloWorld
Everything in Java must be inside a class. This class is called ‘HelloWorld’. The keyword public is an access modifier which determine access level other classes can use this code. In this case, this class is visible to all classes everywhere.
public static void main(String[] args)
This is the only method in this class, main method, with a parameter args as array of String. Every Java program must have a main method. The static method is method that does not operate on an object so the main method has to be static because there aren’t any objects when a program starts. The keyword void is used on a method indicates that the method returns no data.
System.out.println(“Hello World!”);
Here is the body of the main method. This class has only one statement, each statement is separated by a semi-colon (;). This statement, I use System.out object and call println method. The println method displays the text from parameter on console window and terminates the line.

ShareTweetPin
admin

admin

Related Posts

Programs in java

Java program to find quotient and remainder

April 21, 2020
Programs in java

Java program to solve mathematical expressions

April 21, 2020
Programming Language

Difference and similarities between java and c++

April 16, 2020
.Net

Difference between FOPs and OOPs

April 16, 2020
Programming Language

How to set path in java in windows 10, 8.1, 8, 7

April 16, 2020
Programming Language

Object-Oriented Programming (OOP) in Java

January 17, 2020
Next Post

What is the Difference Between Java and Dot NET

Object-Oriented Programming (OOP) in Java

Popular Stories

  • Short name by java program

    0 shares
    Share 0 Tweet 0
  • Relation of two numbers in c programming

    0 shares
    Share 0 Tweet 0
  • How to find quotient and remainder in c++ program

    0 shares
    Share 0 Tweet 0
  • Java program to find quotient and remainder

    0 shares
    Share 0 Tweet 0
  • how to find quotient and remainder in c program

    0 shares
    Share 0 Tweet 0
Programming Shortcut

Hi Friends, Programming Shortcut is Educational Blog, that From you Learn Programming in Multiple languages like C, C++, Java Programming Language.

LEARN MORE »

Recent Posts

  • How to find quotient and remainder in c++ program
  • how to find quotient and remainder in c program
  • Java program to find quotient and remainder

Categories

  • .Net
  • Programming Language
  • Programs in c
  • Programs in cpp
  • Programs in java
  • Uncategorized

All © 2021 Programming Shortcut - Present By Math Training.

No Result
View All Result
  • Home
  • About us
  • Programs in c
  • Programs in cpp
  • Programs in java
  • .Net
  • Privacy Policy
  • Contact Us

All © 2021 Programming Shortcut - Present By Math Training.

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?