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

Sunday, February 26, 2017

Scanner input problem: nextLine combined with next/nextInt/nextDouble


nextInt() or nextDouble() takes one number and leaves "enter" in the
keyboard buffer.

next() takes one word and leaves "enter" in the keyboard buffer.

nextLine() keeps taking characters until "enter" and removes the
"enter" from keyboard buffer. So it effectively takes one sentence /
full name etc.

So, nextLine() written after nextInt() or nextDouble() or next() does
not work as expected because it takes that "enter" only which is left
by previous nextInt()/nextDouble()/next() and finishes its work.

In order to skip that unwanted "enter", use scanner.skip("[\r\n]+")
like in the following example.

//way 1 of 2:

       int n = scanner.nextInt();
        //following line is optional as nextInt/nextDouble/next() can skip "enter"
        scanner.skip("[\r\n]+");
        int m = scanner.nextInt();
        //following line is must, for the nextLine below to work
        scanner.skip("[\r\n]+");
        String fullName = scanner.nextLine();
        out.println("n="+n);
        out.println("m="+m);
        out.println("fullName="+fullName+"=");


//way 2 of 2:

        int n = scanner.nextInt();
        //following line is optional as nextInt/nextDouble/next() can skip "enter"
         scanner.skip("[\r\n]+");
        int m = scanner.nextInt();
        //following line is must for the fullName=..nextLine below to work
        scanner.nextLine();
        String fullName = scanner.nextLine();
        out.println("n="+n);
        out.println("m="+m);
        out.println("fullName="+fullName+"=");


Reference:
http://stackoverflow.com/questions/13102045/skipping-nextline-after-using-next-nextint-or-other-nextfoo-methods

Wednesday, November 30, 2016

IndexOutOfBoundsException

public class ExceptionDemo{
    public static void main(String[] args){
        int[] array = new int[2];
        try {
            System.out.println(array[100]);//non-existent
        } catch (IndexOutOfBoundsException ex){
            StackTraceElement[] e = ex.getStackTrace();
            System.err.println("Got error= " + ex + "\n"+
                               "in file "+e[0].getFileName() +"\n"+
                               "in class "+e[0].getClassName() +"\n"+
                               "in method "+e[0].getMethodName() +"\n"+
                               "in line "+e[0].getLineNumber());
            System.err.println("Full trace= ");
            ex.printStackTrace(System.err);
        }
        System.out.println("As Salamu Alaikum");
    }
}


Reference:
https://docs.oracle.com/javase/tutorial/essential/exceptions/
http://docs.oracle.com/javase/8/docs/api/java/lang/StackTraceElement.html
http://stackoverflow.com/questions/30437019/include-filename-line-number-corresponding-to-system-out-print-statements-in-ecl

Saturday, October 8, 2016

Offline Map:
http://maps.me
https://osmand.net

Street
https://www.mapillary.com/

GPS:
GPX Logger
GPS Logger
GPS Essentials


OSM Data Collection
OSM Tracker
Mapzen
Vespuscci
Mapswipe
GeoMaptool  (customized from ODK, from Sirajganj)

Worldwide Disaster Mapping
http://tasks.hotosm.org


Little Apps
Visualize:
CartoDB
Compare: 
http://osmfight.neis-one.org/
3D
http://demo.f4map.com/
OpenSourceGIS
QGis


Others:
http://openstreetview.org/
http://2016.stateofthemap.org/
http://www.omkserver.com/
http://wiki.osmfoundation.org/w/index.php?title=Licence/Why_would_I_want_my_contributions_to_be_public_domain&redirect=no



OpenStreetMap:
https://www.openstreetmap.org
http://osmlab.github.io/show-me-the-way/

Photo:
http://wiki.openstreetmap.org/wiki/Photo_mapping


JOSM:
https://josm.openstreetmap.de/

I was having connectivity issues while downloading map in JOSM
launching JAR from command line showed more details about what was going on

tried with both 10768 and the latest version

Problems were:
connection timed out, 
unknownhost

Following things did not help
Setting proxy
Replace https with http
replacing domain names with IP

Finally, organizers found out that running following line in the command prompt solves the problem

setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true

JOSM , OpenStreetMap and Map

Offline Map:
http://maps.me
https://osmand.net

Street
https://www.mapillary.com/

GPS:
GPX Logger
GPS Logger
GPS Essentials


OSM Data Collection
OSM Tracker
Mapzen
Vespuscci
Mapswipe
GeoMaptool  (customized from ODK, from Sirajganj)

Worldwide Disaster Mapping
http://tasks.hotosm.org


Little Apps
Visualize:
CartoDB
Compare: 
http://osmfight.neis-one.org/
3D
http://demo.f4map.com/
OpenSourceGIS
QGis


http://www.omkserver.com/



OpenStreetMap:
https://www.openstreetmap.org
http://osmlab.github.io/show-me-the-way/

Photo:
http://wiki.openstreetmap.org/wiki/Photo_mapping


JOSM:
https://josm.openstreetmap.de/

I was having connectivity issues while downloading map in JOSM
launching JAR from command line showed more details about what was going on

tried with both 10768 and the latest version

Problems were:
connection timed out, 
unknownhost

Following things did not help
Setting proxy
Replace https with http
replacing domain names with IP

Finally, organizers found out that running following line in the command prompt solves the problem

setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true

Saturday, September 3, 2016

Sharing Internet via WiFI

Sharing LAN Internet connectivity from laptop or desktop with wifi/wlan card. to other laptops / phones


open cmd in administrative mode

To start the network, copy paste the following two lines

netsh wlan set hostednetwork mode=allow ssid=MyWiFi key=MyPasswordHere

netsh wlan start hostednetwork



to stop the network, copy paste the following line

netsh wlan stop hostednetwork



to connect to it, use the following from phone or other laptops
Wifi name (SSID):
MyWiFi

password:
MyPasswordHere