Lifelong Learning
      Reports Written In Pursuit Of Professional Diploma On IT    
 

Contents

What is Lifelong Learning

Misguided Solution

Report on Educational Technology

Learn SQL Thru Query Analyzer

SQL Test Codes

SQL Review Notes

Java Test Codes

Notes on Learning Java

TCP/IP

C++ CGI Learning Project

Windows NT Overview

Working with Red Hat Linux

Overview of JINI Networking Technology

Remote Access for VPNs

The Author

Notes On Learning Java

Java is a computer programming language developed by Sun Microsystems Inc. It is an object oriented programming language. To program in Java, you need to create classes which Sun Microsystems describes as user defined data types. Classes contain attributes and methods and are used as blueprints for creating objects that can assume values for attributes and that can perform actions using attribute values. 

When you compile a Java program, the resulting code is not directly executable by the operating system. Sun describes the result as byte codes which when run are interpreted by a Java Virtual Machine (JVM) which is a software layer between the program and the operating system created when you install Java in your computer. 

The JVM strategy made Java portable among the different computing platforms but it made program execution a bit slower compared to executing the program directly by the operating system. To overcome this limitation, you need to design a suitable distributed implementation scheme wherein software components are distributed optimally among network nodes. 

Java's power lies in its rich set of class libraries that endows the programmer with a vast reservoir of ready made objects and functions which the programmer can readily use in the application he is developing. By using these class libraries the programmer is relieved of the tedious task of reinventing the wheel so to speak and can concentrate more on the logic of his application.  A staggering array of possible modes of use is available while the programmer is given tested, safe, and correct implementations of the classes and methods made available. 

Java and C++ 

Textbooks indicate that Java adopted the positive features of the C++ language but left out those that may not be safe and could lead to execution errors. One example highlighted is the fact that Java provides for automatic garbage collection thereby preventing incidence of memory leaks that could lead to fatal errors or system crash. Another is multiple inheritance which Java forbade in its implementation. In its stead, Sun invented the notion of an interface which can be severally implemented. To be able to inherit objects and methods from the JApplet class and at the same time use threads in your program, what you can do is extend your class with JApplet and make it implement the Runnable interface. 

Java was born amidst a process of change that swept through information technology toward the close of the 20th century. The paradigm shift from conventional design to object orientation ushered in a new way of thinking about systems and how to go about building them. The change shifted the focus of systems design from processes and data to objects that combined processes and data into a single concept. From there, software development will never be the same again. 

That is why it is rather difficult to talk about Java in isolation of this change of perspective. If your company has decided to adopt this change, then your implementation language would necessarily have to adapt to this change also. If you are given a design that is expressed in terms of classes, properties and behaviors, then you need a language that can fully articulate the intent of such a design in all its various forms and ramifications. And if I follow this trend of thought toward its inevitable conclusion, then Java will be one of the languages of choice in your implementation strategy. 

I do admit that C++ remains as the ultimate language for software development. I must admit too that I hardly know C++ being a newbie in the field of computer programming. But I feel that Java is coming on very strong and may in the near future evolve into something comparable in performance with C++. But we are most concerned about now and you do agree that we cannot postpone our systems development effort and needed to go on. All I can say is that Java offers a refreshing alternative to C++, a language that is within the reach of an average man or woman and is not particularly difficult to learn given the strong desire and determination inculcated in the learner. 

My first advice to Java learners is to have your own computer at home where you can work on any time of day that is most convenient for you.  The thing that you will most need which everyone has an equal number of is time. Make sure that you have a comfortable working place and pay particular attention to how you are seated. You are most likely to spend a big proportion of your time sitting in front of your computer and writing and revising your Java program to satisfy the requirements given to you. 

Building a Java application involves creating unique classes and specifying how these classes will react in response to stimulus outside and how it would use the properties and methods of other classes to bring about the desired results. As a programmer, you will be given what classes are needed and what the requirements are that these classes should satisfy. As most applications nowadays will work within a client-server setup, your program will most likely perform either a client or server role within the scheme provided in the systems design. You need not worry about sophisticated mechanisms for implementing network based operations because the Java developers have already thought about them and have endowed Java with a bewildering array of helping classes which you can easily make use of in your application. 

Foundational Knowledge 

It would indeed be a big advantage if you were equipped beforehand of three vital foundational knowledge: programming logic, object oriented modeling, and SQL. I learned Java while taking up a certificate course on e-technology at a local branch of an NIIT (National Information Institute of India) computer school. As a Java learner, you must ensure that you have been sufficiently grounded on how data manipulations are implemented in hardware using concepts like memory and the various arithmetic and logical operations that can be performed and how these are expressed in a programming language. Learn as much as possible about object oriented design and try to do some exercises on how you will come up with the required classes together with their respective properties and methods given a problem statement. And lastly, have yourself sufficiently grounded on SQL (Structured Query Language) which is a standard language for creating and maintaining relational data bases. MySQL and SQL Server are two software products that you can use to study how tables are created and manipulated. These are readily available either as evaluation or free copies and are easily installed in a Windows based computer.  Don't bother with the administrative portion of SQL, just concentrate on the table creation and manipulation components of the software package. Pay attention to how constraints are implemented since you will be encountering some of these as your Java program accesses tables in the database. 

If you're serious in becoming a first class programmer someday, then it may be worth your while to invest in a book on either mySQl or SQL Server. Make sure that the book includes a free or evaluation copy of the software and install it on your computer at home. The book will most likely contain a sample database which you can work on as you learn the intricacies of the SQL language. More preferably, though is for you to create your own database on a particular area you're most interested in. This way, your database will become more interesting from your own perspective. Mind you, it's not that easy to set up a database. There is a methodology that you need to follow to make sure that you database will not fall into anomalous state that could render the data less useful. In all likelihood, the book that you bought will guide you on how to go about creating one. When you have completed learning SQL, let  mySQL or SQL Server remain in your computer for a while. You might be able to use it for testing how your Java program would access data in your database.   

UML

Unified Modeling Language (UML) is a set of design and documentation tools with which a system design can be expressed or communicated. It finds utility in various phases of systems analysis and design work and in some instances could provide GUI coding capabilities. A UML -based software could provide an invaluable aid during the systems development process. UML is not a systems development methodology; it is more appropriately described as a useful tool in systems development process. For its future value when you graduate from an application programmer to a systems analyst, a good book on UML may likewise be a good investment. 

Again, if you are serious about learning Java, choose a good book from your favorite bookstore and buy one. Make sure that the book you will buy includes a CD ROM with the latest Java Development Kit (JDK) installer on it. Install the JDK and you're off to a good start in your Java learning endeavor. Your next step will be to put the JDK bin folder in your computer's path environment variable. In your Windows computer, either edit the autoexec.bat file or go to the system applet in your computer's control panel and edit the path statement in the environment variable section. You should be adding the D:\jdkx.x.x\bin folder to the path statement where D is your disk drive letter and x.x.x is the version number of your JDK. When done, try testing the java command in your command prompt window and if the response seems to come from the JVM rather than DOS, then your JDK is working properly. 

Applets and Applications 

While you can write Java programs that can be executed both as an applet and an application, do not try to do this at once. It will be easier for you to do this if you have done some intensive programming job doing both applets and applications. Applets are Java programs that are meant to be executed inside an HTML (Hyper Text Markup Language) page. An HTML page is an object that can be displayed by an Internet browser program such as Internet Explorer or Netscape Navigator. In an appropriate place in the HTML page, an applet statement is inserted specifying the file name of the Java program to be executed and the size to be occupied by the applet in the page among others. You will be using Java's appletviewer program to test your applets. After successfully compiling your program, enter appletviewer followed by the name of your HTML file. Compiling is done by entering the javac command followed by the file name of your Java program including the java extension in your DOS command prompt.   

Applications are Java programs that can be directly executed by the Java Virtual Machine (JVM). They are executed by entering java followed by the name of the program's class file. Some applications run in character oriented mode while others use a graphical user interface (GUI).  To use GUI in Java, you typically extend your class so it inherits the properties and methods of the JFrame class. A frame that is extended from JFrame doesn't have a status bar where you can display important messages for the user. You will typically use one or more dialog boxes from the JOptionPane class to display messages and get the user's response.  An application with no need to communicate with the user or with messages directed only at knowledgeable systems professionals will have no need for any graphical user interface.  

One compiler error that you need to be watchful of is misspelling the name of your program file. Your program name should match exactly the name of a public class inside your program. You can include other classes in your program but only one of them, the class using the name of the file, should be made public. If another class inside of the program needs to be accessed as public, then that class needs to be compiled separately in its own name.  

AWT and Swing 

JDK versions older than version 2 were using the Abstract Window Toolkit (AWT) for composing Java's graphical interfaces. The resulting visual effect left much to be desired.  Beginning JDK version 2, Sun introduced a new and more powerful windowing toolkit  which was codenamed Swing.  The new toolkit had all the features found in the old AWT but it had a lot more to offer. Old components like applet, frame, label and fields have new counterparts appropriately named beginning with the big letter J. Applet is now JApplet  and Frame is now JFrame. The visual effect had vastly improved and the programmer can now specify a particular look and feel to the GUI that he so desires. HTML style fonts can now be used and icons included in labels and text fields. New Java programmers should try to adopt the new Java GUI style provided for in Swing not only for its superior aesthetic effect but also for new features that could make the GUI more user-friendly. 

API 

One of the tenets observed in Java language programming is that you don't have to reinvent the wheel. Before coding anything that you want to be done in your program, check first the Java Application Programming Interface (API) if there is already a class that performs the function that you need to do in your program. Java's API is a vast source of ready made classes and methods that can be used in your program. It is organized into packages such as applet, awt, io, net, lang, math, sql, util, and the different packages under javax.swing. A copy of the latest API is an indispensable tool for the Java programmer. Make sure you have a local copy in your own computer so you don't need to go to the Internet every time you need to have a quick lookup on the API. Some books provide a printed version of a selected set of classes in the API. It would be nice to have a printed version of most used selected classes if you want to use a more manageable version but you need to be aware that this is incomplete and if you are looking for a rarely used class or method, then you need to go to the real thing. Browsing the Java API can be a rewarding pastime. Familiarity with the elements found in the API can prove useful later when you need to quickly find something in it. 

The basic rule in using the API is that if you don't want to use the fully qualified package name, you need to import the class or package in your program. If you need just one or a few classes in the package, you can import the classes separately. In case you will be using a lot of classes or methods in the package, you can use the dot asterisk after the package name and all classes in the package will be imported to your program. Some lazy programmers always import everything. However, importing just what you need is a more efficient alternative. 

Null Pointer Exception 

One of the most frequent execution errors encountered by new Java programmers is the null pointer exception error. This is caused by using a reference containing a null pointer. Always bear in mind that when you are using a reference to an object, a two-step process needs to be undertaken. First, it is made known what object type the reference will be pointing to. Second, memory is allocated to hold an instance of the object type. More often than not, the second step is forgotten and the compiler will not complain. But when you use the reference, JVM finds out that the reference doesn't point to anything in memory. You program is then abruptly terminated. The lesson to be learned is this: Instantiate an object type to be pointed to by the reference to avoid encountering null pointer exception when running your program. Instantiating an object type involves using the keyword new plus the size of the memory to be allocated. 

Another thing that you should keep in mind when writing a Java program is that references are known only within the block where the reference is defined and instantiated. Therefore, the larger the block where the reference is defined, the more widely the reference will be known. This means that a reference defined within a method block will only be known within that method block. On the other hand, if you want to use a reference in more than one method, you will have to define the reference within the class block and instantiate it in the constructor of your class.  

Static Versus Non-Static Reference 

One more dimension in the topic of references is the concept of non-static versus static reference.  One common mistake of new Java programmers is accessing a non-static class reference from a static method like main.  Because main is a static method, you can only access non-static class variables from main using an instance of the class' object. On the other hand, you need to qualify a reference as static if you want the reference to always point to a single class instance. One major use of static reference is when using a variable that stores an integer that will be used as primary key in a database table. Here, you want to have only one instance of the variable which can be referenced by any object instantiated from the class and therefore declare the variable as static. While static methods like main can access the reference directly, non-static methods will need to use the name of the class in referring to the variable. 

When you define a constructor for the class you are using, Java will not include a default constructor to your class. Hence, if there is any chance that you will need a default constructor later on, always make it a point to include a default constructor in your code. When using two or more catch blocks, make it a point to put the most specific exception first. This will make it easier for you to debug your code later. If you place a more general exception first, only that exception will be thrown and all the others following will just be useless pieces of code. When coding a method that returns a value to the calling method, make sure that the return statement is the last executable statement in the block. Otherwise, the compiler will report a statement not reached error. 

Abstract Classes 

One common coding mistake made by new Java programmers is putting a semicolon after a method statement. This will result in an unintelligible message from the compiler saying that the class should be qualified as abstract. An abstract class is meant only to be extended. You cannot instantiate an object from such a class. All the methods of an abstract class are also abstract. They are meant to be overridden in a class extended from an abstract class. By putting a semi-colon after a method statement, you are essentially telling the compiler that this is an abstract method. But an abstract method cannot exist in a non-abstract class and therefore you got the compiler message that your class need to be qualified as abstract. Remove the semicolon after the method statement and the compiler will stop complaining. 

You may be wondering why Java forces you to place some statements inside a try catch block. This is actually to help you make your code more robust. Sun already identified some actions that may cause problems in the operation of your program. To ensure that all possible causes of trouble are addressed, Sun designed the Java compiler to catch all potential sources of trouble so the programmer is required to code the proper course of action in case such an exception is raised. You as the programmer can then have some peace of mind that most potential problems are anticipated and responded to in your program. 

Interface Concept 

New Java programmers often find it difficult to grasp the interface concept. You may recall that Sun opted not to allow multiple inheritance in Java because it is believed to be one of the major causes of problems in program code. So to enable a class to inherit attributes and methods from more than one class, Sun introduced the interface concept which is not extended like a class is but only implemented. Your class can then implement as many interfaces which your program may so require. An interface is created much like an abstract class with methods left as undefined. The implementing classes are now required to override those abstract methods in the class that implements the interface. It is like a contract that says that if you like to implement such and such an interface, then you must override all its methods. An abstract class, I believe, does not have such a strict requirement. One example of an abstract class is the adapter class which when used in your program does not impose that all its methods be overridden like an interface. An adapter object that terminates your program when the application window is closed belongs to the Window adapter class which when inquired into from your API turns out to be a public abstract class.  

Object Streams 

If you are coding a network application that sends and receives information using network sockets, the object input and output streams more often than not are best to use. The only caveat in using them is to make sure that the object you are sending and receiving implements the serializable interface. Object streams can also handle most primitive data types such as strings and numbers. Strings directly implement serializable while floats and integers extend number which originally implements the serializable interface. In a sense. Java programming involves choosing from an array of available classes and methods which one is the most suitable to the situation at hand and using them to implement what needs to be done. As a new Java programmer, it will be safer for you to use the already tested classes and methods in the API rather than creating new classes and methods to solve programming problems. 

Decimal Format 

You may be faced with the problem of putting leading zeroes to a six-digit string variable in your programming work. By all means you can code a method to perform such job but why would you spend precious brain power in a problem already solved by the API. The decimal format class offers a decimal formatting method which you can override in your program to specify the format that you so desire. Again, there is no need to reinvent the wheel. Browse through the API and see if any class or interface already implements the method that you need to code.    

Policy Tool 

When you installed Java in your computer, a default security policy was configured by the Java installer. If you add a new folder for your Java programs or need to access a new file you have just created, you might encounter a few security errors regarding file access. To remedy the situation, run the policytool program and create a new policy that will make all permissions to be allowed. You are not likely to damage your computer by doing this. You can make a focused study of the policy tool later when you are already comfortable programming in Java. You need to open the policy file before creating a new policy and don't forget to save your changes after. In your Windows computer, the policy file is typically located in \jre\lib\security path of your jdk folder. 

HTML Converter 

Even though your applet may run happily under appletviewer, it may not run properly under the current Internet browsers like Internet Explorer and Netscape Navigator. This is because these browsers support only the older versions of Java and may not know how to deal with the newer features in the current version. To successfully upload your applet to a web server, you need to convert your HTML file into something that your browser will understand. You can do this manually following directions from Sun's web site or use and HTML converter tool which can be downloaded from the Sun's java web site. As a new Java programmer, it will be best to just use Sun's HTML converter. Usage is usually explained in the download package of the version you downloaded which should be compatible with your existing JDK version. You will also want to make sure that your Internet browser is equipped with the Java Runtime Environment (JRE) appropriate to your JDK version. The JRE is automatically installed when you installed the JDK for newer versions. I am not sure but I think old JDK versions may not install the JRE automatically. Newer JDK versions install a JRE applet in the Windows control panel so if your control panel has a Java JRE applet, then your browser is already equipped with the proper Java plug-in. 

Grid Bag Layout 

When it comes to manually formatting your GUI, grid bag is the most versatile to use. It takes some time getting the feel of it but you can master it in no time. When you finally get the hang of it, you will find yourself using it even for simple layout requirements where simpler layout methods like flow and border layouts may be more appropriate. When using the gird bag layout, you typically instantiate a new grid bag layout object together with a new grid bag constraints object. Then, you use the grid bag constraints to specify the exact location of the component you want to place in your GUI. The key to mastering the grid bag layout is to draw imaginary horizontal and vertical grids on top of your GUI design and number them consecutively from left to right and from top downward. Then use the gridx and the gridy elements in your grid bag constraints to specify where in you GUI you want to locate your GUI components.  

A truly good combination in designing a perfect GUI is to use the border layout and the grid bag layout in the same GUI. In this design, you make your frame use the border layout. Then, you develop your main panel using the grid bag layout and create a buttons panel using a simple flow layout. Place your main panel in the frame using the border layout CENTER locator while you locate your buttons panel using the border layout's SOUTH locator. This way you achieve a clean and appealing GUI.   

ODBC Essentials 

ODBC is a standard method of accessing relational databases. For your Java program to be able to access a relational database, you need to set up a dataset name for the database you will be using. This is accomplished by adding a dataset name (DSN) to the ODBC applet in your Windows control panel.  Some of the things you need to configure are of course the dataset name you will be using, the authentication method to be used, a valid username and password for the database, and the default table to be opened among others. Don't worry about doing this since you will be using a wizard which will guide you in making the right selections. If you're a bit uneasy doing this, read some help information first to build some confidence. You can always delete whatever configuration you have done and start all over again if you make a mistake.  Be reminded that some of these data elements will need to be specified a second time when you make the connection to the database in your Java program. You may want to make a note of what data items you entered or just go back and review how you made the configuration then cancel the operation before the wizard ends.

IDE 

Instructors advise not to use an integrated development environment (IDE) until after you have been sufficiently grounded on the basics of Java language programming. I feel I should echo this advice because I think it is rational but also because I believe that a Java language foundation needs to be built first and foremost in the Java learner and the IDE could get in the way of doing this. I likewise feel that a learner could most profitably make use of an IDE if he has had a solid foundation on the Java basics first. So, it may be to your advantage as a new Java programmer to first build a good solid foundation using the basic tools from the JDK. 

Okay, so there you are. Those are some notes which I hope would find some use to you as you traverse the difficult but not impossible task of learning how to program in the Java language. I would be happy to respond just in case you need further assistance.

Download MS Word Version (.doc) of this document.

 

     

Previous Article

Next Article

   
           
     

LEDAC    A Writer At Heart    My Doc Files    Optional

   
     

Copyright 2008 Aureo P. Castro Email: [email protected]

   
           
Hosted by www.Geocities.ws

1