Skip to main content

Intro to JAVA - Part Two

From what we've learnt from the last lesson you should now have a basic understanding of object oriented programming. Some of you may ask what other form of programming is there apart from the object oriented programming style? Well, there are other programming styles apart from object oriented such as Imperative also call Procedural, Logic and Functional programming styles.
Our focus here is Object oriented programming, OOP, which is currently the most popular among modern programmers.
Some believe that Object oriented programming is limited in terms of performance or what you can achieve with it but I think otherwise. What you can achieve with OOP depends on the programmer's skill set and has nothing to do with the language.
However, OOP is easy to learn and master. Here is a list of OOP styled programming languages out there (list not all inclusive);

  1. JAVA - our focus for now (used for creating Android apps and lots more)
  2. PHP - Good for web apps (used by Facebook and others)
  3. C# - pronounced C sharp (Commonly used by Microsoft visual studio devs)
  4. GO - by Google
  5. Swift - by Apple for creating apps for IOS and OS x apps
  6. Perl
  7. Python - for Data
  8. JavaScript - Not related to JAVA!
There are a lot more languages that support OOP or is OOP styled. Google for more.

Enough about other languages: let's talk JAVA!

At the last lesson we created a JAVA program that prints "Hello Java!" to the console screen. Here is a breakdown of the JAVA syntax.

The first thing you declare in a program is a Class: classes are more like categories of objects just like Car class example as explained during the last lesson. Objects can now be created from the Class.

package org.ben.java;
public class Main {

    public static void main(String[] args) {
        System.out.println("Hello Java!");    }
}

Take a look at the Hello Java! program up here.

The Main class is defined which is the name of the file with capital "M". The class file name must tally with the class declaration in the file or there will be error. 

A public static void main method is declared; this is different from the class Main: in fact, you class can be called anything you want based of the purpose of the class or the general purpose of the app. It is a nice programming practice to create classes based on their use or purpose. For example a Car class, Human class, etc. 
The main method is where the action takes place. Every class must contain a main method. Public means it is accessible throughout your app; other class can access it. Static here means the method can run even if nothing is parsed in as an argument. Void here means there is nothing returned by the method.
Where (String[] args) means that your method can accept an array of Strings as an argument or arguments. In this case "Hello World!.

I believe you have learnt something today. See you next lesson where we talk about types in JAVA.

Please leave a comment if you have a request or an observation.




Comments

Popular posts from this blog

Complete CorelDraw Shortcuts

For Corel enthusiasts out there; here is a list of shortcuts in your favourite design/illustration app to make you work faster. Learning this may not be that easy but with continuous practice you should get used to them. Enjoy! Align Bottom   B   Aligns selected objects to the bottom Align Centers Horizontally   E   Horizontally aligns the centers of the selected objects Align Centers Vertically   C   Vertically aligns the centers of the selected objects Align Left   L Aligns selected objects to the left Align Right   R   Aligns selected objects to the right Align To Baseline Alt+F12   Aligns text to the baseline Align Top   T   Aligns selected objects to the top Artistic Media   I   Draws curves and applies Preset, Brush, Spray, Calligraphic or Pressure Sensitive effe Back One   Ctrl+PgDn   Back One Break Apart   Ctrl+K Breaks apart the selected object Brightness/Contrast/Intensity C...