Showing posts with label oop. Show all posts
Showing posts with label oop. Show all posts

Monday, 1 June 2020

Java programming and OOP

Either to revise or as additional sources, the followins resources may help you with Java programming and OOP.

 Hope they will be useful to you!

Wednesday, 4 October 2017

UML Class Diagrams in a Nutshell

...A really small nutshell.

This webpage contains a nice, short and sweet explanation and side-be-side comparison between a class diagram and its corresponding Java code. Priceless.

Source: http://pages.cs.wisc.edu/~hasti/cs302/examples/UMLdiagram.html

Tuesday, 6 June 2017

Class Relationships

Please read these two resources to have a better understanding of class relationships
For more resources on the principles of OOP and UML diagrams, click here.

OOP Principles and UML

These are my favourite explanations (so far) regarding the principles of OOP: Abstraction, Encapsulation, Inheritance and Polymorphism. They are most important to understand and remember, so study and practice them well. The links have page names (at the end of the link) that are self-explanatory.
UML provides so many tools, that it can be overwhelming. So it is always useful to narrow it down and focus on what is useful for a specific task. The following resources are on UML class diagrams. You are also recommended to look into use-case diagrams, which are great for conceptual designs.
In terms of class relationships, you should know (according to the IBO syllabus content)
  • dependency (“uses”)
  • aggregation (“has a”) and
  • inheritance (“is a”).
You may find the following links useful to revise these concepts. Just focus on what IBO requires among all the detailed information provided.

Monday, 14 March 2016

Static vs Non-static in Java

A really good (and tough!) distinction that everyone coding in Java needs to know: the difference between static and non-static variables in Java.

In my opinion, tutorial4us did a great job explaining it. A very good read indeed.

My understanding is that instance (non-static) variables exist in each object (instance of the class). Each object will have its own value/content for each instance variable. Think of the name in a Person class. We define the name as an attribute or property of a person, and each Person object will have its own name.

Static variables exist only inside the class where they are declared. Some call them "class variables" because they are bound to the class, not the object. They are unique and when a new object is instantiated, the object does not get its own copy of it. Rather than using the dot notation with the object (object.nnnn), you would use it with the class (Class.nnnn).

Note that this also applies to, and is also often used with methods!

Think about these example:


public class Test
{
  public static void main (String args[])
  {
    int[] numbers = {1,2,3,4,5};
    System.out.println( numbers.length ); // =5
    // length (size/number of elements) of the array object
    System.out.println( Math.PI );
    // PI is stored as a static constant inside the Math class
    // we don't need to instantiate a Math object to use PI
  }
}

Thursday, 3 March 2016

this Java keyword

A feature of Java that usually confuses beginners is the "this" prefix.

In a nutshell, the this keyword is used to distinguish between parameters of a method and attributes (instance variables) of a class.

The following link will lead you to a web page that does a great job contrasting and explaining this with examples:

Optimise Windows 10/11

How to optimise your Windows setup Just in case you need it. If you want a safe and conservative approach, just disable the background apps ...