Sunday, November 30, 2014

JAVA

JAVA

March 2013.  About this time, I set my sights into bigger targets.  I set my sights into using college programming books in the university library.  What programming books did I read?  Java, of course, because it was what I was going to study when I start going back to school.

Why did I decided on learning Java, anyway, instead of the other languages?  I think the reason for that was because it was the programming language with lots of available books in the public library.  And it was the language of the first programming book that I used to learn from, the AP Computer Science book, in the public library.

So I perused the university Java books for weeks, whenever I find the time to go to the university.  I was learning more about programming in Java, until I get to almost three-quarters of the pages of one Java book.

I was having a hard time understanding what is happening in the code that was using swing components, especially the statements that were using more than one dot operators.  Of course, it would help if I was coding the book code in a Java IDE.  But I didn’t have a computer and the website that I was using to compile Java programs online does not allow using GUI or applet codes. Here’s an example of that complex code:

import java.awt.*;
import javax.swing.*;

public class Myclass
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();
      frame.getContentPane().add(new JPanel(new FlowLayout(FlowLayout.LEFT)));
      frame.getContentPane().add(new JPanel(new FlowLayout(FlowLayout.CENTER)));
      frame.setSize(500, 500);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }
}

The above is a complete program that displays a Java GUI window. The window has nothing on it except the close button, the minimize button, and the maximize button.

For the code to display the GUI window, the code started by importing the AWT and Swing packages from the Java Standard Library.  The window is implemented by the class definition.  The class main method first creates the window object, adds panels to it, and modifies it further. The window is then made visible to the user.

Understanding the OOP paradigm is the key to programming in Java.  Java is the first language that is purely object oriented.  It is purely object oriented because you cannot make a Java program unless you make a class.  And classes are the stuff that objects are made of.

The dot operators used in the statements are actually member operators. Member operators accessed the class fields and the class methods that objects have encapsulated.  There is actually another notation for a class member operator, but that is used only in C++.

Happy Thanksgiving!

John Sindayen

1 comment: