Some questions people had in class #10

 

What does all this stuff do when I’m actually writing the program?

 

It is the foundation on which everything stands. We define our data this way. We get a lot of our work done by “calling” methods provided with different classes.

 

How do we use objects to start a program and how can we add on info to it?

 

Objects are fancy variables really – they keep track of info that we will use later. In declaring objects, we want to look for things that we will be wanting to keep track of. Frequently these may be nouns in a problem description.

 

Are some of these things really necessary?

 

I think so. Writing any programs in Java, you will need to declare, create and use objects.

 

Why can you put 3 different values after BankAccount?

 

It is basically a matter of “how many values are needed to create an object?” To create a BankAccount, we need an account number, PIN, and balance. To put it another way, when I wrote the BankAccount class, I wrote a constructor that requires 3 “parameters” – pieces of information. The constructor uses the info “passed” to it to create and initialize a BankAccount object.

 

Why does the String shortcut correspond to the same memory as the long version even though they are different characters?

 

The shortcut only saves us typing, they are translated into the same thing when the program is compiled. 

 

Should we use the shorthand notation for Strings, or is it better to type it all out?

 

You can do either. I would use the shorthand to save typing, but I type 10 words per minute. I think most people would use the shorthand. Just remember that it is just shorthand; Strings are still objects, not primitives.   

 

What is the big deal with constructors?

 

A constructor needs to run in order to create an object. The reason this is, is that objects frequently contain multiple pieces of information. Therefore a simple assignment will not do. For instance, in trying to create a BankAccount, an account number, pin, and balance are all needed. We cannot just create the object with BankAccount myAcct = “12345”,”1111”,0;

Because the system would not know what to do with the information (what is what?). We end up supplying step by step instructions of what to do – in a method – a constructor. And you know a constructor when you see one because it has the same name as the class.


In Java can you pretty much use any words you would like to associate with the program that is being written?

 

Well, first, there are several types of  words we might create – variable names, class names, method names. Each must follow the rules for identifiers – start with a letter (or $ or _) and all succeeding characters can be letters, digits, or $ or _. Given that we’ve chosen names, then we have to continue to use them consistently. If we declare a variable as totalTax, then wherever we use that variable we must use the exact same variable name. The same goes for class names and method names. 

 

Where does if and else fit in with strings?

 

They are independent. You can use if and else with any data type, including Strings.

 

What kind of code would be required to allow a user to enter info that would allow them to access a database and make changes, additions and deletions to that database.

 

That is a BIG question – two courses worth of info – three really if you count a course that explains how a database management software program such as Access, SQL Server, or Oracle would be written (we don’t teach that one). I encourage you to take CSC 264, plus the advanced one (372?)