java.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 03 Oct 2015 18:29:10 +0300
changeset 1765 2132765de2f4
parent 1687 da4a6ceb7e89
child 1833 378b566fd86b
permissions -rw-r--r--
Cellular automaton.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
.. -*- coding: utf-8; -*-
1334
9bf0d5a1f0cf Include common header with quick links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1270
diff changeset
     2
.. include:: HEADER.rst
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
================
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
 Java language.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
================
1346
a2fbf50a43f4 Fix: Has no 'contents::' directive.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1334
diff changeset
     7
.. contents::
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
Class version.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
==============
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
1216
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    12
  =========  ====== =====================
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    13
  major      minor  Java platform version
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    14
  =========  ====== =====================
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    15
  45 0x27    3      1.0
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    16
  45 0x27    3      1.1
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    17
  46 0x28    0      1.2
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    18
  47 0x29    0      1.3
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    19
  48 0x30    0      1.4
1677
3d2d4e6062f3 New Java byte code versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1655
diff changeset
    20
  49 0x31    0      5.0
3d2d4e6062f3 New Java byte code versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1655
diff changeset
    21
  50 0x32    0      6.0
3d2d4e6062f3 New Java byte code versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1655
diff changeset
    22
  51 0x33    0      7
3d2d4e6062f3 New Java byte code versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1655
diff changeset
    23
  52 0x34    0      8
1216
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    24
  =========  ====== =====================
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
1216
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    26
where ``minor`` and ``major`` are value of 6 and 8 bytes in .class file::
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    27
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    28
  0xCA, 0xFE, 0xBA, 0xBE, 0x00, minor, 0x00, major
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
Access modifiers.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    31
=================
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    32
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    33
Public.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
-------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    35
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
 * Public class is visible in other packages.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    37
 * Public field is visible everywhere (class must be public too).
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    38
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
Private.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
--------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
 * Private variables or methods may be used only by an instance of the same
1216
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    43
   class that declares the variable or method
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
 * A private feature may only be accessed by the class that owns the feature.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
Protected.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    47
----------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    48
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    49
 * Is available to all classes in the same package and also available to all
1216
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    50
   subclasses of the class that owns the protected feature.
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    51
 * This access is provided even to subclasses that reside in a different
1216
7a3ade740d3f Fix RST syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1215
diff changeset
    52
   package from the class that owns the protected feature.
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    53
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    54
default.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    55
--------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    56
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    57
What you get by default ie, without any access modifier.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    58
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    59
 * It means that it is visible to all within a particular package.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    60
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    61
static.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    62
-------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    63
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    64
 * Static means one per class, not one for each object no matter how many
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    65
   instance of a class might exist. This means that you can use them without
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    66
   creating an instance of a class.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    67
 * Static methods are implicitly final, because overriding is done based on
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    68
   the type of the object, and static methods are attached to a class, not an
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    69
   object.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    70
 * A static method in a superclass can be shadowed by another static method in
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    71
   a subclass, as long as the original method was not declared final.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    72
 * You can't override a static method with a nonstatic method.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    73
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    74
final.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    75
------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    76
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    77
 * A final class can't be extended ie., final class may not be subclassed.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    78
 * A final method can't be overridden when its class is inherited.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    79
 * You can't change value of a final variable.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    80
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    81
Exceptions.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    82
===========
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    83
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    84
A checked exception is some subclass of Exception (or Exception itself),
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    85
excluding class RuntimeException and its subclasses.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    86
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    87
Unchecked exceptions are RuntimeException and any of its subclasses. Class
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    88
Error and its subclasses also are unchecked. With an unchecked exception,
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    89
however, the compiler doesn't force client programmers either to catch the
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    90
exception or declare it in a throws clause.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    91
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    92
Inner classes.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    93
==============
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    94
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    95
Nested top-level classes.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    96
-------------------------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    97
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    98
If you declare a class within a class and specify the static modifier, the
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    99
compiler treats the class just like any other top-level class.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   100
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   101
Any class outside the declaring class accesses the nested class with the
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   102
declaring class name acting similarly to a package. eg, outer.inner. Top-level
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   103
inner classes implicitly have access only to static variables. There can also
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   104
be inner interfaces. All of these are of the nested top-level variety.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   105
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   106
Member classes.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   107
---------------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   108
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   109
Member inner classes are just like other member methods and member variables
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   110
and access to the member class is restricted, just like methods and variables.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   111
This means a public member class acts similarly to a nested top-level class.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   112
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   113
The primary difference between member classes and nested top-level classes is
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   114
that member classes have access to the specific instance of the enclosing
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   115
class.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   116
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   117
Local classes.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   118
--------------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   119
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   120
Local classes are like local variables, specific to a block of code. Their
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   121
visibility is only within the block of their declaration. In order for the
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   122
class to be useful beyond the declaration block, it would need to implement a
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   123
more publicly available interface.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   124
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   125
Because local classes are not members, the modifiers public, protected,
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   126
private, and static are not usable.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   127
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   128
Anonymous classes.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   129
------------------
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   130
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   131
Anonymous inner classes extend local inner classes one level further. As
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   132
anonymous classes have no name, you cannot provide a constructor.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   133
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   134
64-bit problem.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   135
===============
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   136
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   137
  http://www.java.com/en/download/faq/java_win64bit.xml
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   138
                Which version of Java should I download for my 64-bit Windows
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   139
                operating system?
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   140
  http://java.sun.com/javase/6/webnotes/install/system-configurations.html
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   141
                Java SE 6 Release Notes Supported System Configurations
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   142
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   143
Java performance.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   144
=================
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   145
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   146
  http://java.sun.com/performance/reference/whitepapers/5.0_performance.html
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   147
  http://java.sun.com/performance/reference/whitepapers/6_performance.html
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   148
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   149
Creating jar.
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   150
=============
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   151
::
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   152
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   153
  $ jar cf myFile.jar *.class
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   154
  $ jar cmf myManifestFile myFile.jar *.class
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   155
  $ jar -cfe Main.jar foo.Main foo/Main.class
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   156
1215
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   157
Profiling Java.
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   158
===============
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   159
::
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   160
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   161
  $ java -Xprof com.vendor.product.Clazz
1214
fe28cec0bb40 java -Xrunhprof:help
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1213
diff changeset
   162
  $ java -Xrunhprof:help
1213
06623bbdb097 Profiling java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   163
1215
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   164
Debugging Java.
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   165
===============
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   166
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   167
Compile with ``-g`` to preserve source code information::
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   168
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   169
  $ javac -g -cp $CLASSPATH -sourcepath $SRC_DIR -d $BUILD_DIR
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   170
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   171
To run Java program in debugger::
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   172
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   173
  $ jdb -cp $CLASSPATH -sourcepath $SRC_DIR
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   174
1238
53da16ba1897 -Xrunjdwp:transport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1216
diff changeset
   175
To attach to Java application you firstly must run application with (use
53da16ba1897 -Xrunjdwp:transport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1216
diff changeset
   176
``dt_shmem`` for Windows and ``dt_socket`` for Linux)::
1215
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   177
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   178
  $ java -Xdebug -Xrunjdwp:transport=dt_shmem,server=y,suspend=n,address=$PORT \
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   179
    com.vendor.product.Clazz
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   180
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   181
and then attach with debugger::
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   182
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   183
  $ jdb -attach $PORT
84101bddf00c Debugging Java.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1214
diff changeset
   184
1629
32f8c509119d Dump current thread traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1563
diff changeset
   185
Dump current thread traces and memory statistic to stdout::
32f8c509119d Dump current thread traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1563
diff changeset
   186
32f8c509119d Dump current thread traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1563
diff changeset
   187
  $ kill -QUIT $PID
32f8c509119d Dump current thread traces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1563
diff changeset
   188
1643
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   189
Debug class loading.
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   190
====================
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   191
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   192
To dump class loading and unloading to ``System.out`` add to ``java`` opts::
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   193
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   194
  $ java -XX:+TraceClassLoading -XX:+TraceClassUnloading ...
1644
54d482709640 -verbose:class
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1643
diff changeset
   195
  $ java -verbose:class ...
1643
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   196
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   197
To review loaded classes explore heap dump in ``visualvm`` (visit "Classes"
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   198
tab).
fed98aef5cae Debug class loading.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1629
diff changeset
   199
1687
da4a6ceb7e89 Decompile class file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1686
diff changeset
   200
Decompile class file.
da4a6ceb7e89 Decompile class file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1686
diff changeset
   201
=====================
da4a6ceb7e89 Decompile class file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1686
diff changeset
   202
::
da4a6ceb7e89 Decompile class file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1686
diff changeset
   203
da4a6ceb7e89 Decompile class file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1686
diff changeset
   204
  $ javap -v -p -c My.java
da4a6ceb7e89 Decompile class file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1686
diff changeset
   205
1269
69d8c32d7bf9 Find jar by class.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
   206
Find jar by class.
69d8c32d7bf9 Find jar by class.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
   207
==================
69d8c32d7bf9 Find jar by class.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
   208
1270
af6cbb1b5888 http://mvnrepository.com/search.html?query=PKG
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1269
diff changeset
   209
  http://mvnrepository.com/search.html?query=PKG
1269
69d8c32d7bf9 Find jar by class.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
   210
  http://www.jarfinder.com
69d8c32d7bf9 Find jar by class.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
   211
1686
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   212
Set default Java in Debian.
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   213
===========================
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   214
::
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   215
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   216
  $ update-java-alternatives -l
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   217
  $ sudo update-java-alternatives -s java-1.8.0-openjdk-i386
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   218
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   219
or individually for each executable::
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   220
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   221
  $ sudo update-alternatives --config java
4ea7c87dfb87 Set default Java in Debian.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1677
diff changeset
   222
1655
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   223
Import SSL certificate.
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   224
=======================
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   225
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   226
Get cert with::
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   227
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   228
  $ openssl s_client -connect promin-test.it.loc:433
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   229
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   230
  -----BEGIN CERTIFICATE-----
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   231
  ...
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   232
  -----END CERTIFICATE-----
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   233
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   234
or by opening URL in broswer and exporting in "Page info" ==> "Security" menu.
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   235
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   236
Call import utility with default ``changeit`` password::
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   237
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   238
  $ keytool -importcert -file $YOUR.crt -keystore $JAVA_HOME/jre/lib/security/cacert -alias $ANY -storepass changeit
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   239
  $ keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacert -storepass changeit
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   240
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   241
Import certificate system wide in Debian by (note, ``.crt`` extention is
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   242
mandatory)::
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   243
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   244
  $ sudo mkdir /usr/share/ca-certificates/$ANY/    # don't mess with other certs
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   245
  $ sudo cp /tmp/$YOUR.crt /usr/share/ca-certificates/$ANY/
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   246
  $ sudo dpkg-reconfigure --force ca-certificates  # check your cert in curses GUI!
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   247
  $ sudo update-ca-certificates --fresh --verbose
1cabdf6fe296 Import SSL certificate.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1644
diff changeset
   248
1379
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   249
Java EE versions.
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   250
=================
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   251
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   252
======= ======== ======== ========
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   253
Java EE Servlet  JSP      JSTL
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   254
======= ======== ======== ========
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   255
6       3.0      2.2      -
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   256
5       2.5      2.1      1.2
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   257
1.4     2.4      2.0      1.1
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   258
1.2     2.3      1.2      1.0
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   259
======= ======== ======== ========
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   260
1380
428a226bf835 Specify file name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1379
diff changeset
   261
To set servlet version check ``WEB-INF/web.xml``::
1379
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   262
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   263
  <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0">
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   264
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   265
See:
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   266
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   267
  http://jcp.org/aboutJava/communityprocess/final/jsr315/index.html
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   268
                Servlet 3.0 Specification
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   269
  http://jcp.org/aboutJava/communityprocess/mrel/jsr154/index.html
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   270
                Servlet 2.5 Specification
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   271
  http://www.mularien.com/blog/2008/04/24/how-to-reference-and-use-jstl-in-your-web-application/
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   272
                How to Reference and Use JSTL in your Web Application
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   273
  http://en.wikipedia.org/wiki/Java_EE_version_history
e1c949673102 Java EE versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
   274
                Java EE version history
1563
9b4441d30cac Java interactive shell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1380
diff changeset
   275
9b4441d30cac Java interactive shell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1380
diff changeset
   276
Java interactive shell.
9b4441d30cac Java interactive shell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1380
diff changeset
   277
=======================
9b4441d30cac Java interactive shell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1380
diff changeset
   278
9b4441d30cac Java interactive shell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1380
diff changeset
   279
Just use Groovy. ``bsh`` is older alternative without code completion.