Showing posts with label programming. Show all posts
Showing posts with label programming. 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!

Tuesday, 3 December 2019

Lexicographical Order

This refers to the way strings and characters are alphabetised and compared.

In Java, you need to understand lexicographical order to properly implement (and debug) sorting algorithms.

The page below has the best, most concise and practical explanation I have found so far:

Monday, 31 December 2018

Warm up to Computer Science

These resources will help you practice and strengthen your Computer Science and practical programming skills. Multiple links are provided to cover a wider range of backgrounds, experience and needs.

Python is a great first programming language to learn for beginners, and Java is second to none to learn OOP and intermediate to advanced programming concepts. Java is a must for computer science students, and is also the prescribed programming language for the IB Diploma Programme Computer Science course with the Object Oriented Programming (OOP) option.

Good luck!

Theory/General Knowledge:
Practical aspect: Programming

Free eBooks recommended:
A few of the best reference sites about Java programming are

Monday, 20 August 2018

Setting up Java and Geany

In order to program in Java, you may want to follow the instructions and videos that I have prepared. They are simle and straightforward, and have no audio to keep the video lean and to prioritise video quality.

Videos show tutorials for both Windows 10 and macOS.

Setting up your Java programming tools, in order (JDK first, then Geany)
  1. Download and install Java Standard Edition Development Kit, version 8. You will have to agree to using their cookies and accept their License Agreement, then download the right JDK for your system (most likely Mac OS X x64 or Windows x64). Link: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  2. Now download and install Geany from https://www.geany.org/download/releases. You will need to choose between Windows binaries (e.g. "geany-1.33_setup.exe - Full Installer including GTK 2.24 runtime") and macOS X binaries (e.g. "geany-1.33_osx.dmg - Geany and Geany-Plugins combined").
The following screen casts may help you:

Tuesday, 6 June 2017

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.

Sunday, 23 April 2017

2D Arrays and IB Pseudocode

This brief post shows how to create a bi-dimentional array and describe it using IB pseudocode. It isn't stated in the IB Pseudocode in Examinations or Approved notation for developing pseudocode documents, so it's my answer to it, not an official one. Don't sue me if your examiner disagrees with me! O_o
declare A as integer array of size [ROWS][COLUMNS] or
declare A as integer array of size (ROWS, COLUMNS)
declare A as integer array of size [5][6]
declare A as integer array of size (5, 6)
Obviously, integer should be replaced by the appropriate data type.
IB papers may have defined it for you, or they may not ask you at all to define the size. You could define it (unknown size) as
declare A as integer array of size [ ][ ]
...then you'd use it like
loop ROW from 0 to 5
    loop COL from 0 to 6
        output A[ROW][COL]     or    output A(ROW, COL) 
    end loop
end loop
I'd recommend going for the [ ][ ] style as it'd be more consistent with the single dimensional arrays described in the IB pseudocode documents mentioned above.

Arrays and Java

Just a short post with pretty much all you need to know about arrays in Java:
Below are some additional links about arrays and 2D arrays:

Friday, 8 July 2016

Tweaking Ubuntu

I have been playing around with the new LTS version of Ubuntu 16.04 and in my efforts to tweak it to my comfort, did the following:

sudo apt-get install synaptic unity-tweak-tool chromium-browser mc gnome-themes-standard ubuntu-restricted-extras vlc audacious -y

If you're into themes, you may want to have a look at the following resources:

http://www.noobslab.com/p/themes-icons.html
http://lmelinux.net/2016/03/31/adapta-another-beautiful-gtk-theme/
http://lmelinux.net/2016/04/25/apply-adapta-dark-theme-ubuntu-unity/

If you need programming/basic development tools:

sudo apt-get install build-essential default-jdk ruby python python3 geany geany-plugins vim -y

Other Sources:
https://help.ubuntu.com/community/RestrictedFormats
http://askubuntu.com/questions/56446/how-do-i-install-the-ubuntu-restricted-extras-package

Tuesday, 10 May 2016

Linked Lists

A couple of good links for revising singly and doubly linked lists:
The concepts, use, functionality, advantages and disadvantages are more important than the code when studying ADTs at an introductory level; focus on the diagrams rather than the Java (or code) implementations shown in these online resources.

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
  }
}

To code or not to code

...For some of us, that is the question!

One of my favourite authors, V. Anton Spraul, has an interesting website about his books, programming, computer science, and other topics.

What caught my attention (this time) is the Learning How to Program: A Guide section of his web site.

I would like to recommend reading part two, "How do I know if programming is for me?" to anyone considering a CS course, diploma or degree, job, or anything that involves coding.

Below are my favourite quotes from the points he makes:

  • "A good programmer enjoys programming. I don't mean that every act of coding will bring unbridled joy, or that programming is fun in the same way that playing a favorite sport or video game is fun. But there should be a real pleasure in seeing one's program working, even if the program is a pitiable little thing that accomplishes almost nothing."
  • "Probably just about anybody could become a pretty good programmer if they work hard enough to become one. But make no mistake about it, programming is tough mental work. If, on some level, you're not enjoying the work, you're never going to be able to focus on it long enough to master it."
  • "Unfortunately, just because a person really enjoys working with computers doesn't mean he or she will enjoy programming. I guess the reverse is true, though; if you don't like technology, you probably shouldn't try to learn programming."
I couldn't have put it better myself. Thanks again, Mr. Spraul.

Friday, 4 March 2016

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:

Sunday, 7 February 2016

Distribute your Java classes in a JAR file

The source of the information given in this post is http://www.skylit.com/javamethods/faqs/createjar.html
In my opinion, the simplest and quickest way to do this is using the command line.


Steps
  1. Start the Command Prompt. The easiest way is to Shift-Right Click on an empty spot in your Windows (File) Explorer. Make sure no files are selected, though. The idea is that your Windows Explorer should be in the location of your Java files.
  2. Navigate to the folder that holds your class files:
    Copy the path from Windows Explorer's address bar (more details about WE here), then type the following into the command prompt window:

    cd /d 
  3. minding the space at the end, then paste the path that you copied from Windows Explorer's address bar. Press Enter.
  4. If you haven't set your path to include JDK’s binaries (compiler and utilities, including the one that creates jar files), you need to do so by adding it to your default path (your folder may differ depending on the version of the JDK that you installed)
    path %path%;C:\Program Files\Java\jdk1.8.0_83\bin
  5. Compile your class(es):
    javac *.java
  6. Create a manifest file and your jar file (Replace IA with the relevant name to your project):
    echo Main-Class: IA > manifest.txt
    jar cvfm IA.jar manifest.txt *.class
    ---- or ----
    jar cvfe IA.jar IA *.class
  7. Test your jar:
    java -jar IA.jar
  8. Create a batch file so your end user can double click on it to run your command line application (you may also use Notepad to do this):
    copy con run.bat    (creates the file)
    java -jar IA.jar    (Press CONTROL Z and Enter to finish and save the file)
  9. Double click on run.bat to test it.

Tuesday, 22 December 2015

Java Scanner class confusion

If you have used Java's Scanner class, yopu may have come across an odd behaviour as you use the same Scanner object to input numbers and Strings.
I recently found the best explanation for this behaviour (it's not a bug), which you may find and here here at Daniweb. The best replies are from and


The reason it gives you trouble is because when the user enters an integer then hits enter, two things have just been entered - the integer and a "newline" which is \n. The method you are calling, "nextInt", only reads in the integer, which leaves the newline in the input stream. But calling nextLine() does read in newlines, which is why you had to call nextLine() before your code would work. You could have also called next(), which would also have read in the newline. (BestJewSinceJC)

Just change the delimiter.

Scanner in = new Scanner(System.in);
in.useDelimiter("\n");
(cgeier)

Hope you find these useful.

Friday, 23 December 2011

Sun Java on Ubuntu 11.10

Decided to 'fork' my previous post because since Ubuntu 11.10, Sun/Oracle Java has been removed from Canonical's partner repository. Fortunately, Roberto Ferramosca is providing the appropriate packages in his personal package archive (PPA).

So open your terminal, and let's go:

sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-jre sun-java6-plugin sun-java6-fonts

And that's it. Hope it's helpful. Now if you want to ensure Sun's JRE & JDK are the default, type in the terminal:
sudo update-alternatives --config java
and select your preferred alternative from the list. To select a Java compiler, type
sudo update-alternatives --config javac
Now on to the testing. You should get the version numbers of the currently installed and default runtime and compiler by typing (in the terminal):
java -version
javac -version

Sunday, 4 September 2011

Windows, Java and Geany

One of these things that happen in the worst possible moment...

If you want to use the nice and simple Geany IDE under Windows, I'd recommend you to install all the programming languages before you install Geany.

In my case, installing Java and then Geany didn't work at all. Geany wasn't able to compile or execute my Java code. Even after uninstalling and reinstalling both Geany and Java in all possible combinations.

Hope this warning will help someone out there.

Note: Newer versions of Geany have been released, they may have overcome this problem, but I still install Geany after JDK (Java Development Kit) to avoid issues.

Saturday, 23 April 2011

Python 2.7 Mac OS X uninstall

The complete list is documented at http://bugs.python.org/issue7107. The following steps are done inside a terminal session and assume you know how to use the command line. All the terminal command lines below are single lines, even if they appear as two lines in your web browser or this blog post.

To completely remove Python 2.7 from my Mac OS X 10.6:

Remove the entry from the PATH variable by reverting my .bash_profile, edit or delete the file:
nano .bash_profile (remove the PATH lines added by the Python installer, they are commented, so you'll se them easily)
Remove the Python 2.7 framework:
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
Remove the Python 2.7 applications directory
sudo rm -rf "/Applications/Python 2.7"
Remove the symbolic that point back to the 2.7 framework in /usr/local/bin:
Find them with the following ls command, then remove with sudo rm -rf like in the previous steps.
ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7'
In my case, I typed the following commands following the output of the previous ls line:
cd /usr/local/bin 
sudo rm -rf 2to3 idle idle2.7 pydoc pydoc2.7 python python-32 python-config pythonw pythonw-32 smtpd.py smtpd2.7.py


Information taken from:
http://stackoverflow.com/questions/3819449/how-to-uninstall-python-2-7-on-a-mac-os-x-10-6-4
Credits to the users listed there, especially Ned, who answered the question in such a clear and concise way.

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 ...