Skip to content


Run npm install Behind Proxy

npm supports to run behind a proxy. Of course, we can set the proxy using command npm config set proxy or npm config set https-proxy which you can refer to

However, we may only want to use a proxy temporarily without change any configuration, thus, we can set proxy through the command line directly,

npm --proxy http://{user}:{pass}@{proxy_hpst}:{proxy_port} install

Configuration notice of the homebrew installed software in macOS

OpenJDK 19

After installed the openjdk19 using homebrew, it shows the following message.

For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.

If you need to have openjdk first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include"

Use Python3 Virtualenv in macos

For different projects may depend on different plugins, and even same plugin with different version. Virtualenv allows us to create different virtualenvs for different projects.

  1. Install the virtualenv pip package

    pip3 install virtualenv

  2. Create virtualenv

    python3 -m virtualenv /path/to/venv

  3. Activate and Use

    source /path/to/venv/bin/activate

Can Java Invoke a Static Method From a Null Object

What's the output of the following program?

  • NPE?

  • 10?

public class NullStaticMethod {

    public static void main(String[] args) {

        String str = null;



Expand to see anwser

The output is: 10

Even str is null, but Java still can invoke the status method defined in the String class.

Java Init Block

Java has two kinds of init code blocks, static init block and init block.

  • While static init block is used to initialize the class level configurations, and,

  • init block is used to initialize instance data members

    • it runs each time when object of the class is created

    • it runs in the order they appear in the program

    • compiler replaces the init block in each constructor after the super() statement

    So, init block is executed before the constructor logic