Find online courses made by experts from around the world.
Take your courses with you and learn anywhere, anytime.
Learn and practice real-world skills and achieve your goals.
This course provides instruction through video lectures and materials which will teach (you) the student how to program in Java from the very basic level to an intermediate level of programming. The intent is to aid anyone who is struggling in learning how to program and would like to see practical examples and demonstrations. This course is not affiliated with any university and will not provide answers to any homework assignments for any reason. Topics covered will include but not be limited to:
In the end, this course is a stand-alone course, however it would be a huge aid to the online student who is taking a self-directed course, an individual who is trying to learn how to program, or even a high school student looking to get a head start on computer science material they might encounter in college. The material is organized in a start-to-finish fashion, building on knowledge with each section, so it is best to proceed through each section in order. Each section should amount to about a week worth of learning, lining up with most popular online course formats. Additionally, the course works hard to build practical knowledge that will help a student excel in their coursework, and also builds a strong foundation for a start to a career in programming for anyone looking to learn!
As an added bonus, several useful programs are built throughout this course, and the end result of the course includes full source code for a working Sudoku game, amongst other programs, such as card game score calculators and basics physics formula calculation programs.
Not for you? No problem.
30 day money back guarantee.
Learn on the go.
Desktop, iOS and Android.
Certificate of completion.
|Section 1: Introduction to Programming|
|This lecture is our course overview, talks about who I am as your instructor, some of my experiences and ultimately gives a guide on how to proceed through each week/section of the course. Additionally, the topics covered in the course are exposed so that everyone can easily see the information that will be discussed in our course.|
|This lecture is a quick introduction to programming. Essentially, we all want to get out of the gates and run as fast as possible. This introduction discusses some of the pitfalls with that approach. In the end, we need to commit to ourselves and give ourselves the time required to work through the material in a way that helps us to master it through each section. Learning to program is an investment, and like all investments, will take commitment in the form of time and effort. Here we go!|
This video takes us through the installation of the Java 8 SE SDK on our Windows 7 Machine. Please note that all code samples and examples also work with Java 6/7/8/+, so if you are installing Java for the first time, you should use the latest version of the Java 8 SDK. No matter what, your directory structure will be slightly different to reflect the version you installed, but it should not cause you any issues with the code. Whichever version you use, please make sure to continually update your version as prompted to maintain the best level of security with the Java installation.
This video walks us through setting up our windows machine to compile and run a program. For this video, you'll want to get the file "ManualCheck.java" and make sure to place it somewhere on your computer that is easy to access, such as the desktop.
Make sure to follow along with me in the video to complete the steps for manual programming, which make sure we are ready to go for writing java programs on our machine.
This video shows us how to write our very first program, the standard "Hello World" text printing program. Although we haven't covered syntax to this point, the program is simple and straight-forward.
Although we will have a working file 'HelloWorld.' by the end of this lesson, I am not including the file for download on purpose. This will encourage you to create the file on your own. Additionally, if you have any mistakes, you'll have to fix them. Hopefully you will find this a simple and useful activity.
Please note: If you are using the Java 7 SDK, you will need to select the default folder installation path for the Java 7 version you are on, instead of java 6. Use that path when working with the environment and/or manual programming to execute the javac compiler and java runtime executable programs.
In this video, we take a moment to purposefully break our helloworld program, thereby giving us the opportunity to see errors as they happen at compile time, and learn how we might respond to the errors. This demonstration also shows us how programming manually can be more complicated than programming with an IDE due to the feedback not happening as quickly when we make an error.
By purposefully breaking our code, we get used to seeing some errors that we might encounter later. The experience of having broken the code and seeing the direct result may help us to fix errors later when we encounter similar messages from the compiler.
Please note: You will need to select the default folder installation path for the Java version you are on, including the correct current update number . Use that path when working with the environment and/or manual programming to execute the javac compiler and java runtime executable programs.
This video shows a demonstration of installing the Netbeans IDE (which you may choose to use for the remainder of our course; old videos use this IDE, new will not).
After installation, we'll quickly create a HelloWorld project to make sure everything is working and see how a powerful IDE can be beneficial to any programmer.
This video shows a demonstration of installing the Eclipse IDE (which you may choose to use for the remainder of our course; new videos use this IDE going forward).
After installation, we'll quickly create a HelloWorld project to make sure everything is working and see how a powerful IDE can be beneficial to any programmer.
This video shows how to quickly create a project in either NetBeans or Eclipse. Going forward, the lecture resources [files] will be available as *.java files. Therefore, you'll be creating your own project and just importing the resource files.
The files attached for this video are actually going to be used in the next video as well, so this will give you a head start on setting up your project for the next video, and will highlight the idea of creating your own project to work along-side of me as we go through the lectures together.
|In this video, we cover some of the basic syntax for writing programs. In the getting started exercises we've already seen some of this syntax, however in this lecture we take a deeper look at what is required to make sure a program will compile, as well as learn a bit more about what is required to make a program run.|
|This lecture is a brief overview of printing output to the screen using three different types of printing. The first type is the println("..."), which we've already seen. The second type introduces printf -- or formatted printing, and the final type introduces the basic print statement. Most of our code will use either println or printf, but it is good to know about the print statement as well. Additionally, we take a quick look at using variables, by introducing the String type and setting a variable using Strings. We'll cover variables in more details in Section 2, so this brief introduction gives us a taste of what is to come.|
|This video gives us a "real-world" printing example. Additionally, the second part of this video dives into a bit more advanced printing options, introducing String.format and gives us a chance to recognize some patterns to make a better printing procedure.|
|Lecture 13||1 page|
All of the code for section 1 is contained here. Additionally, you should find the required code for each individual lesson attached with the specific lesson.
|Quiz 1||10 questions|
Quiz for the material in section 1
|Section 2: Programming With Variables|
|This video introduces us to types in Java. The concept of a type is discussed, and the main types we are going to use are described, with some computer science behind some of the numbers. The types covered and introduced are Integer (int), Long (long), Float (float), Double (double), Character (char), String, and Boolean (boolean).
This video is done on a lecture whiteboard, which can be difficult to write on at times so some of the handwriting may be a bit tricky to read.
This video is the first of two parts to discuss storing types in variables and working with the types in code.
In this video, we go over the Number types of Integer [int], Long [long], Float [float], and Double [double].
This is the second part of our introduction to types. In this lecture, we discuss the non-number types of Character [char], String [String], and Boolean [boolean].
In this video, we continue with coding examples for storing and using types in variables. This video focuses on the non-number types of Character [char], String [String], and Boolean [boolean].
This video starts our look at a couple of different methods for gathering input from the user. The first method involves using the java.util.Scanner, which makes it necessary for us to import the java.util.Scanner or java.util.* package. This video focuses on the use of the Scanner, and we'll mostly use the Scanner object in our course.
In this video, we take a look at another way to gather input - using the BufferedReader object.
In this video, we take our skills to the next level, using variables to store user input as types and then performing mathematical calculations with the variables. We then print the resulting calculations back to the screen.
In the second part of the video, we take our first stab at using the documentation to learn about a pre-built library, the Math class. Using the Math class, we have the ability to perform some common math functions for easily performing calculations without having to write these methods ourselves.
|This program takes what we have learned so far and starts to wrap it all together. Because we are still somewhat limited in our knowledge, we have to write each calculator as a separate program In the future, we'll be able to take more advanced skills and write a better version of this program that is more user-friendly and has the ability to allow us to choose which calculation(s) we want to run.
If you are taking a course and have an assignment due that does a simple input - calculate - output type of operation, this is a good place to stop and complete the program. If you need to take user input and make decisions or change the calculation algorithm based on the user input, you should continue on to week 3 (section 3) to gain knowledge of decision statements and loops.
In this final video for section two, we do another exercise in gathering user input as well as handling the input by storing it in a variable and then ultimately placing the information into the correct location in the Sudoku grid. Finally, we print out the grid with the user input correctly placed in the grid.
As stated in the video, the game is not playable at this point, nor is it intended to be. We are still learning from the ground up, and positioning ourselves to be able to build the game in a way that it can be played later.
The more we repeat these activities, the better we get at them, so practicing different exercises like this is a really good way to enhance our learning, even though it's just a short and seemingly trivial activity.
|This lecture is just the placeholder to contain the code used during section 2. Please download the code and use to enhance your learning for this week.|
|Quiz 2||10 questions|
This quiz contains questions relating to the section 2 material.
Section Two Resources
|Section 3: Control Statements and Methods|
|This video introduces us to boolean logic. The discussion relates the use of true/false statements and shows how certain mathematical comparisons can be used, as well as boolean variables to determine if specific code blocks should be executed. The introduction also discusses the 'And' and 'Or' operators and closes with a brief introduction to the syntax of the if .. else condition control statement block.|
|This video gives us our first solid look at using conditional control statements to execute certain code paths. By setting variables equal to a certain number, we can determine if certain code should execute based on the value of that number and how it is evaluated in boolean statements, such as less than, greater than, and equal to.|
|This lecture takes us deeper into control statements, showing the ability to nest control statements inside other control statements. Additionally, we take the time to look at using and and or operations to determine specific conditions that cause certain code algorithms to be executed.|
|This video is an advanced session. While it is completely possible to code without the switch and/or without using ternary operators, taking a good look at these elegant code solutions now will help us to be more familiar with them when it is time to start building advanced, robust solutions.|
|This whiteboard lecture gives us a solid look at the structure of methods, and demystifies some of the reasons for typing certain aspects of the methods we have been typing. The major parts of a method signature are identified and explained, and examples that we have already seen are used to help us relate to the idea of writing methods correctly.|
|This lecture session gives us a solid look at some of the benefits of using methods. For the first time in our coding to this point, we are able to separate some of the algorithms that are repeated or are easily isolated. By placing these code blocks into methods, we are able to make our code easier to read and understand, but also position ourselves to have the ability to more easily maintain our code in the future.|
|In this lecture, we adapt the simple physics calculator from section two to make it more robust using methods. In section two we had to have five separate programs, but in this section we can contain the entire code base for all five calculators in methods which are easily leveraged from one program. We also adapt the speed calculator to work for any of the three variables being unknown. As additional learning, a good idea would be for the student to take the code and adapt the other methods to work with unknown variables for a more robust physics calculator.|
|This video is our weekly (section-ly) enhancement to the Sudoku program. Here we implement methods to handle some of the gameplay functionality, separating building the board into smaller methods and handling user input in a gathering method that can be easily repeated. Although we still don't have a working game at this point, we are getting closer with each iteration of the development cycle.|
Sample Code for Section 3
|Quiz 3||7 questions|
This quiz covers lecture material from section 3
Section Three Resources
|Section 4: Loops - Repetitive User Input|
|Our first video this week discusses what a loop is, and gets us thinking about some practical examples of loops in our daily lives. Additionally, the video talks about three critical aspects of all loops:
|This video discusses the first type of loop: the "while" loop. Thinking about it, one could say something like "the loop will continue 'while' something is needed or something is going on. This is how the while loop is set out. Determine the starting condition (i.e. we need to gather input) and then while that condition is not met or is still going on, loop on the code algorithm, until the end condition is met (i.e. we have the correct input).
This video shows two simple loops, which illustrate a couple of different ways to set up the loop. Make sure to get the code at the end of the section to follow along and thoroughly read the comments in the code as we go. Throughout the section we are going to learn a couple of subtle things about programming as we continue to study loops, and build our skills as java programmers.
|This video presents similar information to the while loop video, however it demonstrates the use of the do...while loop in code. The key difference from a regular while loop is the fact that do...while loops will execute at least once, no matter what, whereas a while loop may have a case where it never executes. This is due to the fact that the while loop evaluates the condition and then iterates, and the do..while loop iterates and then evaluates the condition to see if another iteration is needed.|
|This video demonstrates the for loop, which is the last of the three most common loops we'll encounter. Although the for loop may seem a little tricky at first, it is actually very common and will become easy to use with practice. The best part about the for loop is everything is declared in one line of code for all of the three important aspects of loops.|
|This video reviews what we've learned so far by implementing validation on user input by setting up loops to check for bad input and continue until good input is received.|
|This video presents an advanced topic: Recursion. When starting out as a programmer, most likely you will not need to know how to do this, and most likely it will be a bit too difficult to just understand right away. However, recursion is an important component to programming in intermediate and advanced courses and work, so it is good to know about this topic and see it in action.
Recursion is shown in this video using the Fibonacci sequence, which is one of the most famous sequences.
|Our first PIAT lecture this section puts the information we've learned this week into action by upgrading our simple physics calculator.
This week we enhance the density calculations, adding both the ability to validate user input and also the ability to take any of the three density variables as an unknown and solve the equation accordingly. Additionally, all user input in the main algorithm is validated.
The challenge at the end of this lesson is to be able to finish off the rest of the calculators to prevent invalid input as well as to be able to take one of the variables as an unknown and calculate the equation accordingly.
|Our sudoku program this week continues to build on our Sudoku game. Although we will still be left wanting for a better game at the end of this lesson, the progress we are making is markedly displayed by the ability to alter some of the things we are doing in our code and seeing it all start to come together. We'll still only have the one puzzle in place, but by the end of this lesson we can at least loop for user input until it is completed, and validate user input along the way. Additionally, we discuss a couple of problems the program still has and note them as features for upcoming versions.
Lastly, as it is important to create a quick exit from the looping for our demonstration, we get to see our first Easter Egg programmed into our code, which allows us to know a "cheat code" to quickly and accurately solve the puzzle!
|It's time to take a step back and think. This video discusses the complexity of our programs and how they are getting more complex each section. Taking the time to plan before we program can be a critical timesaver, both in accomplishing the overall goal of the program and also by helping us to plan for traps such as bad user input, or special cases our program must handle.
In this lesson, we spend time planning the things we need to handle in order to build code to keep score during the card game 500. Special care is taken to validate input to gather the correct bid information and calculate the overall score for both teams after each round (iteration).
|Our last video this week is the implementation of the scorekeeper for the card game 500. This final program puts everything together from the week, as well as shows how planning before we program allows us to easily envision where we might have loops, if statements, traps such as bad user input, validation routines, and/or calculations to consider, either in the positive or negative direction.
Seeing it all come together in this simple, yet robust program, is a good way to close off the section and demonstrate our clear understanding of looping structures.
|Sample code for week four.|
|Quiz 4||8 questions|
This quiz tests knowledge on topics from section 4
|Section 5: Basic data structures (Arrays)|
|This first lecture of section five gives an overview and introduction to arrays. The type is described, and an example is discussed. Additionally, the syntax and common uses are shown in writing as we talk about how we would code for an array.|
|This lecture is the first encounter with arrays in actual code. Here, we take the knowledge we gained during the discussion in our previous lecture and apply it in code, building a couple of arrays, discussing common coding mistakes that programmers need to avoid, and seeing how to set values in the arrays, iterate the arrays, and get values from the arrays at each index or specific individual indexes.|
This lecture is our first real computer science discussion, as we take a solid look at the difference between how regular variables are only copied and used in multiple places of memory, thereby not being prone to referencing errors, while complex objects such as arrays (and classes next section) are referenced directly in memory. The by value types (ints, booleans, Strings) don't get changed in methods when they are passed to a method, however the by-reference types are just a memory pointer, which means the same object is "referenced" and therefore, the changes made to a referenced object in a method actually affect the object that was created in the calling method as well as the object inside of the called method.
As an update to this, I want to point out that there is actually no such thing as "Passing variables by Reference" in Java. In fact, everything is passed "By Value." What actually happens is the variables for complex types are passed as By Value pointers that point to the address in memory of the complex types. This is why we see some behavior where complex objects are modified when the variables are passed to a method. For more information on this, please see this video that I did for O'Reilly:
This lecture is a quick discussion of a new looping type: the enhanced for loop. Essentially, for object collections and arrays, the Java programmers have given us a very quick and easy method to access each item in the collection or array. Since the length is pre-determined, the code is capable of iterating based on a "for...each" type of syntax. This is a short lecture, so don't skip it.
|In an earlier lecture, we discussed the perils of passing an array to a method and the problems that could result from the method changing that array (by reference). Additionally, array size is 'immutable,' which means that we can't change an array size without creating a new array. This often results in the need for copying the array in order to "expand it." Therefore, we examine the perils of directly copying an array, setting up a referencing issue, and then how to make sure our arrays are not referencing one another when doing a copy operation, using the .clone() method and Arrays.copy().|
|Another common issue with any data is that it needs to be sorted. Additionally, there are always multiple ways to go about anything in programming. In this lecture, we examine a sorting algorithm called "insertion sort" and use it to manually sort our array. It's always a good idea to know how to do things ourselves, in case we need to do some custom actions. However, when doing a simple sort, it is easier and safer to leverage built-in functionality. Java has provided us a method in the Arrays static class, which is Arrays.sort(). The second half of this lecture shows how to easily leverage this method to sort our array.|
|This "Putting it all Together" lecture is a bit longer than I had intended it to be. However, to this point we hit the basics of working with arrays. In this lecture, we start trying to classify a group of Federation ships, their name, designation, class, and commander. Using this information, we are able to thoroughly discuss some of the perils and traps that we fall into when using arrays in our code. There are options that seem to be right, but this lecture helps us examine why they are not the best way to do things. Additionally, the last part of this lecture shows us an advanced topic: Splitting Strings. There are two methods to split a string, and this method is the easier method to understand but the more difficult one to use. When a String contains a delimiter, we can easily split the terms back into an Array of String objects. This is how we determine the best way to work with our data is to create a concatenated string with a pipe delimiter, and put that entire String into one index in the array, allowing for sorting and guaranteeing that our record data is not accidentally mixed up.|
|Our week five take on Sudoku allows us to remove over 1200 lines of code from the game! Now that we have a structure that can store out data (a Multi-Dimensional 2-D array), we can actually do a lot of the work via iteration. We can use the .clone() method to quickly reset our game to the solved condition, and now we can remove all of the string references to individual slots (i..e zeroZero, zeroOne, zeroTwo) and can directly reference any slot in the grid by its row and column coordinate. Two challenges not covered in this lecture that you could do for practice include writing a quick method that checks an entire row or an entire column to see if any numbers are repeated. If the number is repeated, notify the user that their input is invalid. If not repeated, allow the input. The other challenge you use to test yourself would be to create a method to print each individual line as a single string and store each of these lines of data in a single-dimension String array. The String could be pipe-delimited for every number, or you could get even more advanced and do a nested delimiter operation, where you first Split on "|" and then Split each of those results on ":".|
|Use this link to download all of the sample code for week 5.|
|Quiz 5||9 questions|
This quiz is tests knowledge on topics from section 5
|Section 6: Object Classes and Basic Inheritance|
|This video is a written-lecture where we discuss the nature of using classes in our code to model objects. Each class inherits by default from the java class Object, which means that everything we create as a class is also an Object. In this lecture we go over the intricate parts of class structure, and show (in writing) what is required to program our own object classes.|
|This lecture gives us an overview of using UML modelling for discussing and determining what classes and capabilities our systems have. While you probably don't need to understand UML in a basic course, it may help you to keep your system straight to write out the model before actually coding. Additionally, when you program in the real world you'll need to be able to understand how to use models to build your classes, and how to read models to understand the capabilities of larger systems.|
|This lecture returns us to live coding, where we start from the ground up and create an object class to model a Car. With the car, we create and examine the use of the default and the explicit constructor. Additionally, we expose four properties of the class for Make, Model, Year, and Miles. We show how to work with the car object in a driver class using either constructor, and examine in detail what happens when the toString() method is called without being overridden (which we will show how to do in the next session). This lecture is a bit lengthy, but incredibly valuable. Please make sure to give this lecture a full view to make sure to not miss out on any of the intricacies of creating a class.|
|In this lecture, we continue our live coding by building an override on the base class Object toString() method. This allows us to directly print the details of the car by leveraging the toString() method, which eliminates the issue with only displaying the hash code as encountered in the last lecture. Additionally, the intricacies of how to override a method are discussed, including the definition and explanation of a method signature, and how to make sure our new methods directly match the signature of the original method.|
|This lecture continues our live coding exercises as we learn about what it means to "Overload" methods. We spend some time examining the differences between Overriding and Overloading methods, so that we can be sure that after this lecture is complete we have mastered the two topics and would be easily able to discuss the differences between the two. In addition, we use what we learn about overloading methods to build some overloaded options which would allow us to accelerate our car objects in code and have different return types or different input values for performing acceleration.|
|In this lecture we spend time discussing the benefits of using a common class to store some static constants and functions. We also approach the important topic of coupling, and discuss why it's important to keep our classes decoupled from one another. We finish the lecture by examining how to access our static constants and methods in our main driver program.|
|This lecture introduces us to inheritance. When we desire to build complex objects that inherit from base objects, we use the "extends" keyword. This lecture shows how we can put most of the "Car" functionality into a class called "Vehicle" and then extend Vehicle in Car. Additionally, common pitfalls are discussed that most students struggle with, including the proper way to access the superclass constructor and variables, as well as discussing the chain of inheritance and how more-explicit objects have more capability. The lecture concludes with discussion of casting types from a less-specific type to a more-specific type in order to access the more-specific properties.|
|This lecture is our "Putting it all together" lecture, where we see another example of using the concepts we've learned during section six to improve upon our Star Trek ship management program.|
|This lecture wraps up our learning for section six by rebuilding the Sudoku program using classes to abstract different aspects of the program. Because the generation algorithm for the puzzle is so complex, it is included in the program but we are not covering the techniques for generating a solution and pulling out numbers to create an active puzzle. The code contains a link to the original article containing the source as well as briefly mentions the "dancing links" algorithm that is commonly used to generate solutions. This week we complete the game's basic functionality, and now have a working game with validation and generation that allows for random puzzle generation and the ability to complete the Sudoku puzzle.|
|This is the code for section 6.|
|Quiz 6||9 questions|
This quiz covers material from section six of the course.
|Section 7: Abstract Classes and Interfaces|
|This lecture gives us our first look at interfaces. Using a new system that contains vehicles, we are able to build an interface to define all of the common properties of vehicles, and then implement the interface in three classes, Car, Truck, and Motorcycle. By using the interface, we are able to examine how the objects can be used together in the basic data structures of array and ArrayList, thereby examining our first look at polymorphism.|
|This lecture introduces the concept of the abstract class. One use of an abstract class can be to hold common information for all of the subclasses that inherit from the abstract class. Like an interface, abstract classes cannot be instantiated, however objects that inherit from the abstract class can be instantiated to the abstract class type. This allows us to move all of the common Vehicle interface methods that had duplicated code in the Car, Truck, and Motorcycle into the abstract class. Additionally, this lecture goes into some detail about implementing multiple interfaces or extending the abstract class and implementing additional interfaces. We'll first move all of the common code for the subclasses into our common abstract class "VehicleBase" and then we'll add another interface called "FourWheelDrive" which we'll implement on the Truck object. Finally, we show how to cast the object back to the correct type in order to get to the specific property of 'IsFourWheelDrive.'|
This lecture begins our Putting It All Together lesson for section 7. For the first part, we'll build a class to manage vehicles as a system with the ability to find, add, and remove vehicles from the system. We'll also look at figuring out how to identify a few pitfalls and examine a few strategies to prevent the user from causing errors. For the system, we'll use the concept of polymorphism, and therefore the autolot will be coded to the interface, not to some specific type (for example, we only have one add method, not one for each type of vehicle, but one that handles all types of vehicles).
This lesson completes our examination of the autolot system. In part two, we build the driver (which is a console-based GUI) to interact with the autolot system. We discuss how this style of coding has helped us to build a system that allows us to reuse the Autolot code in other GUIs when we have learned how to work with them (such as websites).
This lesson takes a look at the Starships that we were building in section 6. In this code, we learn how to implement the comparable interface so objects can be compared (which allows for sorting). Additionally, we discuss overriding the equals() method so we can easily call to the .equals() method to compare objects for equality.
This lecture covers an advanced topic -- the Strategy Design Pattern. This is a simple introduction, but gives us a new idea to consider when coding: Coding a behavior. To this point, everything we've coded has been a tangible object. By coding behaviors, we can interchange behaviors in our code without having to write separate classes. We dive into this and build two behavior interfaces, one for propulsion and one for weaponry, then we implement three propulsion behaviors and two weaponry behaviors.
Please note that if you are taking your first course as a programmer this topic will probably be beyond the scope of the course you are taking. I am assuming, however, that most all of you taking this course will be continuing on to harder courses as well as pursuing programming as a career. Therefore, you will most likely encounter this idea in the future. If you don't need it for your current course, keep it in the back of your mind, because it will be good to know, even if you never need it for a course.
The final lecture for section seven makes a couple of critical changes to the Sudoku program. The overall algorithm for the code and gameplay is not changed, however we add in a system called GameSystem that will ultimately allow us to have 10 games, with Sudoku being one of them. We create an interface for Game and implement a GameShell abstract class to handle the common code. Sudoku extends GameShell which makes it also a Game by default.
In this lecture we also create a player object to track common properties for players of all the games in the game system.
We then change the Sudoku code to no longer reference the main method and ultimately implement the code in the play() method, as well as to have one player object to track the Sudoku player.
Please find the code for section 7 attached.
|Section 8: Testing with JUnit|
This video is the first part of two parts of an introduction to testing. In this part, we go over some of the major arguments against testing and talk about how testing is actually very important, even if there is a bit more work up front.
In this video, we conclude our introduction to testing by discussing some testing strategies and the unit testing methodologies. We also look at the different assertions and how we'll use assertions to pass or fail the unit tests.
In this video, we go over creation of the unit tests in Eclipse and start our Person object and testing on the Person object, working from the ground up. After we get the test class and JUnit libraries in place, we begin our testing by testing the Person class constructors.
There are two sets of files for this video. The starter pack and the finished code. I highly recommend starting with the starter pack and working along with me. If you get stuck, there are some text files that contain finished versions of the code in both projects. If you are pressed for time and just want to review, or if you have completed the video and want to check your work, take a look at the finished version to compare results or see the end result of this part of the project.
In this video, we continue our look at testing by adding the tests and then coding the accessors (getters) and mutators (setters) for our Person class instance variables.
As before, there are two sets of files for this part of the project. I again recommend using the starter pack and working along with me. The finished version is there for your convenience as well.
In this video, we continue testing our Person object by writing the tests to verify the toString() method is working as expected.
We'll just verify toString() contains our expected property values using the contains method of the String class. If you need to do more thorough testing, like validating a specific format, you could do that here as well.
As before, there are two sets of files for this part of the project. I again recommend using the starter pack and working along with me. The finished version is there for your convenience as well.
In this video, we start our examination of how we'll go about testing the Comparable interface, which will implement in the Person class. This method can sometimes be tricky to implement, so we'll take some time planning before we get started. Some good things to think about will be what inputs can be sent to the method, what specific values we want to return, and what the order of precedence will be for determining if one person is greater than, less than, or equal to another person.
Comparable is an important interface to implement when we are going to be ordering objects. It is very conceivable that an object like person would need to be ordered by last name, then first name, and sometimes we'll care about age as well. We take all three into account in this class.
Please find the planning spreadsheet and pdf/Word Document that I used attached to this video for your reference.
In this video, we go over the implementation of the Comparable interface and take the time to work through some of the testing. The amount of testing needed would go far too long for the video, so a set of instructions exists that allows you to follow through with creating all the tests and learn more about the TDD process.
As with the other testing sessions, I recommend getting the starter pack and working through to the end. The finished code is also available for you to review.
In this video, we take the time to discuss how the equals method works, and how we can override it and test it in our Person class. Once again, we'll benefit from our grid that helps us see which cases we really need to focus on for comparing to determine if two Person objects are equal.
In this video, we go over the coding and testing for overriding the equals() method in the person class. Once again, we use our plan to determine that all code paths are covered and that the method is working as expected with valid testing.
This lecture describes an advanced testing concept: abstract testing. In this lecture, we convert the Person class to an abstract class and then use that as a base class for three other class objects. We then show how we can leverage abstract testing using the factory design pattern to create a base test class that tests common function and is leveraged in the sub-test classes. This is an advanced concept which may not be needed as an introductory programmer, but I want to make sure everyone is aware that this possibility exists.
In this lecture, we create testing on our AutoLot system. We again use some abstract testing, however you could just continue to unit test each class individually if the abstract testing concept with the factory pattern is too complex at this time. The testing helps us to iron out a couple of bugs that existed in the AutoLot code, and is our first chance to see some real good testing where we have a full system that needs testing other than just basic class object testing.
The final lecture for section 8 gives us the ability to see some testing in action in our Sudoku class. Some of the class is left untested due to the complex nature and the amount of time it would take to write the tests on the classes. Additionally, this is the only version of the testing where we leave the default Netbeans testing syntax in place (not using the extension of Junit and leaving the @Test directives in place in the code).
Sample Code for Section 8
I am an experienced .Net developer, certified as an MCSD .Net in C#.net. I have a masters of science degree in computer information systems, and a bachelor of science degree in computer science. I also have many years of experience instructing college courses online in SQL databases, C#/VB .Net programming, java programming, and Microsoft office technology. I have created many online technical training courses that can be purchased here or on other various platforms like O'Reilly/InfiniteSkills, and my own site at training MajorGuidanceSolutions