Saturday, November 30, 2019

Awt vs Swing

One aspect of java I have been looking into is
the difference between awt and swing to create user
interfaces in java. awt is the older model - and slower -whereas
swing is the newer. Below, creating a pop-up window with both.

The first, from a Cyan Code tutorial, uses swing. Interestingly,
the Eclipse interface points out that .awt is never used for this code.
The second uses awt only, and is very different. Swing comes with
all its own specifications, whereas awt uses those of the platform. My
swing window is a tasteful beige, whereas the awt one is default white.

The maddening thing about the awt, though, is that the windows - once
opened - are impossible to close. And it won't take the 'close on exit' command!
I'm going to have to restart the computer.






Friday, November 29, 2019

Java_Lesson(10) Other classes

Starting to find my way on the java Eclipse interface.
One useful shortcut to know is syso, which one
sets form Windows-> preferences. Once it is enabled,
one merely types syso, hold down Ctrl, tap on the space 
bar and the System.out.println...command appears
automatically. 👍



                            *     *     *

So how does one put together a longish set of java commands.
Everything will happen from the Main class and its public
static void main method. Within that, one merely calls class/method
pairs one has created on other pages.

To recap: Create a new project;
a new main class from src;
a new class from source public, static;
syso from class two;
save and run from Main.

One is further free to do more within Main...





Thursday, November 28, 2019

HAPPY!

In French it is called a 'cocktail météo', when any of a wide variety
of precipitation and weather conditions can prevail. Which seems to be the case
for many Americans on this Thanksgiving day.

Still, it is a grand family holiday...


Wednesday, November 27, 2019

Pondering

The matter is controversial: constant exposure to screens
of different kinds can be detrimental, especially to young children
whose brains are in a developmental stage.

Indeed, I have been thinking about a recently published in French
work to the effect that collectively, current generations are experiencing a
lowering of intelligence, something quite unheard of in historical memory.
What could be the mechanism at work here, interfering with brain
development.

Human vision is quite an elaborate and well honed affair: we have two eyes,
each ofwhich capture incoming light through a lens. Remarkable that it is shifting.
I have a plate of cookies and a glass of milk on either side of my plate. Without
moving my head, I can focus on the milk and see the cookies in profile, or focus
on the cookies and see the glass of milk in profile. My brain has done all the work.
Neither a painter nor a photographer can give me that experience; both can put
the cookies and milk in a two-dimentional image, but neither can make that
adjustment of shifting for me. And it is how my brain orients me.

Something to ponder...

https://www.librairie-publico.com/spip.php?article2693

Tuesday, November 26, 2019

Java_Lesson(9) Random

Been looking at generating a random number from the Windows
Command Line. The number will be between 0 and 32,767 exclusive
of the latter. The seed value is tied to the computer timer, so it is
not considered a safe source of randomness for cryptographic
purposes. (I have read that if two people ask for a random within
the same second interval, they will get the same number.!!)

Below, if I ask my computer sequentially, I get two different numbers.
But as an administrator, I can generate a random that gets a double
posting easily enough...






*     *     *

In the context of Java, the random utility can produce different
varieties of numbers. Below, I reproduce the Cyan Code random integer
at work. But I could well have asked for a random double.

The integer is needed in this situation to pick an array member - which run
from 0 to 4 as members - but 1 to 5 as a sequence. Running the code again 
and again gives a different course, most of the time.







Saturday, November 23, 2019

Java_Lesson(8) Downloading

I can get unto the web easily enough from the
command line using the start command:


One thing to notice; I asked to go to blogspot and ended up on my blog's
interface page using my deafault browser, Edge. So the settings on my machine
were used...

Today's probelm is downloading an image with java and, hopefully,
from the command line!

                                                       *     *     *

Success! using Cyan Code Lesson 16 Java code.


This command line takes me to the Imgur page:


I can open an image on the desktop with start as well:


The & symbol permits a sequence of commands on the Windows
command line.

Friday, November 22, 2019

Java_Lesson(7) Arrays

The Cyan Code  tutorial on arrays explained it nicely:
all the members in the array are of the same type, here Strings.
The array construct is a form of short-cut.

The example works through as expected.


If I want just one item, I merely ask for it: [2]
is the third item.



i cannot be resolved without the for subroutine...

                                           *     *     *

It is tempting to think one needs a programming language sitting on top of the
operating system to produce such a result, but that would be false. One
can create arrays in the command line easily enough.

https://www.tutorialspoint.com/batch_script/batch_script_arrays.htm

We are dealing here with flow control systems, and this came about with ALGOL58.
an algebraic language developed by an international group in 1958.

https://en.wikipedia.org/wiki/ALGOL_58

Batch files (Windows)  are procedures written up on a text editor
and run from the command line. They are a time-saving adjunct for
system administrators.

Libre Draw

Recently istalled the Curent Libre Office on my Windows
computer. The draw functions are evolving nicely.

In my defensw for the following; they were done without a model!!



Thursday, November 21, 2019

Tonight!

Lyse is performing again tonight, with her Band Junk Science.



Wednesday, November 20, 2019

Lesson 6 Cont'd

This time, looked at writing to a file with java.
It is actually the same process as with the Command
Prompt:


code source: Cyan Code


*     *     *
It is also possible to read programatically from a file.
The nest day, adding a line for Thursday and retrieving it:



                                              *     *     *

From the Command Line:


This shows the text one page at a time...


Tuesday, November 19, 2019

Freezing Rain


Today was a day of weather misery in Montreal with freezing rain
all morning. The Internet wasn't that much cheerier, with
Revenge of the Swamp Creatures out of Washington.
At least tomorrow should be interesting, with the announcement
of the new Trudeau Cabinet.

Got stuff down around the apartment, and was happy to find on
one of Cyan Code Java tutorial the existence of Pastebin.com, which allows
people to share code more easily. Code on that site  can be merely
copied and pasted, no fuss. I took down the Simple Calculator (just
make sure to close the scanner after all correct outcomes).




I also had the great joy of finding one can  download Microsoft
Expression IV. It is a really good place to work on one's Bezier Tool
skills...I will be looking into this in a future posting.

https://www.microsoft.com/en-us/download/details.aspx?id=36180&751be11f-ede8-5a0c-058c-2ee190a24fa6=True

Monday, November 18, 2019

Timed out

Got exasperated waiting for my favourite MSN game a little while
ago so I ran a ping test. Sure enough, they are not responding. Blogspot,
which hosts this blog, was...


An interesting twist: I can send the ping data to a text file in MyDaily
without ever seeing it. I could, for example, run a ping test every day at
10 am and accunmulate the data. the above creates the Traffic.txt file.



Java_Lesson(6) Writing to a File

Today I will work on writing to file, that is,
adding text to a file programatically. For comparison,
I will first do this from the Windows Command Prompt.

First, I want to create a folder on the desk top. i navigate
to the Desktop with the cd command, and use mkdir to
create the folder and give it a name.



Next, I want to write to a text file within it. I could ask cmd to open
NotePad with the .exe command, but I will write directly. So I
echo the text I want to enter and using >create the text in Notepad
called Weight.txt. Had the latter already existed in MyDaily , I would have
overwritten in it.


It's Monday the 11 and I want to make a new entry. Using @ before echo
creates a new line. Double arrow, >>; adds the text rather than overwriting.


Need to do this from Java next... Why!? Because I can then create arrays
and enter data.

                                                      *     *     *


*     *     *
Been lax on sugar. A weekly report from MyFitnessPal on sugar:

*     *     *







Saturday, November 16, 2019

SHOWTIME

Lyse and her Punk Group JUNK SCIENCE are up
tonight at l'Hemisphère Gauche:


Lotsa Sounds; below, Simonak:

Java_Lesson(5) Math Objects

Of course, this was coming. A simple switch to 'input'
as an int will allow one to work with mathematical expressions
such as <= for equal or lesser than.


Predictably, user entering decimals will earn us an exception. We could
just work with input as a double, but doing this as a policy amounts to
using too much memory allocation.


The answer is using a try/catch construct. The first condition
will play out if the user entered an int. Alternatively, instead of the
program crashing out in the decimals case, we show an error message
to the user. Storing the value from the user must happen within the
try curly braces!


The program as a whole can proceed once this hurdle passed.


The much maligned do... while loop:

                 
                                                   *     *     *

Why is do...while controversial!? Many student programmers 
have stumbled on it to create an infinite loop (one has to shut
the program down to stop it). The source of error is that a boolean
variable only takes the values true or false. But myBoolean false
(!myBoolean) says that the variable has yet to be initiated ie given a value
to store in memory.

One could actually run the above with correct = false; and it would work the
same.

And for anyone tempted to tamper with (!correct), that's the route to perdition 
with the infinite loop.

It's an oooold joke.