2024年10月6日 星期日

how to recover the windows desktop in an RDP session

使用遠端桌面 (RDP) 工具連線到遠方 Windows 電腦時,有時候不小心關閉或弄壞了檔案總管 ( explorer.exe) 行程,導致工作列消失,或桌面變成一片黑,無法操作。這種情況下,毋須驚慌,以下是一步步如何啟動 工作管理員 (Task Manager),恢復桌面的方法。

  1. 步驟一:打開命令列視窗 (CMD)
    1. 打開工作管理員:按下 Windows Key + X  或 Ctrl + Shift + Esc 或 Ctrl + Alt + End,然後選擇「工作管理員」。
    2. 啟動新工作:在工作管理員中,點擊「檔案」選單,然後選擇「執行新工作」。
    3. 輸入命令:在彈出的對話框中,輸入 cmd,然後按下「確定」或 Enter 鍵。

  2. 步驟二:登出並重新登入
    1. 輸入登出命令:在命令提示字元後,輸入以下指令並按下 Enter:
      shutdown /l
      這個關機指令加上 (l)ogout 登出參數,會立即登出當前使用者。
    2. 重新登入:登出後,重新登入你的帳號。此時,桌面應該會恢復正常。

這個方法利用了 Windows 的內建功能來解決因誤操作導致的桌面消失問題。通過工作管理員啟動命令提示字元,然後使用登出命令,再重新登入,可以快速恢復桌面環境。這是一個簡單而有效的解決方案,適用於遠端桌面連線遇到類似無法操作的情況。

2024年10月5日 星期六

is an object with a string field mutable or immutable

In Java, strings are immutable objects. You might wonder if an object contains a String field which can be changed to other strings, is it an immutable or mutable object?

In fact, an object is considered immutable if its state cannot be changed after it is created. This means that all fields of the object must be final and cannot be modified after the object is constructed. Even though String objects themselves are immutable, if an object contains a field of type String that can be changed to reference a different String object, then the containing object is considered mutable. This is because the state of the object (i.e., the value of the String field) can change.

Here’s an example to illustrate this:

public class MutableObject {
    private String mutableField;  // fields without final can be changed

    public MutableObject(String initialField) {
        this.mutableField = initialField;
    }

    public void setMutableField(String newField) {
        this.mutableField = newField;
    }

    public String getMutableField() {
        return mutableField;
    }
}

In this example, MutableObject is mutable because the mutableField can be changed using the setMutableField method.

On the other hand, an immutable object would look like this:

public final class ImmutableObject {
    private final String immutableField; // final fields cannot be changed

    public ImmutableObject(String initialField) {
        this.immutableField = initialField;
    }

    public String getImmutableField() {
        return immutableField;
    }
}

In this case, ImmutableObject is immutable because the immutableField is final and cannot be changed after the object is created.

So, if your object allows its String field to be changed, it is considered mutable.