Comp sci: asynchronous vs synchronous communication

Tutoring comp sci, you might explain asynchronous communication vs synchronous. The tutor describes them.

Asynchronous communication refers to modes in which the correspondents need not be engaged simultaneously. Email, text messaging, and comment boards facilitate asynchronous communication. In such contexts, the receivers respond at their convenience.

Synchronous communication requires the correspondents to be simultaneously engaged, waiting for incoming messages, reading them as soon as they arrive and responding directly. The motivation for waiting and responding immediately is to continue the stream of communication. A phone call or face-to-face conversation is synchronous communication.

Source:

stackoverflow.com

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Calculator usage: how to use the random integer generator on the Casio fx-991ES PLUS C

Tutoring math or computer science, random numbers are often involved. The tutor shows the convenient random integer generator on the Casio fx-991ES PLUS C.

Example: Generate a random integer between 10 and 89 using the Casio fx-991ES PLUS C.

Solution:

Key in ALPHA . 10 SHIFT ) 89 ) =

HTH:)

Source:

Casio fx-991ES PLUS C User’s Guide.

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Java: overriding methods: what it means, and rules about it

Tutoring Java programming, you might be asked to clarify about overriding. The tutor shares some thoughts.

In Java, when you override a method, you either

  1. define its performance (give it a “body”), or else
  2. redefine (change) its performance
  3. .

Case 1, above, refers to the situation of writing a subclass of an abstract class, or implementing an interface: in either case, a method with undefined functionality must (typically) be defined, aka overridden.

Case 2 often refers to the situation of writing a subclass that alters the performance of an inherited method. However, an instance of a class can have a method overridden as well.

Rules:

When overriding a method, its return type, name, and parameter list (including types) must be identical to its original ones [from the abstract class, interface, or base class].

@Override can be used at the beginning of the line where the override is declared. For example:

@Override public void method_x(String param0, int param1,….){

This may give the compiler extra opportunity to check the validity of the override, as well as improve the code’s human readability.

Source:

docs.oracle.com

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Java compile error: non-static method cannot be referenced from a static context – what causes it?

Tutoring Java programming, this error message might come up. The tutor talks about a couple of its causes.

The message

error: non-static method MethodX() cannot be referenced from a static context

has a couple of causes I know:

  1. The class that contains the static main method contains another method other_method that isn’t static. other_method can’t be called from the static one unless it, too, is declared static.
  2. An object has been created [Objectx Ox = new Objectx();], but then its method methodx() is called using the class name [Objectx.methodx();]
    as opposed to the instance name [Ox.methodx();]

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Java programming: constructors in subclasses

Tutoring Java programming, there are so many interesting facets to encounter. The tutor talks about a constructor of a subclass and the word super.

Let’s imagine you write a subclass. Furthermore, let’s imagine the parent class (the superclass) has a detailed constructor. Can you assume that the subclass will simply inherit the parent’s constructor and default to its use? Apparently not.

My situation: I wrote a subclass of an abstract class that, while abstract, has a well-defined constructor. In the subclass I just defined the abstract functions from the parent. The compiler protested, citing a mismatch between the parameters required for the constructor versus those given. I looked up the problem.

Apparently, to a subclass, the compiler provides a default constructor with no arguments.

To instill the parent’s constructor in the subclass, one can declare a constructor in the subclass with the same parameters as those of the superclass’ constructor, then call super(parameter list).

Let’s imagine a parent class PC like so:

class PC{

String name;
String color;

public PC(String name, String color){
this.name=name;
this.color=color;
}//end of constructor

}

Now, the subclass SC:

class SC extends PC{

public SC(String name, String color){
super(name,color);
}//end constructor

}

From my observation, the code in the blue rectangles above is what will make the subclass take on the parent’s constructor.

Source:

docs.oracle.com

journals.ecs.soton.ac.uk/java

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Computers: why flash drives aren’t vulnerable to magnets (supposedly)

Tutoring, you see flash drives carried around with anything stored on them. The tutor shares some findings about them in relation to magnetism.

I recall holding a flash drive with a magnetic lid, and wondering how it could be so.

Apparently, flash drives hold information using electric charges, rather than magnetism. Two websites tell me that, for that reason, flash drives are not changeable by magnetism – at least, not under normal conditions.

Magnetism and electricity are related. Specifically, a changing magnetic field (for instance, as the magnet moves nearby) can cause voltage in a loop of wire. Therefore, I wouldn’t experiment with a flash drive near a magnet if the data was important.

Source:

beta.machinedesign.com

www.pcworld.com

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

English, computer science: disk vs disc

Tutoring English, different versions of familiar words are interesting. The tutor shares a find.

In the context of computers, I recall reading disk. “Is it disc?” I would often wonder. Today the matter surfaced, so I looked it up. I got two points of view:

Collins:

Disk is particularly used in the context of computers, such as hard disk drive (hdd). Disc can be used that way as well, but is the proper way to refer to disc brakes, flying disc, disc jockey, etc.

Merriam-Webster:

Disk and disc are interchangeable. Disk jockey is valid.

Source:

Collins Essential Canadian English Dictionary and Thesaurus. Glasgow: HarperCollins Publishers, 2006.

Merriam-Webster Dictionary. Springfield: Merriam-Webster, 2004.

searchstorage.techtarget.com

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Perl: int() function: isolating a digit

Tutoring computer science, extracting a digit is a suggested exercise. The tutor shows a use of Perl’s int() function.

Let’s imagine you want to find the hundred-thousands digit of an input number. You can do so with the following code:

$digit=(int($input_number/100000))%10;

In the code above, the $input_number is first divided by 100000, which will likely give a decimal. Then, int() simply removes the decimal places, but doesn’t round. Next, %10 gives the remainder when the result is divided by 10. This is needed if the input number is a place past the hundred thousands; eg., the millions, ten millions, etc.

HTH:)

McGrath, Mike. Perl in easy steps. Southam: Computer Step, 2004.

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Perl: regular expressions: yesterday’s code explained

The tutor tells the workings of yesterday’s pattern matching example.

In yesterday’s post I mention that the regular expression

if ($input=~/item1[^0-9]*[0-9]*.?[0-9]{0,2}/i)

can find the pattern item1….$#####.## in a longer string. Here are some explanatory points:

  • =~ is the pattern find operator, which finds the pattern defined on the right in the string on the left.
  • Between / / is the pattern to be matched.
  • item1, between / /, means the literal string item1.
  • [^0-9]* means not numbers, while the asterisk means 0 or more.
  • [0-9]* means numbers only, 0 or more of them.
  • .? means possibly a single decimal point, but maybe none.
  • [0-9]{0,2} means numbers, 0 to 2 of them.
  • The i after the closing slash means case insensitivity: item1 or Item1 will be found.
  • The match, if found, is put in the variable $&, which can afterwards be printed or fetched as desired.

HTH:)

Source:

McGrath, Mike. Perl in easy steps. Southam: Computer Step, 2004.

www.tutorialspoint.com

robert’s perl tutorial

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Perl: using regex (aka regular expression, pattern matching) to find an item and its price in a string

The tutor demonstrates a Perl regular expression that finds an item name and its price in a string.

Suppose you believe that the price of item1 is given in a string, but aren’t sure how exactly it’s said. It could, for instance, say

Item1: $56.77

or

He likes the price of item1 not above $101.21, but understands it may go up soon….

A search for the portion of the string containing item1…$####.## can be executed as follows:

#!/usr/bin/perl
print “Enter the string, please.”;
$input=<STDIN>;
if($input=~/item1[^0-9]*[0-9]*.?[0-9]{0,2}/i){
print “$&\n”;
}
else{
print “Sorry: no match.\n”;
}

I’ll be explaining the workings of this code next post:)

Source:

www.tutorialspoint.com

robert’s perl tutorial

McGrath, Mike. Perl in easy steps. Southam: Computer Step, 2004.

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.