Are you new to programming and do not know how to get started? I felt the same way but recently discovered some helpful ways to get started. Java is an object-oriented programming (OOP) language. It is versatile in that it utilizes the Java Virtual Machine to be platform agnostic, making it unnecessary to compile code separately for Windows, UNIX, Mac OS, among others. It is currently used to develop desktop apps, games, and mobile apps.
An OOP views real-world objects as things with a collection of states and behaviors. Objects of a similar type or properties are grouped into classes. For example, Cats are a class, and lions, tigers, and tabbies are types of cats that can be created as objects from that class. Examples of states of the cats’ class included size, breed, awake, and sleeping. Examples of behaviors of cats are meowing, roaring, going to sleep, and waking up.
By creating a class in OOP, the need to repeat code is reduced, as it creates a starting point for building objects. The class can be passed around in the system to improve modularity. It can also protect code by hiding the source code when a class is called upon.
Getting started is easy. First, download the Java DevelopmentKit (JDK) and install it on your computer. Once installed, you may need to update your ‘Environmental Variables’ to include the path to your Java installation. On a Windows 11 operating system, this can be done in the System Properties on the Advanced tab as shown in Figure 1. For the Path variable, add the file path to the bin directory of your Java install. For example, C:\Program Files\Java\...\bin.
Figure 1
Environmental Variables for Windows
Once you have installed the JDK, you can create your first program using Notepad or another text editor application. Copy the following code into Notepad:
public class HelloWorldProgram {
public static void
main(String []args) {
System.out.println("Hello World");
}
}
Save the file and name it “HelloWorldProgram.java”. Program languages are like other languages, where they have rules that define proper syntax. Take note that the code above is case sensitive, and changing the case for the class and file name can prevent your program from running properly.
Now that you have saved your program file, it will need to be compiled. To do this, open a CMD prompt and change the directory to where you saved the "HelloWorldProgram.java" file, then run “javac HelloWorldProgram.java". This will create a new .class file in the same directory. Next, enter the command “java HelloWorldProgram” and press enter to run your program. The result should output “Hello World” in the CMD window if you were successful.
There are additional tools for more advanced programming, such as using an Integrated Development Environment (IDE) like NetBeans. Tools like these can help test and debug your programs as you create them. Additional tutorials and instructions to learn more about programming with Java can be found at TheJava™ Tutorials and Tutorials Point.
Happy programming! I encourage you to share your programming experiences in the comments, and I look forward to reading about what you have created.
No comments:
Post a Comment