The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20131127

I'm credited in a newly published IT book by Packt Publishing, "Instant JRebel"

I was asked by Packt Publishing a couple of months ago to be a reviewer for their (now) newly published IT book "Instant JRebel".

I got my pdf copy of the book today, so here are the screenshots of where I'm credited:






JRebel is a plugin that most Java developers can't do without, used to hotswap code changes into a running Java application.

20131126

test class demonstrating how java 7's JVM processes class initialization and instantiation

Just wrote a java class to demonstrate JVM 7's class initialization processing order

click the link above to go to the source code.

i created a java class with a "main" method, some static variables and some normal (non-static) instance variables, then ran this file with debug breakpoints on all lines of code to find the processing order and here's what i found:

* access modifiers for variables and methods (private, public, protected, etc) don't seem to affect processing order, ALTHOUGH the "main" method must have the "public" modifier

* standard getter and setter methods for variables don't get processed, i.e. debugger never stops on their breakpoints

* "static final" variables don't get processed by the JVM during initialization or instantiation of the class, i.e. debugger never stops on their breakpoints


processing order:
1. static variables and static initialization blocks, in textual order of appearance
2. "main" method:
    2.1 begin executing any logic encountered
        2.1.1 if a call to instantiate the containing class is made (i.e. "new JVMClassInitializationProcessingOrderTest()"), temporarily pause execution of "main" method logic
            2.1.1.1 initialize (non-static) instance variables and (non-static) initialization blocks, in textual order of appearance
            2.1.1.2 process the class' constructor
            2.1.1.3 resume execution of the remaining logic in the "main" method

20131125

what is the java reserved word "class" called/known as?

i've been recently reviewing some basic java principles lately and today i got to thinking about the word "class" and wondering exactly what that word is actually known as, e.g.:

public class MyClass {
  ...
}


i found in the java tutorial an article called Java Language Keywords:
"
Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.
"

Answer: keyword (identifier)

[SOLVED] "Eclipse: The resource is not on the build path of a java project" - how to use a class in another package

i'm using some time to go back and review some basic concepts in java, so today i read about Controlling Access to Members of a Class.

i set up the following java code package structure in eclipse:
src/
--test/accesscontrol/
----PackagePrivateA.java
----PackagePublicA.java
--test2/
----AccessControlTest.java

Eclipse's "Java EE" perspective:



Eclipse's "Java" perspective:




####PackagePrivate.java####

package test.accesscontrol;

class PackagePrivate {
    PackagePrivate() {
        System.out.println("PackagePrivate() constructor");
    }
}


####PackagePublic.java####

package test.accesscontrol;

public class PackagePublic {
    public PackagePublic() {
        System.out.println("PackagePublic() constructor");
    }
}


####AccessControlTest.java####

package test2;

import test.accesscontrol.PackagePublic;

public class AccessControlTest {
    public AccessControlTest() {
        PackagePrivate pPriv = new PackagePrivate();
        PackagePublic pPub = new PackagePublic();
        System.out.println("AccessControlTest() constructor");
    }
}


####

---
NOTE: the red line in the class AccessControlTest:
PackagePrivate pPriv = new PackagePrivate();

will not work (and is not expected to work) because class PackagePrivate is declared with a package-private access modifier, i.e. no "public" in front of the "class" keyword identifier, so the class AccessControlTest shouldn't have access to the class PackagePrivate because of java's access control rules.
---

however, when i first tried importing/referencing the class PackagePublic in the class AccessControlTest, i got the following error in eclipse:
The resource is not on the build path of a java project

theoretically, it should work fine because the class PackagePublic is declared as a public class, "in which case that class is visible to all classes everywhere" (provided it's visible in the classpath).

i found out that the reason eclipse wasn't finding the class PackagePublic was because the src folder wasn't set as a source folder.

so to fix this:
* change to eclipse's "Java" perspective
* right click on the src folder > Build Path > Use as source folder


20131119

[SOLVED] primefaces p:dialog not rendering ui:include page component content

i have a p:dialog that looks like this:

<p:dialog ...>  
    <p:panel>
        <ui:include src="/webcomponents/presentation/user/testUserMenu.xhtml" />
    </p:panel>
</p:dialog>

(NOTE: "..." just means "etc/some code")

testUserMenu.xhtml looks like this:

...
<p:panelGrid id="testUserMenu">
...
    <p:commandButton value="#{msg['label.close']}" ... />

...
</p:panelGrid>
...


but the "close" button, nor anything else in the p:dialog, was getting rendered in the browser.
finally, i figured out (thanks to my colleague dan) that p:panelGrid simply needed a defined "columns" attribute, like this:

<p:panelGrid id="testUserMenu" columns="1">

20131113

[WORKAROUND] eclipse kepler - primefaces 4 xhtml/jsf autocomplete no description for attributes

i have my primefaces jar included in my project build path, and when i do ctrl+space in an xhtml/jsf file, inside a primefaces tag, i get the list of available attributes, but there's no description for them:


i found a workaround by accident: when the autocomplete window is open, as shown in the screenshot above, do ctrl+space again, several times, until you rotate back to the attributes list, and THEN the description will show:


[SOLVED] where is the jboss 7 (EAP 6) management console?

it listens on port 9990, e.g.:
localhost:9990

and the login credentials (username, password) are here:
jboss-eap-6.1/standalone/configuration/mgmt-users.properties

and the configuration line looks like this:
myadmin=8290c07a9251c5d7c3d691ee4e08f243

the hash value to the right of the equals sign is the encrypted password

20131110

ubuntu - low disk space the volume boot has only X MB disk space remaining

i started getting warning popups telling me i only had 10 MB left in my /boot partition:
low disk space the volume boot has only 10 MB disk space remaining

so i first checked to see what was in my /boot folder:
ls -la /boot


which gave this output:

-rw-r--r--  1 root root   918917 mai    1  2013 abi-3.8.0-19-generic
-rw-r--r--  1 root root   918917 mai   15 00:42 abi-3.8.0-21-generic
-rw-r--r--  1 root root   919039 mai   16 17:42 abi-3.8.0-22-generic
-rw-r--r--  1 root root   919604 aug.  13 22:10 abi-3.8.0-29-generic
-rw-r--r--  1 root root   919661 aug.  22 23:21 abi-3.8.0-30-generic
-rw-r--r--  1 root root   919745 sep.  10 22:29 abi-3.8.0-31-generic
-rw-r--r--  1 root root   919745 okt.   2 01:00 abi-3.8.0-32-generic
-rw-r--r--  1 root root   919810 okt.  23 11:42 abi-3.8.0-33-generic
-rw-r--r--  1 root root   154942 mai    1  2013 config-3.8.0-19-generic
-rw-r--r--  1 root root   154942 mai   15 00:42 config-3.8.0-21-generic
-rw-r--r--  1 root root   154943 mai   16 17:42 config-3.8.0-22-generic
-rw-r--r--  1 root root   154960 aug.  13 22:10 config-3.8.0-29-generic
-rw-r--r--  1 root root   154960 aug.  22 23:21 config-3.8.0-30-generic
-rw-r--r--  1 root root   154960 sep.  10 22:29 config-3.8.0-31-generic
-rw-r--r--  1 root root   154961 okt.   2 01:00 config-3.8.0-32-generic
-rw-r--r--  1 root root   154961 okt.  23 11:42 config-3.8.0-33-generic
drwxr-xr-x  5 root root     1024 nov.   9 10:24 grub
-rw-r--r--  1 root root 16797726 mai   22 14:06 initrd.img-3.8.0-19-generic
-rw-r--r--  1 root root 16797707 mai   22 14:57 initrd.img-3.8.0-21-generic
-rw-r--r--  1 root root 16798859 mai   24 10:12 initrd.img-3.8.0-22-generic
-rw-r--r--  1 root root 16863423 aug.  22 10:09 initrd.img-3.8.0-29-generic
-rw-r--r--  1 root root 16863744 sep.   7 16:52 initrd.img-3.8.0-30-generic
-rw-r--r--  1 root root 16865732 okt.  10 08:46 initrd.img-3.8.0-31-generic
-rw-r--r--  1 root root 16868285 okt.  31 11:58 initrd.img-3.8.0-32-generic
-rw-r--r--  1 root root 16868895 nov.   9 10:24 initrd.img-3.8.0-33-generic
drwxr-xr-x  2 root root    12288 mai   22 13:48 lost+found
-rw-r--r--  1 root root   176764 des.   5  2012 memtest86+.bin
-rw-r--r--  1 root root   178944 des.   5  2012 memtest86+_multiboot.bin
-rw-------  1 root root  3060094 mai    1  2013 System.map-3.8.0-19-generic
-rw-------  1 root root  3060094 mai   15 00:42 System.map-3.8.0-21-generic
-rw-------  1 root root  3060454 mai   16 17:42 System.map-3.8.0-22-generic
-rw-------  1 root root  3062491 aug.  13 22:10 System.map-3.8.0-29-generic
-rw-------  1 root root  3062704 aug.  22 23:21 System.map-3.8.0-30-generic
-rw-------  1 root root  3062541 sep.  10 22:29 System.map-3.8.0-31-generic
-rw-------  1 root root  3062477 okt.   2 01:00 System.map-3.8.0-32-generic
-rw-------  1 root root  3062707 okt.  23 11:42 System.map-3.8.0-33-generic
-rw-------  1 root root  5356528 mai    1  2013 vmlinuz-3.8.0-19-generic
-rw-------  1 root root  5356592 mai   15 00:42 vmlinuz-3.8.0-21-generic
-rw-------  1 root root  5356688 mai   16 17:42 vmlinuz-3.8.0-22-generic
-rw-------  1 root root  5360272 aug.  13 22:10 vmlinuz-3.8.0-29-generic
-rw-------  1 root root  5361936 aug.  22 23:21 vmlinuz-3.8.0-30-generic
-rw-------  1 root root  5362320 sep.  10 22:29 vmlinuz-3.8.0-31-generic
-rw-------  1 root root  5363184 okt.   2 01:00 vmlinuz-3.8.0-32-generic
-rw-------  1 root root  5364816 okt.  23 11:42 vmlinuz-3.8.0-33-generic


so i could see that the only kernel i wanted to retain was 3.8.0-33-generic, so i removed all the old kernels like this:
sudo apt-get purge linux-image-3.8.0-{19,21,22,29,30,31,32}-generic

which gave this output:
The following packages will be REMOVED:
  linux-image-3.8.0-19-generic* linux-image-3.8.0-21-generic* linux-image-3.8.0-22-generic* linux-image-3.8.0-29-generic* linux-image-3.8.0-30-generic* linux-image-3.8.0-31-generic*
  linux-image-3.8.0-32-generic* linux-image-extra-3.8.0-19-generic* linux-image-extra-3.8.0-21-generic* linux-image-extra-3.8.0-22-generic* linux-image-extra-3.8.0-29-generic*
  linux-image-extra-3.8.0-30-generic* linux-image-extra-3.8.0-31-generic* linux-image-extra-3.8.0-32-generic*



20131108

useful, advanced bash functionality

http://www.thegeekstuff.com/2008/08/15-examples-to-master-linux-command-line-history/#more-130

here are some examples of some useful bash functionality that i haven't used before:

// search history for most recent execution of ps command

(keyboard combination:) ctrl+r
(type:) ps

now you have two options:
* to execute the command, just hit enter
* to edit the command, just hit the right arrow key


// shorter way to search for running java processes

pgrep -lf java

(which is identical to: ps aux|grep java )


// kill the gedit process

pkill gedit



// get the last argument from the previous command to the current command

ls|grep somefile.txt
nano -w !!:$


which executes:
nano -w somefile.txt


// get the first argument from the previous command to the current command

cp file1.txt file2.txt
nano -w !^

which executes:
nano -w file1.txt



20131107

[SOLVED] JSF SessionScoped: com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class

when trying to view a jsf page, i got the following error in the browser:
http 500 error:
com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: com.test.userUsersDataBean



and this was in the console:
11:23:07,407 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/].[facesServlet]] (http-localhost/127.0.0.1:8080-3) JBWEB000236: Servlet.service() for servlet facesServlet threw exception: java.lang.NullPointerException
    at com.test.userUsersDataBean.setUserAndMemberOnBackingBean(UsersDataBean.java:97) [:]
    at com.test.userUsersDataBean.<init>(UsersDataBean.java:109) [:]
...



here's the code for UsersDataBean.java, line 97:
user = userMenuBean.getUser();

userMenuBean was apparently null. eventually i found out that the problem was this, in UserMenuBean.java:
@javax.enterprise.context.SessionScoped


when i changed it to this, it worked:
@javax.faces.bean.SessionScoped;


UPDATE

i just got a similar Cant instantiate class error when i migrated some validator classes from faces-config.xml to using annotations. the solution was just to rebuild/recompile the project, then "Clean" the server (servers > right click on my jboss server instance > clean), then restart the server.

20131106

[SOLVED] java ee xhtml, how to hide jsf tags in source code

today's task at work was to find out how to hide xhtml tag code in jsf pages, i.e. when a user attempts "view > source code", we don't want them to see the non-rendered jsf tags. i searched a lot, using the following search phrases:
jsf hide source code
primefaces hide source code
jsf don't show source code
jee hide jsf source code
jee web.xml hide jsf source
hide xhtml source
jsf disable viewing xhtml source

but surprisingly found no concrete answer as to how to solve this, but after much trial and error, i've finally figured it out.

put this code in your web.xml:

<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
    <url-pattern>*.xhtml</url-pattern>

    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>