Thursday, June 6, 2019

So you want to program with Java?

You feel ambitious. You know it's time to learn something new. You have a desire to learn some form of programming and heard that Java would be an excellent place to start. If this describes you, then you'll want to read on and learn a little more about what Java is and how to set up the coding environment and write your first code.

Let's take a moment to discuss the type of programming language that Java is, OOP. OOP, or object-oriented programming, is a programming language that uses "objects" to represent real-world objects or abstract concept. The objects are used to tell the program what to do and how to do it. Consider a car as an object. The car consists of properties (Color, interior type, etc.) and methods (start, accelerate, stop, etc.) After a programmer has created an object, that object can be used over and over again and should any information need to be changed, the programmer can make the necessary corrections to the object without having to search the whole code and make adjustments.

There are four major principles of OOP. They are encapsulation, abstraction, inheritance, and polymorphism. I'm going to explain in laymen's terms what each principle is and share a link to a video that I found helpful, which explains the four principles in greater detail.

Encapsulation - Data are bundled together with the Methods that use said data.

Abstraction - The intimate details of the code are hidden from the user, allowing them to see only the interactive parts.

Inheritance- The idea that an object can inherit the properties of another object.

Polymorphism-A single object can be used in different ways.

For a more in-depth look at these ideas, check out this video
https://www.youtube.com/watch?v=pTB0EiLXUC8

Now that we have a basic understanding of an OOP, we need to install Java so we can write our first code. Instead of listing the instructions, check this video out.
https://www.youtube.com/watch?v=yX-qG2Ooqzk
The video explains how to install the newest version of the JDK and Netbeans. The JDK is the heart of Java and Netbeans is your development environment, where you'll code your programs. Once installed, it's time to write your first program!

The first step is to create a new project.



After creating the new project, we need a name! Name the project whatever you fancy, just make sure the "Create Main Class" IS selected.



Once you select "finish," you'll be brought to the coding screen. There's really no reason to worry about much on the screen, the only important part right now is where your code belongs. You'll need to place your code after the comment, // TODO code application logic here. The code to print your first line is very easy.

System.out.println("Hello World!");


Once keyed in, you'll tell the computer to run the program by pressing the green arrow on the top action bar. In just a few moments, you'll see your first line printed out!


Congratulations! You've written your first program! Now it's time to get out there and make mistakes, break the program and learn to be a Java master!!

Good Luck!!

No comments:

Post a Comment