Monthly Archives: March 2014

Web

Set width and height to empty link A tag in HTML

link_empty
You are probably deal with link (A-tag) in HTML. But how we can set size if it is empty, i.e. with no content?
Here is example solution:

<!DOCTYPE html>
<html>
    <head>
        <style>
        a.link1, a.link2, a.link3 {display:block; 
            width: 100px; height: 100px;
            margin: 5px; float: left;}
        a.link1 {background-color: red;}
        a.link2 {background-color: green;}
        a.link3 {background-color: blue;}
        </style>
    </head>
    <body>
        <a href="#1"></a>
        <a href="#2"></a>
        <a href="#3"></a>
    </body>
</html>

As you can see, the key feature is adding display:block; to A-tag style.
Enjoy!

Actually, about polymorphism in OOP

polymorphism
What about polymorphism?
Did you know polymorphism works with interfaces only, but not with inheritance?
Look here.

BaseClass.java

public class BaseClass {

    private String var = "i'm in base!";

    public void method() {
        System.out.println("Hello from base.");
    }

    public String getVar() {
        return var;
    }
}

ExtClass.java

public class ExtClass extends BaseClass {

    private String var = "i'm in EXT!!!";

    @Override
    public void method() {
        System.out.println("Hello from EXT!!!");
    }

    @Override
    public String getVar() {
        return var;
    }
}

Test1.java

public class Test1 {

    public static void main(String[] args) {

        System.out.println("# BaseClass:");
        System.out.println("------------");
        BaseClass baseClass = new BaseClass();
        System.out.println("var = " + baseClass.getVar());
        baseClass.method();
        System.out.println("");

        System.out.println("# ExtClass:");
        System.out.println("-----------");
        ExtClass extClass = new ExtClass();
        System.out.println("var = " + extClass.getVar());
        extClass.method();
        System.out.println("");

        System.out.println("# Cast ExtClass to BaseClass:");
        System.out.println("-----------------------------");
        BaseClass baseClassCasted = (BaseClass) extClass;
        System.out.println("var = " + baseClassCasted.getVar());
        baseClassCasted.method();
        System.out.println("");
    }
}

The result:

# BaseClass:
------------
var = i'm in base!
Hello from base.

# ExtClass:
-----------
var = i'm in EXT!!!
Hello from EXT!!!

# Cast ExtClass to BaseClass:
-----------------------------
var = i'm in EXT!!!
Hello from EXT!!!

But how we can access to the base class?
And if you really have to invoke method from casted class, use implementation!
Meth.java

public interface Meth {

    void method();

    String getVar();
}

BaseClass.java

public class BaseClass implements Meth {

    private String var = "i'm in base!";

    @Override
    public void method() {
        System.out.println("Hello from base.");
    }

    @Override
    public String getVar() {
        return var;
    }
}

ExtClass.java

    private String var = "i'm in EXT!!!";

    @Override
    public void method() {
        System.out.println("Hello from EXT!!!");
    }

    @Override
    public String getVar() {
        return var;
    }

Test1.java

        System.out.println("# interface from BaseClass:");
        System.out.println("-----------");
        Meth baseMeth = new BaseClass();
        System.out.println("var = " + baseMeth.getVar());
        baseMeth.method();
        System.out.println("");

        System.out.println("# interface from ExtClass:");
        System.out.println("-----------");
        Meth extMeth = new ExtClass();
        System.out.println("var = " + extMeth.getVar());
        extMeth.method();
        System.out.println("");

And here we have:

# interface from BaseClass:
-----------
var = i'm in base!
Hello from base.

# interface from ExtClass:
-----------
var = i'm in EXT!!!
Hello from EXT!!!

And now all as you expect!

PS. All code in java. Have fun!

Delete files and folders with long names in Windows

four-file-folders
Using command line you can delete files and folders with long names:

  rmdir /S /Q <FOLDER_NAME_TO_DELETE>