Java - Intermediate All-in-one Tutorial #5
An all-in-one tutorial for the java programming language! With a complete working program you can run and examine the code and try to master java as well.
What To Expect:
For this tutorial I have right here, I will go over some knowledge on the java programming language. This is moreso from a course I took at University and I compiled all the assignments into one executable package for my own personal fun. I decided to share it because coding and creating new problems is easy as an assignment.
Here, most of the topics that will be covered in this java tutorial will be about objects, classes, instances, polymorphism, inheritence, generics, overriding, overloading, collections, maps, sorting algorithms, file input and output, recursion, interfaces, and writing nice comments.
Outline of Each Assignment:
Since this is from a class I took, I will briefly outline each assignment and what topic is was focused around. These assignments are related to the java package or program I will link below that goes to my Github. You may use any integrated development environment (IDE) you wish. I use NetBeans on a windows pc system. Here are the assignment outlines:
Assignment 1 -
This is more of a review on using basic java operators and understanding syntax. The program for this assignment is about generating random numbers for a super-lotto-style lottery ticket. The program also has user input using the scanner package.
Assignment 2 -
This is an assignment that goes over the basics of creating a class in java. We easily created a broad class for later we will create a subclass for this class. A class is basically a way of defining your own data-types by using already available primitive data-types in java.
Assignment 3 -
For this assignment we will use assignment one and implement writing to a text file. We will also appened to previous lottery ticket numbers to this text file. There is also a use of exception handling for our file methods just in case the program fails.
Assignment 4 -
Here in this assignment, we created a subclass from assignment two. Implementing a subclass is easy because all you have to add to the class is the extends keyword and then you can define anything you want for that sub class and it will also inherit from that base class.
Assignment 5 -
This one was about exploring arraylists and collections. Here we simply created our own method to print data of our objects that we created with our base class and sub class.
Assignment 6 -
For this assignment, we created our own interface, which is essential an abstract way of saying that these functions, when used onto a class, should be implemented in order to use it. Here we also override the compareTo method to be more specific and fit our base class and sub class created in previous assignments.
Assignment 7 -
Now we move onto different types of algorithms for searching, sorting, and learning the big O notation for determining search speeds and efficiency of an alogrithm. In this assignment we created a sorting method, a binary search method, and a recursive method.
Assignment 8 -
For this final assignment, we implemented either a hashtable or a hashmap. We get to practice with using key value mapping and storing our own objects as the value. In this assignment we also address chaining values to the same key and using a very simple hash function for our hashtable or hashmap.
The Source Code:
Again, I used NetBeans to write, compile, and execute my code. Here is a link to my GitHub where you can download all the files as a ZIP.
Now as a learning resource, I would suggest using Tutorials Point. However, if you get stuck, I good site (with an elitist community) is to check out StackOverflow. There you can find good people that could help you, but really programming is more of a trial and error type of thing. So if your code isn't working, just keep reading and trying different logic.
I don't want to take your time to explain some terminology, because the important thing about programming is if you have a logical way of thinking. Once you develop a logical way of thinking, and how you plan to solve the problem you are given, then it's just a matter of using syntax. This is true for any language you want to learn. On the other hand, if you want to know the important topics for becoming better at java from this tutorial, you should read up on classes, collections, sorting and searching algorithms, and maps.
As you can see, I made a seperate class that has test code, kind of like unit testing, for each part of the assignments I was given. This java file is the AssignExtend.java file, because I created seperate functions to run just for the speific assignment I was given to do. You can edit and add more things to any of these files, and experiment on your own. I will briefly touch on some java syntax and what I think and know about them in my own words (this is from memory).
Generics are when you want to pass objects or any parameter, but you don't know what type it is. When you use generics you will also have to make functions or set-up if statements to handle different types of data-types or your created objects. This is useful, because maybe you don't want to keep having to re-use a similar function that does the same thing, and by using generics, you can eliminate lines of code and be more efficient.
Exception handling is very important because you don't want your program to crash on the user. If that happens in real-life, someone could lose data, or even die! Giving your program, or letting your system know how to handle a crash is essential to the overall safety of itself and the user.
Searching and sorthing alogirthms are important. You will have to learn and master them because each algorithm has their advantages and disadvantages! Everything in life as an advantage and disadvantage (professors can't stress it enough to me)! Common searching algorithms are; linear search which searches each element in order one-by-one; binary search which searches elements from the middle first and divides going further down (good to use a key for searching); a hashtable or hashmap search which uses the key; and a binary-search tree which starts at the root and checks every subtree. For sorthing algorithms we have; selection sort, merge sort, insertion sort, and quicksort, which are self-explanatory really. You should also learn how to derive a big o notation from an alogrithm, since efficiency is what will get you hired (if you want a job).
Javadoc and comments are also important because when you pass your code to the next person they need to understand it quickly! This is important in an agile development for developers. By making good comments for your code, people can work on their implementation right away, instead of wasting and spending hours trying to understand why you put an if statement there. In NetBeans you can also generate a javadoc, which is essentially an API document about your package or program (just search it up).
I will continue to increase my programming knowledge and learn for it is my way of fun! I hope you enjoyed this short tutorial, have a fantastic day!
Comments powered by CComment