Computer

Simple JAVA program

Simple JAVA program
Want create site? With Free visual composer you can do it easy.

Object – I will take some real world examples to make this easy. In our real world, there are many objects such as cars, clothes, dogs, cats etc.: All their objects have a state or/and a behavior. If we take the object as cat, the state can be name, color, breed and the behavior can be eating, playing, purring etc. Just like that in Java also the object has states and behaviors. A state of a software object is stored in the fields and the behaviors are shown via methods. (Methods operate on the state of the object and the object to object communication is done via methods.)Class – By using classes we can create different objects.

Public – Which means it is visible to all. Represents the visibility.

Static – If a method is static we do not need to create object to invoke the static method.

Void – This is the return type of the method which means it does not return any value.

Main – Indicates the startup of the program.

Following is a very basic type of a Java program. 

public class Fish{
 string color;
 string name;
 void swimming(){
 }
 void eating(){
 }
 void sleeping(){
 }
}
How to run your Java program?

Open your Notepad and write a simple java program as above. Save the file as Fish.java. To compile and run the program, go to your command prompt and give the command to run the program.cd new
javac Fish.java

Java simple

Thamali Epa
Thamali is a contributor at Nerdynaut Staff.
Did you find apk for android? You can find new Free Android Games and apps.
  • Fascinated
  • Happy
  • Sad
  • Angry
  • Bored
  • Afraid

FB comments

Use 3dcart to create your online store.
1 Comment

1 Comment

  1. POINTOF.ORG

    February 27, 2016 at 6:21 pm

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular

​Disclaimer : Nerdynaut is a tech company which consists of professionals in respective academic fields in its functional team facing challenging roles to quench the thirst of knowledge in cyberspace. Every article and majority of artworks in this website are copyright of Nerdynaut 2017. After a written permission from the publisher, the original content can be reused or referred for promotional work of education without any modification. Expressions of mass media with intentional harm on Nerdynaut brand may be liable to criminal prosecution and civil claims for the damages caused.
Protected by Copyscape
* = required field

Copyright©2014-2017.The Nerdynaut. All Rights Reserved. A game-changing subordinate of Naut's Holdings.
Made in Sri Lanka.

To Top