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

Sunday, November 23, 2014

PROGRAMMER

PROGRAMMER

February 2013. About this time, I run my first program. It was a Java program, of course, because it was the only programming language I was trying to learn at this time, in preparation for my going back to school.

I was using the public library computers. Since the public library does not allow downloading anything into their computers, I used an online compiler to compile my programs.

I actually compiled a lot of Java programs, because I was just learning to be a programmer. I was using the compiler to know if I really know what I have just learned about Java from reading the public library books.

I wrote the programs all by myself without the aid of the Java books I was learning from, because there was not enough room to put them in the library's Computer Room. There were 20 computers, and everyone of them is almost always being used in that small room.

One of my earliest Java program is still accessible in the online compiler website. I have written my name on the program as shown here:

/**
     This is a documentation of my first program.
     It will display the copyright of the program.
*/

class cdocumentation {
     public static void main(String args[]) {
          System.out.print("\tThis program is written by John Sindayen.\n");
          int vyear = 2013;
          System.out.println("\t\t\t\bCopyright " + vyear);
          }}
/*
This is the end of the program.
*/

During this early period, I have already shown some good programming practices. Here are some:
a. Documentation
b. Use of indentations and spaces

Some good programming practices that needed to be applied in this early program are these:
a. Uppercase first letter for a Java class name.
b. Conventionally, array brackets should be placed beside the String data type.
c. Ending braces should be in different lines to make it more readable.

Finally, here are some of the prolific programmers who has invented their own programming language, or otherwise known for something famous.

John Backus created ForTran, short for Formula Translation, a scientific programming language.
Alan Cooper created Visual Basic programming language.
Brad Cox created Objective-C object oriented programming language.
Brendan Eich created JavaScript web scripting language.
James Gosling created Java, the first pure object oriented programming language.
Grace Hopper created COBOL, short for Common Business Oriented Language, a business programming language. She became a U.S. Navy admiral.
Toru Iwatani created the Pac-Man game.
Rasmus Lerdorf created PHP client-server based web scripting language.
Ada Lovelace is the first known programmer.  She programmed Charles Babbage's mechanical computer. She is otherwise known as the Countess of Lovelace.
Yukihiro Matsumoto created Ruby object oriented programming language.
Markus Persson created the Minecraft game.
Dennis Ritchie created C, the ancestor of many modern programming languages.
Guido van Rossum created Python, an all object type programming language.
Bjarne Stroustrup created C++, the first language to implement object oriented programming.
Linus Torvalds created Linux open source operating system.
Niklaus Wirth created Pascal procedural programming language.

Welcome to the club!

John Sindayen

References:
http://en.wikipedia.org/wiki/List_of_programmers
http://stackoverflow.com/questions/26776008/does-python-data-type-are-all-object-based-on-c-class

Thursday, November 20, 2014

COMPUTER

KNIGHT IN PROGRAMMING : JOURNEY TO PROGRAMMING

COMPUTER

This blog is about my journey to programming, in various language cultures and platform environments. Here we go!

January 2013. I saw my first Java program, in a public library book. It was one of those high school programming book. It was titled "Be Prepared for the AP Computer Science Exam in Java."

I thought the book was for me since it's written for high school students. I read every pages, starting from the softbound cover until I got to a program solving for a Fibonacci series using recursion, some 200 pages later.

There were two function calls of the same recursive function in the return statement. I couldn't figure out why the output is such after doing several walk-through of the resulting output.* The two calls to the recursive function was throwing me out of the loop. So back to square one! Start from scratch!

I then started to read books that actually teaches Java to a beginner. The AP book was actually not a book for learning Java. It was a book for reviewing what you know of Java, by reminding you of what you need to know before doing its exams at the end of each sections and chapters, all of which were to write the output of a code segment or to test your programming concept.

Why do I have to learn Java? I was planning to enroll in the VRAP program available to U.S. Armed Forces veterans. And I have always been interested with computers. So I planned to major in Computer Programming. It was either that or Culinary Arts, but I wasn't interested in making a career of cooking. I'd rather cook codes than cook cookies! ;-)

Using the beginner books, I learned how to code the traditional first program for programmers, Hello World!, in Java.

Python is actually the easiest first programming language for a beginner because it only takes one line of code to program Hello World. This:

print(“Hello World!”)

Save that single statement from IDLE IDE, name the file, and every time you run the program from IDLE, the Python interactive mode responds with >>>Hello World!

Anyway, I think learning about binary code, is actually the first thing one should learn if one is to be a professional computer programmer.  So here is a binary code instruction that a specific computer architecture is able to execute:

10001100011010000000000001000100

Binary code is very much computer architecture dependent. You need to design your computer to accept your machine language in order for your computer to execute your code. This particular code is specific to MIPS computer architecture using 32 bits long instructions. This particular instruction tells the computer to load a value into register 8 by referencing the address stored in register 3.

This sounds like a lot of technical stuff. It is! But learning to be a good computer programmer takes a lot of learning. It takes at least 10,000 hours of coding and learning before you can consider yourself an expert. It’ll probably be much easier to earn your wings in the Air Force than to be an expert computer programmer. ;-)

But always starting from the beginning helps! Knowing your PC, CPU, ALU, CU, I/O storage devices, RAM, ROM, bits, bytes, and words before learning your programming syntaxes and semantics will go a long way into understanding computers.

Happy computing!

John Sindayen

*After learning from the beginning books, I was able to reproduce the same output as the correct answer in my walk-through of the output.

References:
http://en.wikipedia.org/wiki/Machine_code
http://www.amazon.com/Prepared-Computer-Science-Exam-Java/dp/0965485358
http://crunchify.com/write-java-program-to-print-fibonacci-series-upto-n-number/