Java - Super Basic Tutorial #1
This is a super tutorial for Java which will cover most data-types, simple loops, and some functions based off a course (but from my memory) I took at University.
This isn't really a tutorial, but more of a inside view of what Java is. Java is a programming language that communicates software to machine language to your computer. There are many application that use Java, but if you didn't know, Java is actually an extremely vulnerable language. Find more about it here. In this article I will go over basic functions and go over simple syntax of Java. I do recommend you learn Java from The New Boston. Below is one of of my console applications I coded for one of my homework problems in the Java course I'm taking. The IDE I made the program in is NetBeans. Before you check the code, it would be a good idea to familiarize yourself with data types, primitive data types, a few of the basic input and output functions, and how Java handles doing arithmetic.
Although I will assume you know how to read some syntax of Java, I will cover a few basic knowledge. Primitive data-types such as int, char, boolean, byte, float, double, short, and long are the basic data-types you will use for initializing variables to use for your program. Java also has loop logic, such as for, while, and such. The different things about Java on why it's popular is that is was an object-oriented multi-cross-platform language. Java programs could be executed from any machine as long as it had Java on it. It was really one of the first of its language due to being able to understand, rather than lots of code such as C and C++. Not only that, but Java has many libraries you can utilize in your program. The basic logic and syntax of Java, should not be over thought, as when you write the code, it's almost like writing English, but just with more variables and numbers. Try creating a simple if statement by checking if a user input is a number or a letter.
We will look over this code that I typed for a homework assignment.
If you looked at the code and were able to figure some of it out, then you will enjoy coding. This program is actually an optimization program, that will find the best length of fence you should use give how much length of fence you can use. It calculates the perimeter and area, and based on that will give you the best length and width to use. In Java, it is class and object oriented. There are actually a ton of libraries with pre-defined functions you will use all the time. In this particular program, I ask the user to enter numbers. I then parse them into a string so I can use it for the calcBest method. Why would I do this? It's all about design. The reason I did this, was so I am able to return the length and the width as a string format to the user. If I didn't do that, it could only return one thing. What parsing is, is basically like a filter. A great example is a water filter. The user gets water from a lake, but you don't want the impurities, so the filter takes care of that and you are left with the delicious water. It's the same with parsing. The user input, if you have noticed, is encapsulated by a try catch statement which will return an error if the user inputs garbage. In this case, anything that's not an int, which is a whole real number, will return an error. I added that because I don't want the program to crash once it gets to the method. I could have added more bug-fixing code, but maybe you can do it for yourself to learn. Once it goes through the calcBest method, you get the answer and that's the end of the program. In this program, we have a sub-routine that calls a method, so that's a great practice, but not really an efficient one, since the machine will have to look for it. That's because, if we did it all in the main function, the machine wouldn't need to find what we are referring to when looking for the function. Hopefully you can analyze this code and learn from it. This may seem more advanced than your usual tutorial, but if you want to actually make a program/software that's applicable, you need to learn from the hard material, because it will be more beneficial.
I know this tutorial isn't that basic, that's why it has super in the title, but hopefully you were able to grasp some aspects of Java. If there are errors or I didn't make sense or made a mistake, feel free to leave a comment.
Comments powered by CComment