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.

Saturday, April 19, 2014

Learning - Servlets with Cookies (in NetBeans IDE)



Hey Expert! (if you're not already, you will be!)

I'm not sure if anyone else has seen this issue, but I was going through one of the Hands-On tutorials (using PC) and pressed Alt+Enter to search for classes to import (since Ctrl+Shift+I was not triggering the Import). The dialog opened a set of libraries to choose from. Does it matter which javax.servlet.* to use (version?, etc.)? I'll go back through and double check my dependencies, but just thought I would ask


When I manually add the imported Class, remove the import, and declare the Cookie object, then I see the option to auto-import http.Cookie class. Any ideas on this behavior with NetBeans IDE?

<<I still need to research this behavior in NetBeans IDE.>>

However, I did get an answer from my professor regarding how the library we use in our Servlet does matter. Here's what he says:

Yes, it does matter.  You want to make sure that we pick up Servlet 3.1. If you select javax: javaee-web-api 7.0, you will get *all* Java EE 7 (Web Profile) APIs, and not just servlet 3.1. As an FYI, this jar file does not contain implementation of the Java EE 7 APIs, it contains enough of the API to compile against. The implementation of the APIs is the application server itself, and in this course that means GlassFish 4.0.

So, I use (import) the library:  javax.servlet-api (3.1.0) JAR.

Thursday, April 17, 2014

Good2Know - Heartbleed Bug



Hello my friends,

I thought you might be interested in this article as well as a response in the StackOverflow community regarding my perspective on this Heartbleed Bug. 

The best (or important) part to know in the article is titled “Can heartbeat extension be disabled during the TLS handshake?” This includes the ultimate answer that IT needs to upgrade systems to a fixed OpenSSL version. Or, buy a trusted SSL certificate.

And, this is why I’m not worried about this bug – because I'm not using SSL anyways and, if I did, I would buy an SSL certificate from a trusted security company, and not use OpenSSL.

Otherwise, we all Engineers would have panicked. ;-)

Super thanks to the authors of the article (specifically CODENOMICON) and the StackOverflow responses!


Cheers,

Thursday, April 3, 2014

Learning - Deleting Repository in GitHub

Hello, I hope you are doing well today.

We will learn how to remove a repository in GitHub.

WARNING: If you remove (delete) this repository from GitHub, no one will be able to fork from it, add updates to it, etc.

First, I'm already signed into GitHub and I already have a repository that I wish to remove called "Java".


Okay, let's click on "Java" repository link. As you can see, there's nothing in this repository except for a README file. Next, let's click on "Settings" in the right side of the screen (that is, what I highlighted in blue although maybe hard to see).


After we click on "Settings" link, we want to scroll down to the "Danger Zone" section. In this section, we will click on the button labeled "Delete this repository".


A message will display alerting us that we need to be sure about deleting this repository because once we remove this repository there is no way to get this back. I understand the consequences, so I am going to proceed with entering the name of the repository to remove called "Java" and click "I understand the consequences, delete this repository" button.


Once I clicked this Delete button, GitHub confirms that I have successfully deleted my repository called "Java" and I can also see that my list of repositories does NOT include "Java" anymore. Excellent!!!




And that's it for today! Talk to you soon!