How to Write Your First Java Program

Knoji reviews products and up-and-coming brands we think you'll love. In certain cases, we may receive a commission from brands mentioned in our guides. Learn more.
Java is a popular programming language that can be utilized with different purposes. For instance, it could be used for the purpose for creating applications and applets for web sites. This is going to be primarily focused on being able to get an unders


Java is a popular programming language that can be utilized with different purposes.  For instance, it could be used for the purpose for creating applications and applets for web sites.  This is going to be primarily focused on being able to get an understanding of how to create a sample program.

The difficulty level for this is going to be on easy as it is mainly focused on just getting started on how to go about learning this programming language. 


#1: Get a program that will work with Java code.  Recommendations would include either NetBeans or jGrasp.  Both are free programs that can be found online.

#2: A basic understanding of logic should help out quite a bit. 

#3: It would help greatly to know some programming languages especially when dealing with object-oriented programming.


#1: If you are familiar with another language like C++, you will notice that it has some similarities such as data type and some of the keywords.

#2: They are involved with having one class file per application.  The name of the class has to be the same name as the file.

#3: Constantly save your work.  It is very important to do that as you don’t want to lose anything important.  When writing a program and forgetting to save can lead to frustration as it would involve losing important data.

#4: Using NetBeans actually creates a .jar file once it’s been completed so it won’t be needed to reopen the program again.

#5: With jGrasp, however, there is no .jar file that is created.




#1: Open up jGrasp on your computer.

#2: Create a Java file.  Make sure that the name of the file is going to be the same name as the main class.

#3: Begin writing up your code actually.   See the example below.

That is an example.  You can create it any way you want.

#4: Save it immediately as it is going to be important.

#5: Compile the code.  If there are no errors, skip the next step.  Otherwise, go to the next step.

#6: Go back and correct any mistakes that were made.  It’s normal.  Go back two steps actually.

#7: Run the program immediately to make sure everything is correct.


#1: Open up NetBeans and give it a few minutes to load.  Depending upon your computer speed, it will make the difference.

#2: After it loads, create a new project and have it set to go to either your hard drive, flash drive, or an external hard drive.

#3: Create an empty project and add files.  For this purpose, you’re going to need one and it will include a main method.

#4: Begin writing your code.  A picture below will show an example of how to go about completing it.  You can create your own and have it a little bit different.

#5: Save your work immediately.

#6: Start building it.  Let it go through its process.  If there are errors, go to the next step.  If there are none, go to the final step.

#7: Any errors that exist should be corrected.  Sometimes it can be a simple spelling mistake or a syntax error.  After doing that, go back two steps and repeat the process.

#8: Run the program completely and make sure it is going to do so.  


It is just the beginning of completing a Java program.  In fact, this is easy but as time goes on, it will get more complicated as time progresses and learning new techniques.  Think of it as just getting your feet wet when working with Java for the very first time.  As far as what program to use, it’s up to you and is going to come down to what your needs are.


About This Article

Bruce Bostwick

Explore Top Programming Tools

GitHub Review Compare GitHub vs. top competitors See GitHub Coupon Codes Codeanywhere Review Compare Codeanywhere vs. top competitors See 1 Codeanywhere Discount Codes Coderbyte Review Compare Coderbyte vs. top competitors See 1 Coderbyte Coupon Codes Visual Lightbox Review Compare Visual Lightbox vs. top competitors See Visual Lightbox Coupons Proxyseller Review Compare Proxyseller vs. top competitors See 1 Proxyseller Coupon Codes Another Nike Bot Review Compare Another Nike Bot vs. top competitors See 1 Another Nike Bot Coupon Codes Codelobster Software Review Compare Codelobster Software vs. top competitors See Codelobster Software Promo Codes Review Compare vs. top competitors See 3 Promo Codes Install Aware Review Compare Install Aware vs. top competitors See 2 Install Aware Coupons WriteRoot Review Compare WriteRoot vs. top competitors See WriteRoot Coupons Reflective Web Hosting Review Compare Reflective Web Hosting vs. top competitors See 1 Reflective Web Hosting Promo Codes C++ Rocks! Review Compare C++ Rocks! vs. top competitors See C++ Rocks! Promo Codes Flashloaded Review Compare Flashloaded vs. top competitors See Flashloaded Promo Codes BNC Scripts Review Compare BNC Scripts vs. top competitors See BNC Scripts Discount Codes PostSharp Review Compare PostSharp vs. top competitors See PostSharp Coupon Codes MyXocai Builder Review Compare MyXocai Builder vs. top competitors See MyXocai Builder Coupons Deep Fried Code Review Compare Deep Fried Code vs. top competitors See 1 Deep Fried Code Promo Codes Top-ranked programming tools >>