Programming is an expanding field with many growing employment opportunities. The Bureau of Labor Statistics estimates that job growth in the field will be around 8% and see an employment growth of around 28,400 by the year 2022 (“Computer Programmers”). But being a beginner at programming can be daunting. Seeing an advanced programmer’s thousands of lines of code can be intimidating if someone is just starting to understand the basics of a programming language. But as with most large tasks, it’s best to start at the basics and slowly grow your knowledge of the subject with your experience.
“Programming languages” can be considered an overarching term comprised of multiple smaller portions, similar to how the terms “Movies” and “Books” can be broken down into smaller genres like horror, action-adventure, or drama. One of the most basic and accessible genres of programming languages to begin in is Java. Java is a general-purpose programming language that was developed by Sun Microsystems in the mid-1990’s. Most computers and most operating systems can run Java programs without any trouble (“Is Java Accessible?”).
The best way to fully understand the basic conventions of a Java program is to begin creating one and, step-by-step, understand how each small part of a program makes it work as a whole. However, to begin developing a program with the Java language, you’ll first need an Interactive Development Environment (IDE). This will be the software that you’ll write and save code in. The first major task to overcome in programming is getting accustomed to your IDE of choice. If you plan on creating programs, you’ll first need to understand your IDE’s basic functions like creating new projects and classes. Creating a new project will just create a space for you to program in, similar to starting a new document in Microsoft Word. Creating classes has much more of a purpose however it’s not necessary to understand the intricacies of this process as a beginner. It’s only necessary to know that each program you make needs to have at least one class for you to write your code in.
Once you’ve created your first project and class, you’re ready to move onto the next step towards developing a program. Here is where you’ll need to create your main method. The main method is where your code will start being read once your program is executed. And again, for the purposes of a first program, one does not need to understand every aspect of a method. Generally, the main method won’t change and more than one will not be needed until you move on to more advanced levels of programming. But unlike creating a project and class, which can generally be done by clicking buttons in the IDE, a method has to be manually typed in by the programmer. There will be two braces following the name of the class you created. You will create the method within these braces and then all of the code for your program will go between the braces following your method. What actually needs to be typed to create the main method is public static void main(String[] args) (“Lesson: A Closer Look at the ‘Hello World’ Application”). At this point your program should look similar to this:
public class PracticeProgram{
public static void main(String[] args){
}
}
Make sure to pay attention to capitalization, spacing, indentation, and parenthesis placement when writing in any programming language. Just like any other language, Java follows syntax rules. The best way for you to familiarize yourself with these syntax rules is simply to practice the language and pick up on the rules through first-hand experience and experimentation.
After the main method is in place you should have a foundation for writing your first basic program. This is the point at which a programmer would ask him or herself “What do I want my program to do?” In the professional world, a programmer would generally have some kind of prompt or specific task assigned to them that needs to be accomplished by their program. For example, a prompt for this program could be, “Create a program that displays the following message. Use at least a single variable:
Virginia Military Institute
Class of 2018
To accomplish the task presented by this prompt, a programmer would normally try to break down the problem as much as possible and work on the program piece-by-piece, if possible. The first piece that a beginner should take notice of is the fact that the prompt asks the program to output text. To output text in any form using Java, you’ll need to call your first method (while continuing to pay attention to syntax). Specifically, the System.out.println() method (“Formatting”). Calling this method is as simple as typing it between the braces of the main method:
public static void main(String[] args){
System.out.println();
}
Take notice of the syntax used when this method is called. Aside from the case sensitivity and parentheses, it’s important to notice the semi-colon at the end of the code line. In Java, semi-colons are a convention that functions similar to how periods function in the English language. They signal the end of a statement in the program. For now, a semi-colon will be at the end of most statements just like how a period would end most sentences.
Now that the method was called, you have the ability to output text. The method is utilized by typing the text that you want to be output inside of the parentheses following it. The text that you’re outputting should be placed within quotation. Anything placed within these quotations will be printed exactly as it is. If it’s not in quotations, Java will think that you’re trying to call methods or variables. Since the first line of the text from the prompt was “Virginia Military Institute”, that’s what needs to go between the parentheses (quotations included):
public static void main(String[] args){
System.out.println(“Virginia Military Institute”);
}
This code should output the first line of the text that was presented in the prompt, fulfilling half of the stipulations. To fulfill the second stipulation, you’ll need to output a second line using at least a single variable. This new line of code will be also be started by calling on the System.out.println() method. At this point, we’ll also need to be thinking about what’s going to be used as a variable.
There are several types of variables that can be identified in Java. But some of the most commonly used variable types are int, double, and boolean. Each of these variable types represents something different that the variable will be enabled able to do upon declaration. For example, the int type will mean that the variable can be an integer; the double type indicates that the variable will be a number with a decimal. Boolean variables will check if a variable is true or false and actually output the corresponding result. There are many other less commonly used variable types in Java that become more useful for larger projects.
For this program, since we’re specifically asked to provide a variable, the only variable type that’s really necessary is int. We know this because there are no decimals that will be in the text output, which requires a double type, nor is there any need for truth evaluation, which requires a boolean type. The number we would want to set as the integer is the only one in the prompt’s text: “Class of 2018”.
To set “2018” as the variable, it needs to be declared. You do this by typing “int [VariableName] = 2018;” The variable’s name has no effect on how the program functions. Just as in math, the actual name of the variable has no bearing on its value. It can be called anything, with a few exceptions (Java does have a syntax rule that prevents declaring a variable name starting with any numbers). If possible, also try to type all variable declarations at the beginning of the main method. Another convention of Java, and all programming languages, is that all lines of code are read sequentially. So this presents a problem (as well as an error) if the program tries to read a line of code that uses a variable before it has read the line of code that declares said variable.
Taking into account all of these rules, the variable declaration should look similar to this. For the purposes of this program, the variable could be named “ratMass”:
public static void main(String[] args){
int ratMass = 2018;
System.out.println(“Virginia Military Institute”);
System.out.println();
}
Completing the program and meeting all of the stipulations of the prompt now simply requires using the System.out.println() method to display the final line using the variable:
public static void main(String[] args){
int ratMass = 2018;
System.out.println(“Virginia Military Institute”);
System.out.println(“Class of “ + ratMass);
}
Since the variable “ratMass” wasn’t inside the quotations, it will output its value (rather than outputting exactly as the word “ratMass”) which is equal to 2018. The plus sign inside of the System.out.println() method concatenates the two portions of the output rather than serving any mathematical function (“Formatting”).
This final step should complete this basic program. Once the program is compiled and executed, the output should display exactly what the prompt indicated. It should also be a small glimpse into the many unique conventions of Java that can be found in even the most simplistic programs. As one’s understanding of the Java programming language expands, so too does one’s knowledge of the various quirks and rules that makes Java its own genre in a sea of programming languages. The same can be said for all other programming languages. Each one has unique properties that define them as their own genres.
Works Cited
“Computer Programmers” Bureau of Labor Statistics: Occupational Outlook Handbook. U.S. Department of Labor, 8 January 2014, Web. 10 October 2014.
“Is Java Accessible?” Accessible Tech. N.p. n.d. Web. 10 October 2014
“Java Method Calling” Home And Learn. Home and Learn, n.d. Web. 10 October 2014
“Formatting” Oracle: Java Documentation. Oracle, n.d. Web. 10 October 2014
“Lesson: A Closer Look at the ‘Hello World’ Application” Oracle: Java Documentation. Oracle,