static variable can be changed

as long as it is not “final”

public class StaticDemo {
static String name;

public static void staticVariable() {
name = name + ” ” + “Singh”;
System.out.println(“Value of static variable after method calling : ”
+ name);
}

public static void main(String[] args) {
System.out.println(“Initial value of static variable : ”
+ StaticDemo.name);
StaticDemo.name = “Bharat”;
System.out.println(“Value of static variable after initialization : ”
+ StaticDemo.name);
StaticDemo.staticVariable();
}

}

output:

Initial value of static variable : null
Value of static variable after initialization : Bharat
Value of static variable after method calling : Bharat Singh

reference in java and pointer in C

http://programmers.stackexchange.com/questions/141834/how-is-a-java-reference-different-from-a-c-pointer

References might be implemented by storing the address. Usually Java references will be implemented as pointers, but that’s not required by the specification. They may be using an additional layer of indirection to enable easier garbage collection. But in the end it will (almost always) boil down to (C-style) pointers being involved in the implementation of (Java-style) references.

You can’t do pointer arithmetic with references. The most important difference between a pointer in C and a reference in Java is that you can’t actually get to (and manipulate) the underlying value of a reference in Java. In other words: you can’t do pointer arithmetic.

In C you can add something to a pointer (i.e. the address) or substract something to point to things that are “nearby” or point to places that are at any place.

In Java, a reference points to one thing and that thing only. You can make a variable hold a different reference, but you can’t just ask it to point to “the thing after the original thing”.

References are strongly typed. Another difference is that the type of a reference is much more strictly controlled in Java than the type of a pointer is in C. In C you can have an int* and cast it to a char* and just re-interpret the memory at that location. That re-interpretation doesn’t work in Java: you can only interpret the object at the other end of the reference as something that it already is (i.e. you can cast a Object reference to String reference only if the object pointed to is actually a String).

Those differences make C pointers more powerful, but also more dangerous. Both of those possibilities (pointer arithmetic and re-interpreting the values being pointed to) add flexibility to C and are the source of some of the power of the language. But they are also big sources of problems, because if used incorrectly they can easily break assumptions that your code is built around. And it’s pretty easy to use them incorrectly.

java command line option

http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=%2Fcom.ibm.java.doc.diagnostics.60%2Fdiag%2Fappendixes%2Fcmdline%2Fcommands_jvm.html

-cp, -classpath <directories and compressed or .jar files separated by : (; on Windows)>
Sets the search path for application classes and resources. If -classpath and -cp are not used, and the CLASSPATH environment variable is not set, the user classpath is, by default, the current directory (.).
-help, -?
Prints a usage message.

linux keyboard shortcut

 Ctrl+a 把光标移到行首。

 Ctrl+e 把光标移到行尾。

 Ctrl+l  清除终端。该快捷操作与在命令行键入clear作用相同。

 Ctrl+d 从Shell提示中注销并关闭,使用该快捷键就不必键入exit。

 Ctrl+u 清除光标处到行首的字符。

 Ctrl+k 删除从光标到行末所有字符。

 Ctrl+p 显示上一条命令

 Ctrl+n 显示下一条命令(在执行了Ctrl+p后才有效果)

 Ctrl+f 光标向右移动一个字符

 Ctrl+b 光标向左移动一个字符

 Alt+f   光标向右移动一个单词

 Alt+b  光标向左移动一个单词

 Ctrl+r 逆向搜索包含输入字符串的命令,继续按 Ctrl+r,再向上搜索,可使用 Ctrl+c 中断命令 (这个很强大有木有!!)

 Ctrl+w 剪切光标所在处之前的一个词 (以空格、标点等为分隔符)

 Ctrl+y 粘贴(就是粘贴Ctrl+w, Ctrl+k, Ctrl+u等命令剪切删除的内容)

 Alt+u 将光标所在处的单词转为大写 (从光标处到词的结尾) 我承认现在的命令都是小写, 这个使用率不高

 Alt+l 将光标所在处的单词转为小写 (从光标处到词的结尾)

 Alt+c 将光标所在处的单词转为首字母大写 (从光标处到词的结尾)

 Ctrl+c 中断命令

 Ctrl+s 挂起当前 shell (命令输入不了, 像是卡死了一样)

 Ctrl+q 重新启用挂起的 shell (收拾上条快捷键闯下的祸)

 Ctrl+z 暂停命令

 reset Resets the terminal if terminal screen is not displaying correctly.

cast

Foo foo = (Foo) bar;

cast first check if bar is an isInstanceOf Foo, if it is then ok. otherwise a cast exception will be thrown.

Class Bar extends Foo => Bar is an instance of Foo

widening

byte (1 byte) => char (2 bytes) => short (2 bytes) => int ( 4 bytes) => long (8 bytes)int num = ‘a’; // automatically without loss ( higher bit is filled with zeros)

char a = 1; // has error

char a = (char) 1; // casting, has loss with only the lower bits kepts