Advanced Topics

These topics are extremely advanced, have many books written on each one alone, and you can usually find college classes on some of these. I'm not going to explain here how you use these, but mainly what they mean, and why you need them.

Exception Handling: The purpose of exception handling is to enable that when something out of control goes wrong, that the program does not crash, by either righting itself, or at least if necessary, by dying gracefully. A well used example is the following. You ask the user to type in a number. The user types in "8d7r". Your program tries multiplying this number, and can't. If you did not have exception handling, then the program would crash. What else is it supposed to do. Therefore you use exception handling and say like this. "If anything between (lets say) lines 25 through 78 cause an error, instead of crashing, run this fixup code". This is known as a try catch block. You tell the computer to try to do lines 25 - 78, and catch the following errors. If the computer does catch them then it should do the following to fix it. In my case you would say, "if you catch a 'Number is messed up, and not really a number' exception, then show a window saying, 'You idiot, please type in a real number'". You can catch a specific error, or say "catch any and every error". You can also catch one error after another and say, "If you catch error one do this, error two do that, and error three don't do anything, and if another error that I didn't mention happens, then do this." (Obviously, this is not how you code it, but I'm trying to show the idea).

Multithreading Multithreading means having a single process (program) doing many things at the same time, while sharing the general data. Why would I want this, and any ways, what does it mean? A computer can only do one thing at a time. However, computers are so fast, that it can do part of one program in lets say, one tenth of a second, clear and save all of the memory for that program, work a second program for one tenth of a second, etc. Then in one second ten programs could work consecutively, and it will look like the computer is doing all ten in one shot. This is known as multiprocessing, meaning a bunch of completely separate programs running at the same time. But, lets say that you want one program to run different parts at one time. Why would I want to do that? Look at Microsoft Word. They have one piece of code to check for spelling, one piece of code to check for grammar, one piece to allow you to type, and the piece of code to run that annoying little paperclip in the corner, All at the same time. That's multithreading. For the same program to create "threads" that do different things together. Not that a computer can do more than one thing at a time, but it keeps on switching from one piece of code to the next, so fast, that it looks like it is all happening at the same time. The difference between multiprocessing, and multithreading, is that multiprocessing is running different programs, while multithreading is running different threads in one program. Therefore, multiprocessing has to clear what it is working in the processor (the part of the computer's brain that runs the instructions) and save it for next time, while multithreading keeps the same program, and just runs different parts. Another example of multithreading is the computer game of diablo (or any advanced computer game). You're inside the ruins, and ten skeletons, five bats, and three ogres come to attack you. How is the computer able to run through each one? Through multithreading, the program can give a different thread to each one, and switch off to give a thousandth of a second for each one. Therefore, it looks like they (and you the sorcerer) are all running at exactly the same time, but in reality, the computer is switching off. Also, since they all have to interact with each other, with you, and with the rest of the game (like if you fire at him he dies), so you don't want to clear the basic memory every time, but that they should all run with the same memory together.

In Java, multithreading is very easy. You just tell the program that you want it to be a thread, and when you want the thread to start, you tell it to start. The switching back and forth is all done for you by the Java language automatically.

Input Output (IO or I/O) Input means what comes into your program from the outside, and output means what is going to leave your program to the outside. For example, if you want your program to read what the user has typed in from the keyboard, or read from a different file, then you need to input that information. If you want that your program should send a paragraph to the printer to print, the screen to display, or to some other file to be stored, then you need to output that paragraph. Java supplies many classes and ways to input and output. They supply ways to input and output characters, streams, files, and serialized objects. Characters are like Strings, meaning, that it will input/output a bunch of characters that make up words and sentences. Streams are streams of bytes. Since everything deep down in the computer world is composed of ones and zeros, you can send a stream of ones and zeros to be outputted (for example) to the screen. (If you open a picture with certain editors, like TextPad, you will see that that picture is made of ones and zeros (although in a 16 number digit system)). Files are whole records of data, like a file on your computer, or like a folder in your file cabinet at home. Serializable objects are objects that the program can save the way it is with the behavior that it currently has, and reput it together in exactly the same way. This is known as serializing, and deserializing. One other word that comes up a lot is a buffer. A buffer is a storage space of memory that a large amount of data can be placed into, and outputted at once. For example, lets say you have a program that makes up a word, and outputs it. If you only need the end product, then it's a waste to send each word separately. Instead, you put all of the words into a big chunk called a buffer, and when the buffer becomes full, you send the whole buffer as one big piece of data.

Networking Networking in short (as this is a major subject) is the ability for one computer to talk to another through a connection. For a network you need two things. One is the physical device that connects the two computers, and the second thing that you need is the code that enables one computer to call and talk to another. In networking you have two parties, the client and the server. The server starts and waits for someone to call him. The client calls him, and the server answers back. For example, lets look at the Internet. The web browser (like Internet explorer) makes a call to the web server, giving it an Internet address, and asking it to return the page that that address points to. The web browser is a client, asking for information that the web server will return. The server is running even if no one is online, waiting for someone to call it, and the client makes that call, expecting the server to be there. The physical medium for the computers to talk is the phone wire, and the other part is the web browser and web servers' software. Another way of networking is through an intranet. An intranet is a bunch of computers, networked together, that they and only they can talk to each other, but no one from the outside can get in. A company might have an intranet where they can share information between each other, but not to someone from the outside. Here, the physical medium are the wires that connect the computer's together, and the logical medium is the software.

Like the other technologies, Java does most of the work of networking for you. Java creates something called sockets, that allow you to talk to a different computer through inputs and outputs.