Thursday, May 22, 2014

Learning IE - F12 key opens Developer Tools

I have been working with Internet Explorer (version 8) because my company still mandates that Developers test in IE8 since our customers mainly use IE8.

Well, sometimes we developers run into issues and I struggle to figure out what the issue is when the app works fine in FireFox or Chrome. Today, I accidentally stumble on this cool trick.

Open Internet Explorer.


Press key F12 and viola! the IE Developer Tools window opens.

Not sure how useful this is, but now we know it exists! (Instead of wondering why IE doesn't have one like FireFox and Chrome, lol.)

Saturday, April 26, 2014

Learning NetBeans - Creating Database

I ran into an issue today where my professor's tutorial didn't work out as planned. My GlassFish Server 4 console stated "sample database not found" or something like that. I'll have to make sure to take the screenshot next time.

Anyhow, to resolve this issue, I went into the directory instructed by my professor and renamed my folder "sample" to "sample_original". There was nothing in this folder but a subfolder called "log" with log files. Oh, here is where the directory was:

C:/Users/gradney/.netbeans-derby

This is the default location (where my %HOME% is C:/Users/gradney) that NetBeans will create its Derby (database) directory. This is NetBeans' Java database, I believe.

Once I renamed this folder to "sample_original" (instead of deleting it because I might need this folder later), I went back into NetBeans and created the database from within the IDE. Here's the YouTube I followed (from the first few minutes) and it worked.


Quick Instruction
Open NetBeans IDE > Go to Services tab/view > Expand Databases > Right-click Java DB > click Create Database > enter Database Name (like 'sample') > enter Username (like 'app') > enter Password (like 'app') > click OK.


Friday, April 25, 2014

Learning NetBeans - IDE Knowledge Nuggets

Why re-invent instead of leverage (what already exist wonderfully)?
Here I am leveraging other people's blogs, answers, etc. on learning NetBeans IDE.
*QI - Quick Instruction.

NetBeans - Top 10 IDE PC Keyboard Shortcuts

My Favorites
I don't have any of my own yet, but will update as I do make my own list.

Refer [2]

http://netbeanside61.blogspot.com/2008/04/top-10-netbeans-ide-keyboard-shortcuts.html

NetBeans - Adding Maven Dependencies (similar to updating & removing)

QI: Add Dependency
Open NetBeans > Open Project > Right-click on folder Dependencies > Add Dependency > Query by library name (e.g. servlet-api) > select from Search Results > click Add.
QI: Remove Dependency
Open NetBeans > Open Project > Expand folder Dependencies > Right-click on library> select Remove Dependency.
*Since I could figure out how to add, then I knew how to update and remove (library) dependencies as well.

Refer [2]

http://mrhaki.blogspot.com/2009/07/add-maven-dependency-in-netbeans.html


Thursday, April 24, 2014

Learning Java - What's BMP, CMP, and JPA?

Today, I am learning the difference among Java's ways to interact with a database or storage device.

JPA: Java Persistence Architecture API

The JPA is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database. JPA was defined as part of the EJB 3.0 specification as a replacement for the EJB 2 CMP Entity Beans specification. JPA is now considered the standard industry approach for Object to Relational Mapping (ORM) in the Java industry.
JPA allows POJO (Plain Old Java Objects) to be easily persisted without requiring the classes to implement any interfaces or methods as the EJB 2 CMP specification required. JPA allows an object's object-relational mappings to be defined through standard annotations or XML defining how the Java class maps to a relational database table. JPA also defines a runtime EntityManager API for processing queries and transaction on the objects against the database. JPA defines an object-level query language, JPQL, to allow querying of the objects from the database.

Why JPA replaced BMP/CMP?

Entity Beans calls for to much complicated code and heavy resource footprint, and they could be used only in Java EE application servers because of interconnections and dependencies in the source code between beans and DAO objects (or persistent framework).

Reference(s): 

http://en.wikibooks.org/wiki/Java_Persistence/What_is_JPA%3F
http://en.wikipedia.org/wiki/Java_Persistence_API
http://www.oracle.com/technetwork/java/javaee/tech/persistence-jsp-140049.html

CMP: Container-Managed Persistence

A CMP bean is an entity bean whose state is synchronized with the database automatically.
In other words, the bean developer doesn't need to write any explicit database calls into the bean code; the container will automatically synchronize the persistent fields with the database as dictated by the deployer at deployment time.
When a CMP bean is deployed, the deployer uses the EJB tools provided by the vendor to map the persistent fields in the bean to the database. The persistence fields will be a subset of the instance fields, called container-managed fields, as identified by the bean developer in the deployment descriptor.

Reference(s): 

http://www.jguru.com/faq/view.jsp?EID=1087

BMP: Bean-Managed Persistence

A BMP bean is an entity that synchronizes its state with the database manually.
In other words, the bean developer must code explicit database calls into the bean itself. BMP provides the bean developer with more flexibility in how the bean reads and writes its data than a container-managed persistence (CMP) bean. CMP bean is limited to the mapping facilities provided by the EJB vendor, BMP beans are only limited by skill of the bean developer.
The ability to code an entity bean's persistence logic explicitly is important when the EJB container's CMP features are insufficient to meet the needs of the entity bean. Entity beans that need to synchronize their state with several data sources are excellent candidates for BMP. So are beans that need to access data sources (possibly legacy systems) that are not supported by CMP. In addition, BMP bean are often employed when a vendor's CMP facilities are not sophisticated enough to handle complex Object-to-Relational mapping.

Reference(s): 

http://www.jguru.com/faq/view.jsp?EID=1090

Remember

  • JPA replaces CMP & BMP as Java industry standard's Object-to-Relational Mapping (ORM).
  • CMP bean is limited to the mapping facilities provided by the EJB vendor; BMP beans are only limited by skill of the bean developer.

Additional References:




Learning NetBeans - Setting Default Browser

I thought I had set my default browser to use the Embedded Webkit Browser included with NetBeans. But, my default browser still opens my HelloWorld webpage in Google Chrome (my OS's default web browser that I had set).

Here's what I did:
  1. Open NetBeans IDE > Add HelloApp web project > click Run icon (or in menu bar, select Run > Run Project).

What happens is the index.html (default webpage for web project) displays in my operating system's default browser which is Chrome.


However, I would like my project to display the webpages in NetBeans' embedded webkit browser.

Solution: To fix this, here's what I did:
  1. In menu bar, select Run > select Set Project Browser > Embedded Webkit Browser.
  2. Click Run icon (or in menu bar, select Run > Run Project).


Now my project displays in the NetBeans' embedded webkit browser.


To update the default browser for the project, simply follow the process again (mentioned in the "Solution" section) and select one of the browser options.

Wednesday, April 23, 2014

Learning Java - What is "new String[0]"?

I came across some code as:

row.add( row.toArray( new String[0] ) );

But, what does "new String[0]" mean?

I found some good answers at the following (StackOverflow site):

According to my code, since my "row" object is not a granddaddy Java type Object but a String type, I want to add a row of String type to the existing row(s). By telling the method .toArray() to return reference type of String and not Object, my row will add a new array of Strings. By passing '0' into the String array, we are declaring to return the type only.

Here's a combined answer taken from folk at StackOverflow:
It is the array into which the elements of the Set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
So that, in this example, you get back a String[]. The one without any argument gives back to you an Object[].
See you have 2 versions of this method:
By passing String[] array, you are using the generic version.
Object[] toArray(), returns an Object[] which cannot be cast to String[] or any other type array.
T[] toArray(T[] a) , returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set.



Troubleshoot - (Eclipse) Debug Error: "Model Proxy installed notification job"

Hello, hello!
Did you run into this "Model Proxy installed notification job" Error, too?

So, I ran into this bizarre error in Eclipse IDE (Juno version) while debugging some code. The error title is "Multiple problems have occurred" and the message is:
'An internal error occurred during: "Model Proxy installed notification job". '




I thought if I clicked on "OK" and perhaps restarted Eclipse IDE, then this error would resolve itself due to some Eclipse caching or what not. Anyhow, this thought failed. So, before I started trying all kinds of crazy stuff, I googled and found this answer @ http://stackoverflow.com/questions/14611383/eclipse-debugger-error-model-proxy-installed-notification-job

However, those instructions still didn't work for me (from stackoverflow). I went back into Eclipse, opened the Debug perspective. Error displayed again. Click OK on error dialog.

Then, I noticed something strange in my Breakpoints view. Although all of my breakpoints "looked" like they were removed, my 'Remove All Breakpoints' icon was still enabled. Strange, because shouldn't this icon be disabled if all of my breakpoints are removed?

*click on picture to enlarge view*

So, let's try something. In the Breakpoints view, I clicked on the icon to Remove All Breakpoints (and 'yes' that I am sure). And now I see the Breakpoints view I am expecting along with the 'Remove All Breakpoints' icon disabled.

*click on picture to enlarge view*

To test and make sure my error was resolved, I switched to Java perspective and back to Debug. No error displayed. I removed the Breakpoints view and re-added the Breakpoints view. No error displayed. I left my Eclipse at the Debug perspective and restarted Eclipse. Still no error. AWESOME!!! Issue resolved and have a nice day! Hahahaaa....

P.S. I also removed all the .bak logs in ./workspace/.metadata directory. I don't think this was related to the Debug error, but making note just in case.