# HG changeset patch # User Oleksandr Gavenko # Date 1329570561 -7200 # Node ID 1b6871f6914acdc2b87aca747484b79ca9b21f35 # Parent 70c6a3153bc76d3ce62e2be1e43b6b32d19848c3# Parent 3354c6e9cb95d08d51d880d47be9823890e8fc02 merged diff -r 3354c6e9cb95 -r 1b6871f6914a java.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java.rst Sat Feb 18 15:09:21 2012 +0200 @@ -0,0 +1,180 @@ +.. -*- coding: utf-8; -*- + +================ + Java language. +================ + +Class version. +============== + + ========= ====== ===================== + major minor Java platform version + ========= ====== ===================== + 45 0x27 3 1.0 + 45 0x27 3 1.1 + 46 0x28 0 1.2 + 47 0x29 0 1.3 + 48 0x30 0 1.4 + 49 0x31 0 1.5 + 50 0x32 0 1.6 + ========= ====== ===================== + +where ``minor`` and ``major`` are value of 6 and 8 bytes in .class file:: + + 0xCA, 0xFE, 0xBA, 0xBE, 0x00, minor, 0x00, major + +Access modifiers. +================= + +Public. +------- + + * Public class is visible in other packages. + * Public field is visible everywhere (class must be public too). + +Private. +-------- + + * Private variables or methods may be used only by an instance of the same + class that declares the variable or method + * A private feature may only be accessed by the class that owns the feature. + +Protected. +---------- + + * Is available to all classes in the same package and also available to all + subclasses of the class that owns the protected feature. + * This access is provided even to subclasses that reside in a different + package from the class that owns the protected feature. + +default. +-------- + +What you get by default ie, without any access modifier. + + * It means that it is visible to all within a particular package. + +static. +------- + + * Static means one per class, not one for each object no matter how many + instance of a class might exist. This means that you can use them without + creating an instance of a class. + * Static methods are implicitly final, because overriding is done based on + the type of the object, and static methods are attached to a class, not an + object. + * A static method in a superclass can be shadowed by another static method in + a subclass, as long as the original method was not declared final. + * You can't override a static method with a nonstatic method. + +final. +------ + + * A final class can't be extended ie., final class may not be subclassed. + * A final method can't be overridden when its class is inherited. + * You can't change value of a final variable. + +Exceptions. +=========== + +A checked exception is some subclass of Exception (or Exception itself), +excluding class RuntimeException and its subclasses. + +Unchecked exceptions are RuntimeException and any of its subclasses. Class +Error and its subclasses also are unchecked. With an unchecked exception, +however, the compiler doesn't force client programmers either to catch the +exception or declare it in a throws clause. + +Inner classes. +============== + +Nested top-level classes. +------------------------- + +If you declare a class within a class and specify the static modifier, the +compiler treats the class just like any other top-level class. + +Any class outside the declaring class accesses the nested class with the +declaring class name acting similarly to a package. eg, outer.inner. Top-level +inner classes implicitly have access only to static variables. There can also +be inner interfaces. All of these are of the nested top-level variety. + +Member classes. +--------------- + +Member inner classes are just like other member methods and member variables +and access to the member class is restricted, just like methods and variables. +This means a public member class acts similarly to a nested top-level class. + +The primary difference between member classes and nested top-level classes is +that member classes have access to the specific instance of the enclosing +class. + +Local classes. +-------------- + +Local classes are like local variables, specific to a block of code. Their +visibility is only within the block of their declaration. In order for the +class to be useful beyond the declaration block, it would need to implement a +more publicly available interface. + +Because local classes are not members, the modifiers public, protected, +private, and static are not usable. + +Anonymous classes. +------------------ + +Anonymous inner classes extend local inner classes one level further. As +anonymous classes have no name, you cannot provide a constructor. + +64-bit problem. +=============== + + http://www.java.com/en/download/faq/java_win64bit.xml + Which version of Java should I download for my 64-bit Windows + operating system? + http://java.sun.com/javase/6/webnotes/install/system-configurations.html + Java SE 6 Release Notes Supported System Configurations + +Java performance. +================= + + http://java.sun.com/performance/reference/whitepapers/5.0_performance.html + http://java.sun.com/performance/reference/whitepapers/6_performance.html + +Creating jar. +============= +:: + + $ jar cf myFile.jar *.class + $ jar cmf myManifestFile myFile.jar *.class + $ jar -cfe Main.jar foo.Main foo/Main.class + +Profiling Java. +=============== +:: + + $ java -Xprof com.vendor.product.Clazz + $ java -Xrunhprof:help + +Debugging Java. +=============== + +Compile with ``-g`` to preserve source code information:: + + $ javac -g -cp $CLASSPATH -sourcepath $SRC_DIR -d $BUILD_DIR + +To run Java program in debugger:: + + $ jdb -cp $CLASSPATH -sourcepath $SRC_DIR + +To attach to Java application you firstly must run application with (use +``dt_shmem`` for Windows and ``dt_socket`` for Linux):: + + $ java -Xdebug -Xrunjdwp:transport=dt_shmem,server=y,suspend=n,address=$PORT \ + com.vendor.product.Clazz + +and then attach with debugger:: + + $ jdb -attach $PORT + diff -r 3354c6e9cb95 -r 1b6871f6914a port.rst --- a/port.rst Fri Feb 10 00:03:17 2012 +0200 +++ b/port.rst Sat Feb 18 15:09:21 2012 +0200 @@ -1,6 +1,12 @@ --*- mode: outline; coding: utf-8; -*- +.. -*- coding: utf-8; -*- -* Port forwarding. +=============== + Network port. +=============== + +Port forwarding. +================ +:: $ ssh -L 8888:www.linuxhorizon.ro:80 user@computer -N $ ssh -L 8888:www.linuxhorizon.ro:80 -L 110:mail.linuxhorizon.ro:110 \ @@ -10,54 +16,99 @@ and smtp. It is useful to recive/send your e-mails when you don't have direct access to the mail server. -For the ASCII art and lynx browser fans here is illustrated the first example: +For the ASCII art and lynx browser fans here is illustrated the first example:: +----------+<--port 22-->+----------+<--port 80-->o-----------+ |SSH Client|-------------|ssh_server|-------------| host | +----------+ +----------+ o-----------+ localhost:8888 computer www.linuxhorizon.ro:80 -* Port listening. +Reverse SSH Tunneling. +====================== + +Have you ever wanted to ssh to your Linux box that sits behind NAT? Now you can +with reverse SSH tunneling. This document will show you step by step how to set +up reverse SSH tunneling. The reverse SSH tunneling should work fine with Unix +like systems. + +Let's assume that Destination's IP is 192.168.20.55 (Linux box that you want to +access). + +You want to access from Linux client with IP 138.47.99.99. +Destination (192.168.20.55) <- NAT <- Source (138.47.99.99) + +SH from the destination to the source (with public ip) using command below:: + + $ ssh -R 19999:localhost:22 sourceuser@138.47.99.99 + +port 19999 can be any unused port. Now you can SSH from source to destination +through SSH tuneling:: -Connect to a server: + $ ssh localhost -p 19999 + +3rd party servers can also access 192.168.20.55 through Destination +(138.47.99.99). Destination:: + + (192.168.20.55) <- |NAT| <- Source (138.47.99.99) <- Bob's server + +From Bob's server:: + + $ ssh sourceuser@138.47.99.99 + +After the sucessful login to Source:: + + $ ssh localhost -p 19999 + +The connection between destination and source must be alive at all time. Tip: +you may run a command (e.g. watch, top) on Destination to keep the connection +active. + +Port listening. +=============== + +Connect to a server:: $ nc hostname port -Be a server: +Be a server:: $ nc -l -p port -* Simple filetransfer. +Simple filetransfer. +==================== -Serve a file: +Serve a file:: $ nc -l -p port < file -Receive a file: +Receive a file:: $ nc hostname port > file -* Filesystem cloning. +Filesystem cloning. +=================== -Serve the filesystem: +Serve the filesystem:: $ tar cOPp --same-owner / | nc -l -p port -Receive the filesystem: +Receive the filesystem:: $ nc -w3 hostname port | tar xPp -* Disk cloning. +Disk cloning. +============= -Serve the disk image: +Serve the disk image:: $ dd if=/dev/hda | nc -l -p port -Receive the image: +Receive the image:: $ nc -w3 hostname port | dd of=/dev/hda -* Encrypted, compressed and IP restricted filetransfer. +Encrypted, compressed and IP restricted filetransfer. +===================================================== If combining encryption and compression, be sure to compress first then encrypt when sending and reverse the order for receiving. Do not attempt to @@ -66,19 +117,22 @@ required, specifying the IP address of the host that will be transferring the file is a good idea. -Serving a compresssed, encrypted file from 192.168.0.1 to 192.168.0.2: +Serving a compresssed, encrypted file from 192.168.0.1 to 192.168.0.2:: $ gzip -c < file | openssl aes-128-cbc -e -k thispassword | nc -l 192.168.0.2 12345 -Receiving, decrypting and decompressing that file: +Receiving, decrypting and decompressing that file:: $ nc 192.168.0.1 12345 | openssl aes-128-cbc -d -k thispassword | gunzip -c > file -* Scan with nmap. +Scan with nmap. +=============== TODO -* Scan with netcat. +Scan with netcat. +================= +:: $ nc -v -w 2 -z hostname portrange $ nc -v -w 2 -z hostname portlisting @@ -87,6 +141,7 @@ portlisting is for example 11,20,135 will scan these ports. I just tried this on windows xp, and the comma separated list of ports does -NOT work. Instead, use space separated list. eg: +NOT work. Instead, use space separated list. eg:: cmd> nc.exe -vv -w 2 -z www.example.com 20-25 79 80 110 137-139 443 + diff -r 3354c6e9cb95 -r 1b6871f6914a prettyprint.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prettyprint.rst Sat Feb 18 15:09:21 2012 +0200 @@ -0,0 +1,80 @@ +.. -*- coding: utf-8 -*- + +=========================== + Pretty print source code. +=========================== +.. contents:: + +Code formatter, beautifier, pretty printer. + +xml. +==== + +tidy. +----- +:: + + $ tidy -xml -i -utf8 -o out.xml in.xml + +or in Emacs:: + + C-x h C-x c utf-8 C-u M-| tidy -q -xml -i -utf8 - + + http://tidy.sourceforge.net + Home page. + http://www.emacswiki.org/cgi-bin/wiki/tidy.el + Emacs bindings. + +xmllint. +-------- +:: + + $ xmllint --format file.xml + +or in Emacs: + + : C-x h C-u M-| xmllint --format - + +Emacs and nxml. +--------------- + +You need introduce line-breaks and then:: + + C-x h C-M-\ + +xmlindent. +---------- + + http://xmlindent.sourceforge.net/ + +c/c++/java/c#. +-------------- + +Artistic Style, astyle. +----------------------- + +A Free, Fast and Small Automatic Formatter for C, C++, C#, and Java Source Code. + +There are exist package for Cygwin, Debian. + + http://astyle.sourceforge.net/ + home page + +Uncrustify. +----------- + +Source Code Beautifier for C, C++, C#, ObjectiveC, D, Java, Pawn and VALA. + +Exist package for Windows (binary from home page), Debian. + + http://uncrustify.sourceforge.net/ + home page + +jpplib. +------- + +Pretty Printer Library. + + http://jpplib.sourceforge.net/ + Home page. + diff -r 3354c6e9cb95 -r 1b6871f6914a remote-shell.rst --- a/remote-shell.rst Fri Feb 10 00:03:17 2012 +0200 +++ b/remote-shell.rst Sat Feb 18 15:09:21 2012 +0200 @@ -1,39 +1,5 @@ -*- mode: outline; coding: utf-8 -*- -* Reverse SSH Tunneling - -Have you ever wanted to ssh to your Linux box that sits behind NAT? Now you can with -reverse SSH tunneling. This document will show you step by step how to set up reverse SSH -tunneling. The reverse SSH tunneling should work fine with Unix like systems. - -Let's assume that Destination's IP is 192.168.20.55 (Linux box that you want to access). - -You want to access from Linux client with IP 138.47.99.99. -Destination (192.168.20.55) <- |NAT| <- Source (138.47.99.99) - -SH from the destination to the source (with public ip) using command below: - - $ ssh -R 19999:localhost:22 sourceuser@138.47.99.99 - -port 19999 can be any unused port. -Now you can SSH from source to destination through SSH tuneling: - - $ ssh localhost -p 19999 - -3rd party servers can also access 192.168.20.55 through Destination (138.47.99.99). -Destination (192.168.20.55) <- |NAT| <- Source (138.47.99.99) <- Bob's server - -From Bob's server: - - $ ssh sourceuser@138.47.99.99 - -After the sucessful login to Source: - - $ ssh localhost -p 19999 - -The connection between destination and source must be alive at all time. Tip: you may run -a command (e.g. watch, top) on Destination to keep the connection active. - * Ajaxterm. Allow remote shell access to host from web browser (require html+css+javascript).