Programming Series - 03 - Basics of the Object Oriented Programming part 2

 Hello guys!

Here I continue the basics of the object oriented programming, that I started here , by talking about coments, operators and execution control statements.

A summary of what we've talked about in the previous post:


We are going to talk a little about comments.

We can comment code in two ways: /* some comment */ - the traditional C style comment, begin with a /* and continue, possibly across many lines, until a */

The Second type of comment comes from C++ and it's the single line comment, starts with a // and continues until the end of the line. Example: //This is a comment

Comment documentation:

Javadoc is a tool used for generating Java code documentation in HTML format from Java code and requires documentation in a predefined format. 

These comments may be placed above any class, method or fild which we want to ducoment and are commonly made up of two sections:

  • The description of what we're commenting on
  • The standalone block tags (marked with the "@" symbol) which describe specific meta-data

All javadoc commands occur only within /* */ comments

Some of those commands are:

  • @see - provide link to another class that may help provide clarity
  • {@docRoot} - the relative path
  • @version - current version
  • @author - names of the autors
  • @since - the version where this piece of code was introduced
  • @deprecated
  • @param
  • @return
  • @throws
Here is an example:

//: c02:HelloDate.java 
    import java.util.* ; 
/** The first Thinking in Java example program. 
    * Displays a string and today's date. 
    * @author Bruce Eckel 
    * @author www.BruceEckel.com */ 
        public class HelloDate { 
    /** Sole entry point to class & application 
        * @param args array of string arguments 
        * @return No return value 
        * @exception exceptions No exceptions thrown */
         public static void main (String[] args) { 
            System.out.println("Hello, it's: "); 
            System.out.println (new Date()); 
        
    }


Now, I'm going to talk about operators. Operators are taking one or more arguments to produce a new value.
This is the precedence table. It defines how an expression evaluates when several operators are present. For example, multiplication and division are performed before addition and subtraction. Parantheses can be used to make the order of evaluation explicit.

The assignment is performed with the operator = 
Means it will take the value on the right-hand side and copyt it to the left-hand side. Ex a = 4 . You can't assign something to a constant value, so you can't say 4 = a

Mathematical operators are:
  • Addition (+)
  • Subtraction (-)
  • Division (/)
  • Multiplication (*)
  • Modulus (%) - the remainder from integer division
A shorthand notation to perform an operation and an assignment at the same time is denoted by an operator followed by an equal sign, for example to add 4 to the variable x and assign the result to x, you can use x += 4 , which is equivalent to x=x+4 


Increment and devrement operators: -- to decrease by one unit, ++ to increase by one unit, not only modify the variable but also produce the value of the variable as a result.

Pre and Post:

  • Pre-increment, the ++ operator appears before the variable (++a)
  • Post-increment, the ++ operator appears after the variable (a++)
  • Pre-decrement, the -- operator appears before the variable (--a)
  • Post-decrement, the -- operator appears after the variable (a--)
For Post increment and decrement, the value is produced, then the operation is performed.


Relational Operators, generate a boolean result. Evaluate the relationship between the values of the operands. Examples:
  • less than (<)
  • greater than (>)
  • less than or equal to (<=)
  • greater than or equal to (>=)
  • equivalent (==)
  • not equivalent (!=)
:Logical operators:
  • AND (&&) 
  • OR (||)
  • NOT (!)     


Java operators:
  • if-else operator, ex: bool?a:b - means if bool is true, return a, if bool is false, return b
  • String operator "+" - concatenates strings
  • Cast is used to make a type conversion explicit
Execution control statements:
  • return , specifies the value returned by a method
  • if-else
  • while
  • do-while
  • for
  • switch
  • break
  • continue

I hope you enjoyed reading this and now you have an idea what's Object Oriented Programming about!
Thanks for reading, see you next time! And don't forget to ask me anything!

Post a Comment

0 Comments