Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Advanced Java

I have been away from the Java programming language for almost the whole summer. There was an app I wanted to write. But I needed it to work quick. So I fell back to using C++. Now I want to get back into the Java swing of things (no pun intended). This week I signed up for a community college course on Advanced Java.

I was a little shocked by the price of the class. It rang up to around $800. That does not even cover the cost of the book. I thought community college was supposed ot be inexpensive. It might be worth it though. We are supposed to cover topics such as collections, multithreading, generics, database programming, network programming, and Java Server Pages. Dang. That's quite a list.

To get my Java skills back, I decided to read the first chapter from the class textbook. It is on recusion. The Java syntax for recursion is simple enough. Understanding the technique of generating a recursive algorithm to solve a problem is hard. With the new Java class coming up at the end of the month, I think I will be more chatty on my blog about Java points of interest.

Back to Java

I have been spending time learning JavaScript over the past year or so. However now it is time to return to Java. Later this year I plan to take an advanced Java class in school. However for now I am writing some small utlities in Java.

I was surprised at how rusty I got. You need to use your skills to keep them current. I coded a simple switch statement. Being a good developer, I tried to use some constants in the labels of the switch statement. They did not work. Ooops. I forgot to make those constants "final".

There was something that surprised me a bit. I put together a switch statement that initialized a variable. I included a default label in the switch clause. So all paths through would get the variable initialized. However the compiler still gave me a warning that the variable might not be initialized.

It was a small thing. But I don't want any warnings in my code. So I had to blatantly initiallize my variable. Not so clean.

Access Modifiers

Just read a rant about a developer that likes to use parentheses to make the order of operations explicit. He does not want a reader of his code to need to know the operator precedence rules. As an extension, he also explicitly declares the access modifier for any java function that he writes.

This started a big discussion on what it means to not specify an access modifier for a Java function. In C++ it is easy. C++ class members without an access modifier are private. C++ structure members without an access modifier are public. However in Java, not specifying an access modifier means the function is package private.

Package private has no keyword. It is the access allowed when you do not specify a modifier. This causes the function to only be accessible by other members in the package. This is different than public, private, or protected. I am sure I learned this some time ago in my Java college class. However today it was solidified.

Disappointing Advice

This semester I am taking a web development class in school. We are learning HTML and Cascading Style Sheets (CSS). However next semester I shall take an advanced Java programming class. I thought I had better brush up on my Java programming since I had not done any since my intro to Java class.

I thought I could combine what I learned in web development with some Java code to produce a Content Management System (CMS). It would take user input and spit out a blog site in HTML. This seemed doable in a month or two if I kept the app simple.

Today I read an advice column from a developer claiming to be a veteran who was in the know. He started out by recommending that developers do not create CMS systems. Ooops. He went on to say that developers should not code in Java. Ouch. That was the double whammy.

The reasons for this advice were twofold. First there are too many existing CMS solutions on the market. Second he said users just don't use Java apps. Well that might make sense if I was trying to start up a business with my product. But I am just trying to write a throw away app to gain some experience. So I think I am okay with my idea. It just won't turn into some money making opportunity. Or will it?

Good or Great

I have finished reading the chapter on arrays in Java. This is for my college class. In addition to the reading, I have completed each Self-Test question from the chapter. I have written Java programs to solve all the exercises at the end of the chapter. You could say that I have achieved a good understanding of the material.

Here comes the hard part. There are also a bunch of programming projects at the end of the chapter. However there are so many other things I would rather be doing. We are behind at work. I could catch up with this week's list of tasks to be completed. It is nice outside. I can do some necessary yard work. The weather also lends itself to me taking a bike ride with friends. The girlfriend wants to see a bunch of movies. She is also hungry and wants to go out to eat.

It is easy in the middle of the night to spend some time learning Java. The hard part is now when I really don't want to do any more Java programming. After all, I have reached a good enough level of understanding. What is there to gain by going further? The answer is that there is greatness to be attained. Now I am not saying that I will be a great Java developer. But in order to have a chance at greatness, I must push on now. It is absolutely required to do each and every one of the programming projects in the back of the book.

To tell the truth, greatness will also require going beyond the projects in the book. I need to code up some other programs using Java. You know. I need to implement some non trivial application using the Java programming language. Only then will I have a slight chance at possessing great Java programming skills. Let's see where this takes me.

Setting the CLASSPATH

I continue to read ahead in my Java class textbook. Reading alone does not make the concepts sink in. So I try to do each and every exercise in the book. Today I had some free time at work. I decided to try one of the exercises from the section I was reading. The exercise instructed me to use a class that had a source listing in the book.

My instructor provided me with the source code for the listings in the book. This helped so I did not need to type in the code. I compiled the class provided to me by the book. Then I coded up a simple second class in another file which made use of the class from the book. However the Java compiler complained that it did not know the other class name.

This was very strange. I had already compiled the other class. Everything was in the same directory. I was at a loss. I tried to import the other class. That did not work. The other class was not in a package. I could have sworn that this worked before. If the other class is in the same directory you can use it.

Then it dawned on my. I bet there was something wrong with the CLASSPATH. I checked out the system variables and found that the current directory (.) was not a part of the CLASSPATH. I quickly added it to the beginning of the CLASSPATH. Now this makes sense. Java won’t consider code in the current directory unless that directory is part of the CLASSPATH.

Software Distribution

I coded up a cool quiz program on Oracle PL/SQL questions. It was aimed at helping me study for an Oracle certification exam. Now I wanted to release this program to other people to use. I did not want to just send out some Java source code. From what I gather, you can ship the Java class files. However this requires a certain version of the Java run time,

How do commercial shops roll out their software? Do they include the class files with an install that checks and optionally installs the Java Run time Environment? I come from a C++ Windows background. So my instinct is to somehow turn this thing into a self contained executable file that I distribute. However it seems this is not the Java way to go.

Maybe there are not that many users who code and ship Java applications. Or maybe there are not many desktop applications that are developed and shipped like this. It is easier if the program only needs to run on the server. In that case, you can ensure the correct version of the Java run time is installed there. You can also deploy just the class files to the correct locations. Users can then just access the program through web pages viewed in their browser.

Development in the Java world appears to be a new paradigm. I am not sure if I like it. But first I need to get with the program as far as software deliveries go. After I have tried it for a while, I may have a better perspective if it works, and whether it is a good way to go for development and delivery.

Game Success

Good news. I successfully created a simple Java game within 7 days. This was in response to a challenge posted on a Usenet news group. You can find a link to the program on the Legend of Angband web site.

The emphasis on my development for this game was to knock out something quick. As a result, I only had two classes. There was the driver program which had my main() method. And then there was a Monster class housed in its own file.

This was a Dungeons and Dragons style two dimensional game. There was no rocket science here. I drew a maze. Then I put some gold in that maze. And I added some monsters. The monsters fight you when you attack them. They follow you if you try to flee. Yeah it does not sound like much. I am still a Java novice and it has been a busy week. Download it and give it a try already.

Once You Go Static...

I am on a 7 Day Quest to write a game in Java. That's a tall order since I am only half way through a college Java class. But I am learning a lot.

For example, I am trying to conserve time due to the quick deadline. Therefore I am putting all my code in one class. This class has a static main function to run the program. Guess what? That function can only call other static functions in this class. That's not too object oriented.

Well perhaps the optimistic way of looking at this is that I have an object. But it is the only one of its kind. There is only one main. So the class with that has main must be a singleton. I am keeping some data in static variables. And I am breaking up functionality into static methods. But it still feels a little clunky.

Missing Arrays

I am halfway through my college class on Java. There are a number of topics we have not covered yet. Normally that is fine, as we will eventually get to them. However I just entered a programming contest to write a Java game in 7 days. My game will be called dL1.

We have yet to cover packages, arrays, or file input/output. That is a bummer. My game will be on a two dimensional grid. That's where arrays would really come in handy. My plan is to substitute objects that references each other for arrays.

I was hoping to use some third party code to do the actual drawing for my game. So I cannot wait any more. I am reading ahead in my course book to see how to use packages. As of last night, I still had not mastered the topic. I really need to get a move on it. The contest ends in 7 days and I have one Java file which does not compile. May the Force be with me.