This module covers instances, classes, and debugging in Java.
This module covers instances, classes, and debugging in Java. It then discusses how to resolve errors by using test cases, typing in test conditions, and creating flow charts.
Learning Objectives
- Learn how to debug errors
- Learn about instance methods and instance variables
- Learn about class methods and class variables
- Learn the difference between instances and classes
Skills you’ll gain
DebuggingJava (Programming Language)Java APIsJava Code Coverage ToolsJava Development KitJava ModuleWhat You'll Learn
- Debug errors in Java using test cases, test conditions, and flow charts
- Identify and resolve logic errors in Java programs
- Apply instance methods and instance variables in Java
- Apply class methods and class variables in Java
- Distinguish between instances and classes
- Build programs using classes and constructors
Key Takeaways
- This module covers instances, classes, and debugging in Java.
- Errors can be resolved by using test cases, typing in test conditions, and creating flow charts.
- The course explains the difference between instances and classes.
- Lessons address instance methods and variables alongside class methods and variables.
- The course progresses from debugging and logic errors to classes, constructors, and a creation program.
Frequently Asked Questions
What does this Java module cover?
It covers instances, classes, and debugging in Java, including how to resolve errors using test cases, test conditions, and flow charts.
What will I learn about debugging?
You will learn how to debug errors and how to resolve them by using test cases, typing in test conditions, and creating flow charts. Lessons include Debugging Part 1, Debugging Part 2, and Logic Errors.
What does the course teach about classes and instances?
It teaches instance methods and instance variables, class methods and class variables, and the difference between instances and classes, with lessons on Classes, Constructors, and Instance Vs. Class.
What skills does this course help build?
It supports skills in Debugging, Java (Programming Language), Java APIs, Java Code Coverage Tools, Java Development Kit, and Java Module.
Is this course suitable for beginners?
Yes, it is a beginner-level Java module covering debugging, instances, and classes.
Transcript
Show transcript (free preview lesson)
Transcript of the free preview lesson. Remaining lessons unlock with the full course.
Welcome back to knowledgecity's course on programming in Java. I'm Cliff Brozo, I'm your instructor. And in today's lesson, we're going to learn about debugging a program. If you remember, this is the program that we just examined the one that involved the switch statement and the if statements and even pulling out the calendar month. In this program, I've inserted a bunch of errors that weren't there the last time we compiled it let's run it this time and see what happens. The first error that I get points to line 17 and down at the bottom, it says main.java 17 and it tells me that I made an error that it's not a statement. And the statement that it's interested in is scan.close. In this particular case, what we need to understand is that close is a function and all functions must end with an open and close parentheses. So the fact that it's not a statement is really meaning that I need to go in right after the word close and put in open and close parentheses. Now, the trick to debugging a program is to only make one change at a time. Even if you see things that are wrong, wait until the compiler tells you that you've made a mistake. If you make too many changes, you might wind up changing something that's correct and turning it into something that's not correct. So we make one change at a time. Let's recompile. It points now to line 52, and I go scroll down to line 52, and it says difference == your month - month + 1. In this error, we've got to remember that there is a difference between the equal sign and the equal equal sign. The equal equal tests for equality while the single equal sign puts a value into the left side of the equation. In this case, the only time that I would use a double equal sign is with an if statement or while statement in every other occurrence, I wanna use a single equal sign that I'm going to take the result of this calculation that's your month minus the month, plus one, and place it in the variable difference. And the way I do that is with a single equal. As we said, one change and recompile, Java line 66 says it's an error and it reached the end of the file while parsing. What's going on here is that I am missing a close curly bracket and the IDE tries to help us by putting these vertical lines in that help us line up these brackets. And if I follow this one all the way up, I can see that that close is corresponding to my public static void main String Args routine. Look in line four and I have an open and there's no corresponding close. So as the compiler was going through and checking all of the code, it reached the end of file. And it didn't find a close curly bracket. So I'll put one in and I think that I'm going to be done because there's only one error left, but I'm mistaken. I put it in and it still says the same thing. Hmm, this is an interesting thing because I just fixed that code and it gave me the same error. When that happens, you have to go back and look and check to make sure that all of your open brackets have corresponding close brackets. I'm gonna go up to the top of the program. I have one open, I have two opens, lines four and line six, line 23 has an open for the switch statement. And I follow these lines down and I see that there's no close for the switch statement. So Java doesn't know that, what Java knows is that there's just an uneven amount of close brackets. And it says I reached the end of the file and I didn't find the ending bracket. So I'm gonna put one in and once again, I think I'm done. Oh, no, I'm not. I fixed that one error and now I've got one, two, three, four, five, six, seven eight, nine, almost every line becomes an error. And here's where you start to panic. I've got 20 errors when I just had one. How does this happen? Well, the computer doesn't know the details of each line until it finishes going through the entire program, making sure that all of your routines are opened and closed correctly. So when it compiled last time and told me I had one error, I put that one error in and now it said all right, I'm gonna go in and look at every line individually. So that's now what we have to do. My first line talks to me and says, line three, public class main. Class main is public, it should be declared in a file named main Java. Well, this is an indication right here, main Java is an indication of what the files should be named. But in my case, I have a file named Main.java with capital M. So it's telling me that this M must be uppercase. So I'll put in a capital M. As I said, even though I know that I have 19 more errors, I'm going to recompile because one change could produce multiple errors. Now it brings me back to line one and it said, error cannot find symbol. And the little pointer here that says, this is where it got messed up. It was looking for a symbol the class of scanner. And in this particular case, well, I didn't spell scanner with a capital S and capitalization is important. I make that a capital S, recompile again. Now it's telling me, line 15 tells me that it can't find the symbol Scanner.nextInt, and it's looking and there is no such thing as scanner. I named my scanner scan, not Scanner. So the correct code is to say, Scan.nextInt.
Learn on the Go
Take your learning anywhere — the KnowledgeCity mobile app lets you watch lessons on the go.