author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Tue, 07 Feb 2012 16:51:31 +0200 | |
changeset 1215 | 84101bddf00c |
parent 1214 | fe28cec0bb40 |
child 1216 | 7a3ade740d3f |
permissions | -rw-r--r-- |
1213 | 1 |
.. -*- coding: utf-8; -*- |
2 |
||
3 |
================ |
|
4 |
Java language. |
|
5 |
================ |
|
6 |
||
7 |
Class version. |
|
8 |
============== |
|
9 |
||
10 |
See value of 6 and 8 bytes in .class file: |
|
11 |
||
12 |
{0xCA, 0xFE, 0xBA, 0xBE, 0x00, minor, 0x00, major} |
|
13 |
||
14 |
major minor Java platform version |
|
15 |
45 0x27 3 1.0 |
|
16 |
45 0x27 3 1.1 |
|
17 |
46 0x28 0 1.2 |
|
18 |
47 0x29 0 1.3 |
|
19 |
48 0x30 0 1.4 |
|
20 |
49 0x31 0 1.5 |
|
21 |
50 0x32 0 1.6 |
|
22 |
||
23 |
Access modifiers. |
|
24 |
================= |
|
25 |
||
26 |
Public. |
|
27 |
------- |
|
28 |
||
29 |
* Public class is visible in other packages. |
|
30 |
* Public field is visible everywhere (class must be public too). |
|
31 |
||
32 |
Private. |
|
33 |
-------- |
|
34 |
||
35 |
* Private variables or methods may be used only by an instance of the same |
|
36 |
class that declares the variable or method |
|
37 |
* A private feature may only be accessed by the class that owns the feature. |
|
38 |
||
39 |
Protected. |
|
40 |
---------- |
|
41 |
||
42 |
* Is available to all classes in the same package and also available to all |
|
43 |
subclasses of the class that owns the protected feature. |
|
44 |
* This access is provided even to subclasses that reside in a different |
|
45 |
package from the class that owns the protected feature. |
|
46 |
||
47 |
default. |
|
48 |
-------- |
|
49 |
||
50 |
What you get by default ie, without any access modifier. |
|
51 |
||
52 |
* It means that it is visible to all within a particular package. |
|
53 |
||
54 |
static. |
|
55 |
------- |
|
56 |
||
57 |
* Static means one per class, not one for each object no matter how many |
|
58 |
instance of a class might exist. This means that you can use them without |
|
59 |
creating an instance of a class. |
|
60 |
* Static methods are implicitly final, because overriding is done based on |
|
61 |
the type of the object, and static methods are attached to a class, not an |
|
62 |
object. |
|
63 |
* A static method in a superclass can be shadowed by another static method in |
|
64 |
a subclass, as long as the original method was not declared final. |
|
65 |
* You can't override a static method with a nonstatic method. |
|
66 |
||
67 |
final. |
|
68 |
------ |
|
69 |
||
70 |
* A final class can't be extended ie., final class may not be subclassed. |
|
71 |
* A final method can't be overridden when its class is inherited. |
|
72 |
* You can't change value of a final variable. |
|
73 |
||
74 |
Exceptions. |
|
75 |
=========== |
|
76 |
||
77 |
A checked exception is some subclass of Exception (or Exception itself), |
|
78 |
excluding class RuntimeException and its subclasses. |
|
79 |
||
80 |
Unchecked exceptions are RuntimeException and any of its subclasses. Class |
|
81 |
Error and its subclasses also are unchecked. With an unchecked exception, |
|
82 |
however, the compiler doesn't force client programmers either to catch the |
|
83 |
exception or declare it in a throws clause. |
|
84 |
||
85 |
Inner classes. |
|
86 |
============== |
|
87 |
||
88 |
Nested top-level classes. |
|
89 |
------------------------- |
|
90 |
||
91 |
If you declare a class within a class and specify the static modifier, the |
|
92 |
compiler treats the class just like any other top-level class. |
|
93 |
||
94 |
Any class outside the declaring class accesses the nested class with the |
|
95 |
declaring class name acting similarly to a package. eg, outer.inner. Top-level |
|
96 |
inner classes implicitly have access only to static variables. There can also |
|
97 |
be inner interfaces. All of these are of the nested top-level variety. |
|
98 |
||
99 |
Member classes. |
|
100 |
--------------- |
|
101 |
||
102 |
Member inner classes are just like other member methods and member variables |
|
103 |
and access to the member class is restricted, just like methods and variables. |
|
104 |
This means a public member class acts similarly to a nested top-level class. |
|
105 |
||
106 |
The primary difference between member classes and nested top-level classes is |
|
107 |
that member classes have access to the specific instance of the enclosing |
|
108 |
class. |
|
109 |
||
110 |
Local classes. |
|
111 |
-------------- |
|
112 |
||
113 |
Local classes are like local variables, specific to a block of code. Their |
|
114 |
visibility is only within the block of their declaration. In order for the |
|
115 |
class to be useful beyond the declaration block, it would need to implement a |
|
116 |
more publicly available interface. |
|
117 |
||
118 |
Because local classes are not members, the modifiers public, protected, |
|
119 |
private, and static are not usable. |
|
120 |
||
121 |
Anonymous classes. |
|
122 |
------------------ |
|
123 |
||
124 |
Anonymous inner classes extend local inner classes one level further. As |
|
125 |
anonymous classes have no name, you cannot provide a constructor. |
|
126 |
||
127 |
64-bit problem. |
|
128 |
=============== |
|
129 |
||
130 |
http://www.java.com/en/download/faq/java_win64bit.xml |
|
131 |
Which version of Java should I download for my 64-bit Windows |
|
132 |
operating system? |
|
133 |
http://java.sun.com/javase/6/webnotes/install/system-configurations.html |
|
134 |
Java SE 6 Release Notes Supported System Configurations |
|
135 |
||
136 |
Java performance. |
|
137 |
================= |
|
138 |
||
139 |
http://java.sun.com/performance/reference/whitepapers/5.0_performance.html |
|
140 |
http://java.sun.com/performance/reference/whitepapers/6_performance.html |
|
141 |
||
142 |
Creating jar. |
|
143 |
============= |
|
144 |
:: |
|
145 |
||
146 |
$ jar cf myFile.jar *.class |
|
147 |
$ jar cmf myManifestFile myFile.jar *.class |
|
148 |
$ jar -cfe Main.jar foo.Main foo/Main.class |
|
149 |
||
1215 | 150 |
Profiling Java. |
1213 | 151 |
=============== |
152 |
:: |
|
153 |
||
154 |
$ java -Xprof com.vendor.product.Clazz |
|
1214
fe28cec0bb40
java -Xrunhprof:help
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1213
diff
changeset
|
155 |
$ java -Xrunhprof:help |
1213 | 156 |
|
1215 | 157 |
Debugging Java. |
158 |
=============== |
|
159 |
||
160 |
Compile with ``-g`` to preserve source code information:: |
|
161 |
||
162 |
$ javac -g -cp $CLASSPATH -sourcepath $SRC_DIR -d $BUILD_DIR |
|
163 |
||
164 |
To run Java program in debugger:: |
|
165 |
||
166 |
$ jdb -cp $CLASSPATH -sourcepath $SRC_DIR |
|
167 |
||
168 |
To attach to Java application you firstly must run application with:: |
|
169 |
||
170 |
$ java -Xdebug -Xrunjdwp:transport=dt_shmem,server=y,suspend=n,address=$PORT \ |
|
171 |
com.vendor.product.Clazz |
|
172 |
||
173 |
and then attach with debugger:: |
|
174 |
||
175 |
$ jdb -attach $PORT |
|
176 |