Sunday, February 25, 2018

Checking String for Equality

Note: Your feedback on how to improve this post is most welcome.

For comparing String values, ==, !=, >, < are not appropriate. These are better suited to numbers.

For Strings, use something like
Scanner sc = new Scanner(System.in);
System.out.println("Please type + or - or *");
String operator = sc.next();
if (operator.equals ("+"))
{
     System.out.println("you gave a plus sign");
}
else
{
     System.out.println("you gave something else");
}


Recommended reading:

for regular students:
http://alvinalexander.com/java/edu/qanda/pjqa00001.shtml

for advanced learners:
http://docs.oracle.com/javase/tutorial/java/data/comparestrings.html
https://www.javaworld.com/article/2077355/core-java/don-t-be-strung-along.html
https://www.baeldung.com/java-compare-strings


Want to learn more about characters and strings?
https://www.javaworld.com/article/2074031/core-java/jdk-7--java-switching-on-strings-is-here.html
https://www.javaworld.com/article/2074647/core-java/core-java-java-s-character-and-assorted-string-classes-support-text-processing.html

Thursday, February 8, 2018

The Story of a TINY FROG

Also available on many sites including http://slideplayer.com/slide/3166044/

------- Forwarded message ----------
From: Chowdhury Farsad Aurangzeb

TINY FROGS

Once upon a time there was a bunch of tiny frogs.... who arranged a running competition.

The goal was to reach the top of a very high tower.

A big crowd had gathered around the tower to see the race and cheer on the contestants....

The race began....

Honestly:

No one in the crowd really believed that the tiny frogs would reach the top of the tower.

You heard statements such as:

"Oh, WAY too difficult!!"

"They will NEVER make it to the top."

or:

"Not a chance that they will succeed. The tower is too high!"

The tiny frogs began collapsing. One by one....

Except for those, who in a fresh tempo, were climbing higher and higher....

The crowd continued to yell,  "It is too difficult!!! No one will make it!"

More tiny frogs got tired and gave up....

But ONE continued higher and higher and higher....

This one wouldn't give up!

At the end everyone else had given up climbing the tower. Except for the one
tiny frog who, after a big effort, was the only one who reached the top!

THEN all of the other tiny frogs naturally wanted to know how this one frog
managed to do it?

A contestant asked the tiny frog how he had found the strength to succeed
and reach the goal?

It turned out....

That the winner was DEAF!!!!
 
The wisdom of this story is:

Never listen to other people's tendencies to be
 negative or pessimistic....  

because they take your most wonderful dreams
and wishes away from you -- the ones you have in your heart!

Always think of the power words have.

Because everything you hear and read will affect your actions!

Therefore:

ALWAYS be....

POSITIVE!

And above all:

Be DEAF when people tell YOU that you cannot fulfill your dreams!

Always think:

God and I can do this!



---------- Forwarded message ----------
From: Chowdhury Farsad Aurangzeb 
Throughout the semester students get frustrated with studies (like: Programming, maths and etc..). In this situations we have to be the Tiny Frog and inspire ourselves and avoid hearing what people are saying negative about us. If we can't succeed, we have to keep on trying till we can achieve the actual goal. If you fail and keep on trying people might say things that might hold you back and might dis-inspire you  but give damn to those people and keep on trying because the actual LOSER gives up the moment people starts talking negative about them... 

Saturday, January 13, 2018

Software Engineering

All Circuits are Busy Now: The 1990 AT&T Long Distance Network Collapse
http://users.csc.calpoly.edu/~jdalbey/SWE/Papers/att_collapse.html

Wednesday, January 10, 2018

Improving Java Programming Skills

Disclaimer: Found any inaccuracy? Please let me know how to improve this article further.
==================================

Logic
=======

  • How to Solve it by Computer by R. G. Dromey


Basic Coding
===========


Advanced Coding
==============

  • OCA Java SE Programmer Exam Guide by Kathy Sierra and Bert Bates
  • Effective Java by Joshua Bloch
  • Java Puzzlers: Traps, Pitfalls, and Corner Cases by Joseph Samuel Bloch and Neal Gafter
  • Core Java by Cay Horstmann
  • http://www.javaworld.com


Basic video
======

Programming Language Level 1 (CSE110)
==============
Video 1 to 42 of http://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28


Programming Language Level 2 (CSE111)
==============
Video 27 to last of http://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28

and Video 1 to 3 of http://www.youtube.com/playlist?list=PL27BCE863B6A864E3


Programming Language Level 2 (CSE310)
==============
http://www.youtube.com/playlist?list=PL27BCE863B6A864E3





Next levels:
========
Data Structures and Algorithms Made Easy in Java: Data Structure and Algorithmic Puzzles
by Narasimha Karumanchi

Solve ACM Programming Contests problems from different online judges like http://topcoder.com



Elements of Programming Interviews in Java: The Insiders' Guide
by Adnan Aziz, Tsung-Hsien Lee, Amit Prakash

Cracking the Coding Interview: Programming Questions and Solutions
by Gayle Laakmann McDowell

Code Complete: A Practical Handbook of Software Construction
by Steve McConnell


need more?

Friday, October 27, 2017

Using Escape Character / Sequences or Special Characters

Disclaimer: If you find any inaccuracy in this article, please let me know how to improve it further.
==================================


List of all escape sequences is available at the bottom of https://docs.oracle.com/javase/tutorial/java/data/characters.html
One of those is "\t";

System.out.println("\t");
or,
System.out.println('\t');

The line above mimics the behavior of the "tab key" present on the keyboard. So, theywork in exactly the same way.

Tab key moves the cursor to the next "tab stops". Tab stops are the places where cursor jumps to, when the tab key is pressed.

In word processing applications such as LibreOffice Writer, you can set the locations or gaps for tab stops. Similarly, remember that we change "indentation level" in Dr Java IDE,  to 5 spaces (instead of 2), that tells amount of spaces the cursor will move when tab is pressed.

By default (since its invention), tab character moves 8 spaces, which is roughly an inch.
This behavior will be visible for the line of text that you print in java or write in notepad or word.

When you are writing some character, you are decreasing the space to be jumped.


For example,
if you only type "tab" and write "hello", it will give 8 spaces and "hello" will appear at 9th position.
If you write "winter", then "tab", then "bye", tab moves the cursor 2 spaces to reach 9th position.
If you write "winterA", then "tab", then "bye", tab moves the cursor 1 space to reach 9th position.
If you write "winterAB", then "tab", then "bye", tab moves the cursor 8 spaces to reach 17th position.

The lines containing hyphens and numbers below are for ease of demonstration only. The output should like as follows:

----\t--
12345678901234567890
        hello
winter  bye
winterA bye
winterAB        bye
12345678901234567890


In short, tab will move the cursor AFTER column positions that are multiples of 8. That is 9, 17, 25 ...... (8n+1) where n = 1, 2, ....

So, number of spaces to be jumped can vary from 1 to 8, depending on how many columns are occupied by previous text in the same line.

In some environments, instead of 8, it becomes 2 or 4 or 5 or 6 etc.
In those cases, tab stops will be at (2n+1) or (4n+1) or (5n+1) or (6n+1) etc.

Find out the behavior of your environment by copying and pasting following lines to the "interaction pane" of DrJava,

System.out.println("----\\t--");
System.out.println("12345678901234567890");
System.out.println("\thello");
System.out.println("winter\tbye");
System.out.println("winterAB\tbye");
System.out.println("12345678901234567890");


References:
1) http://en.wikipedia.org/wiki/Tab_stop
2) http://en.wikipedia.org/wiki/Tab_key#Usage
3) http://en.wikipedia.org/wiki/LibreOffice_Writer
4) http://www.coderanch.com/t/392682/java/java/tabs-spaces
5) http://cboard.cprogramming.com/c-programming/41287-horizontal-tab-%5Ct-what-determines-number-spaces.html
6) http://mathbits.com/MathBits/Java/Introduction/escapesequences.htm
7) https://docs.oracle.com/javase/tutorial/java/data/characters.html


If you know how to run java programs from commandline/console, then try printing \007 as well if you want to print something more awesome.

Don't forget to follow the steps :
https://web.archive.org/web/20140506231020/http://www.sadafnoor.com/blog/print-sound-java/

Save the program in My computer, directly inside C or D drive or any other drive
For example, as C:\testBeep.java
Then open and compile using DrJava
From Start menu -> Run, type cmd and click ok
From the black cmd / "command prompt" window,
type the following
java testBeep
It should make a beep sound.

Thursday, October 5, 2017

DrJava "Warning: Resource leak: '......' is never closed"

If you receive the following from DrJava "Warning: Resource leak:
'......' is never closed"

It is a warning / suggestion, not an error.
You may wish to add the following line as the last line of your program.
sc.close();
assuming sc is the scanner variable in your programs.

Monday, June 12, 2017

Program / Data Structure and Algorithm Visualization / Simulation

Being able to visualize or simulate how a program, data structure or algorithm is working may help to understand how it is working, help in troubleshooting, teaching, and may be in enhancing it further.
 
Please find some Visualization / Simulation sites below. Please feel free to suggest alternatives.


Data Structure and Algorithm Visualization

VisualGo


David Galles's Site

Algorithms and Data Structures Animations for the Liang Java, C++, and Python Books



Program Visualization

Java
Python, C, C++, Java, JS, Ruby, TypeScript

R

Web Apps (HTML, CSS, JS)


Recommended Reading