Home > Articles > Programming > Java

Writing Your First Java Program

  • Print
  • + Share This
  • 💬 Discuss
This chapter is from the book
Rogers Cadenhead shows you how to create, save, compile, and test your first Java program. You'll even get to do some basic debugging.

THIS HOUR’S TO-DO LIST:

  • Type a Java program into a text editor.
  • Organize a program with bracket marks.
  • Store information in a variable.
  • Display the information stored in a variable.
  • Save, compile, and run a program.

As you learned during Hour 1, “Becoming a Programmer,” a computer program is a set of instructions that tell a computer what to do. These instructions are given to a computer using a programming language.

During this hour, you create your first Java program by entering it into a text editor. When that’s done, you save the program, compile it, and test it out. Then you break it on purpose and fix it again, just to show off.

What You Need to Write Programs

As explained in Hour 1, to create Java programs, you must have a programming tool that supports the Java Development Kit (JDK) such as the NetBeans integrated development environment (IDE). You need a tool that can compile and run Java programs and a text editor to write those programs.

With most programming languages, computer programs are written by entering text into a text editor (also called a source code editor). Some programming languages come with their own editor. NetBeans includes its own editor for writing Java programs.

Java programs are simple text files without any special formatting, such as centered text or boldface text. The NetBeans source code editor functions like a simple text editor with some extremely useful enhancements for programmers. Text turns different colors as you type to identify different elements of the language. NetBeans also indents lines properly and provides helpful programming documentation inside the editor.

Because Java programs are text files, you can open and edit them with any text editor. You could write a Java program with NetBeans, open it in Windows Notepad and make changes, and open it again later in NetBeans without any problems.

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus