Wednesday 10 June 2015

JavaScript Namespacing Made Easy

I am sure all of us have had painful experiences with spaghetti JavaScript and hopefully came to realize the value in having it structured JavaScript.

Hopefully this will help with some of the namespacing pains, JavaScript does not have native namespaces but it does have JSON objects that is the next best thing. Some advantages:
  • Allowing complex structured JavaScript facilitates navigation in IDE (Go to definition)
  • Scoping in namespaces allows easier browsing and debugging in browser (Predictive text)
A normal namespace implementation



What is the advantage of using this namespacing library?
  • Easily create namespace chain with dotted notation
  • Flexible ordering (E.g. Create level 3 then define level 2)
  • Merging of namespace content on multiple declaration


 Feel free to download and use (No guarantees but suggestions or bug feedback welcome).

Examples creating namespaces using this library:


 


Friday 22 March 2013

Introduction into Java EE and Eclipse

So I have recently moved from the very familiar Microsoft stack, so hopefully I can give some tutorials for those interested in Java Web Application development.

This tutorial is just to get your basic dev environment up and running. I am using a windows development system but you can also create a similar setup on Linux (Suggest Ubuntu) if you want.

Some pre-reading
  • What is Oracle Java SE? In essence it is a platform specification from Oracle that consists of a collection of Java resources. Some primary resources include JDK (Developers) and JRE (includes JVM and allows the JDK code to execute). Read more on each version’s Java Docs (E.g. Java SE 6).
  • What is Java EE? Oracles enterprise java platform, it is an extension of Java SE. This provides an API and runtime environment for rich enterprise application that can be deployed to the likes of WebSphere, Glassfish and JBoss.

Downloads


Setup Instructions

1. Create the following folder structure
  


2. Install JDK 6
  *Be sure to change the target directory to ‘c:\development\bin\jdk1.6.0_43

3. Extract the Eclipse folder in the downloaded ZIP file
   *Extract the folder to ‘c:\development\bin\eclipse


Another alternative IDE is IntelliJ IDEA, I suggest Eclipse to start off as not IntelliJ features are free.

4. Set Java System Runtime Environment Variable


Right click ‘My Computer’ > Properties > Advance > Under ‘System Variables’ > New

Variable name:         JAVA_HOME 
Variable value:          c:\development\bin\jdk1.6.0_43

5. Extract Tomcat 6

*Extract tomcat folder to ‘c:\development\bin\apache-tomcat-6.0.36’

This is for development, most likely you will deploy to WebSphere, Glassfish and JBoss as your production environment. 

6.  Open Eclipse



a.  At startup you be prompted to specify a working directory. Navigate to the created ‘c:\development\workspace’ folder and select ‘Use this the default..


 

b.  We need to add the extracted Tomcat 6.



Navigate to the tab ‘Servers’ below. Right click > New > Server. Under Apache select ‘Tomcat v6.0 Server’ and next. Browse to the extracted Tomcat folder and finish.

7.  Create a very basic Web Application to test environment



a.  Select ‘File’ > ‘New’ > ‘Dynamic Web Project’ > Give name ‘Test Environment’ > Finish



b.  In ‘Project Explorer’ under ‘WebContent’ right click and create ‘New’ > ‘File’ > Create ‘index.jsp’



c.  Inside the open file, click on the white and press Cntr+Space. This will give a list of scaffolding options. Select ‘New HTML File (5)..’ and enter a basic <H1> hello world text.

<body>
<!--  Add this below -->
<H1>Hello world!</H1>
</body>


d. Right click on the ‘index.jsp’ > Run as > Run on Server. Select the added Tomcat server and ‘Always use this server when running this project’ > Finish







If you can see the hello world you have successfully created a basic JAVA EE and eclipse dev environment.



Eclipse - Overview


·         Project Explorer
The is the main project map and navigation section

·         Main Canvas
Files open and currently being looked at. A good thing to know here is you can maximize/normalize a tab by double clicking on it.

·         Perspectives
Different viewports, debug is the other main one you will use. Some companies create their own flavors (customized) versions of Eclipse; these are likely to include their own perspectives.

·         View/Tools
Having the right set of tools and views goes a long way. Here is a couple of important ones

View
Description
Markers
Here you find the list of compile time errors and warnings
Servers
Here you will find your Tomcat server and configure it
Tasks
Find your project ToDo’s here
Console
View the output of your loggers and System.out
Breakpoints
Show the list of set breakpoints
Expressions
This allows you to test code while debugging and check their result


Some important menu actions

Action
Description
Build Project
Project > Build Project
Clean Project
Project > Clean (Sadly this needs to be done regularly)
Clean Server
In ‘Servers’ > Right click on server > Right click > Clean
Run on Server
Right click on file (E.g. index.jsp) > Run As > Choose server
Debug on Server
Right click on file (E.g. index.jsp) > Debug As > Choose server
 

Some important Shortcuts

Shortcut
Description
Ctrl+shift+t
Extensive type search through all available libraries
Alt+Shift+s
Open menu for generating formatting scaffolding
Tab
Tab indent forward
Shift+tab
Tab indent backward
Ctrl+1
Click on import before. Let eclipse clean and organize imports.
Ctrl+t / F4
Open Type Hierarchy. Very powerful inheritance viewer
F3
Go to definition
Alt-left
Go to previous file
Alt+right
Go to next file

                                         
Install Additional Software

·         Add from Marketplace
*Access through ‘Help’ > ‘Eclipse marketplace’. If you don’t see it you might need to add it manually.

·         Add additional software manually. Here is an example of two:
      *Add form ‘Help’ > ‘Install new software’ > Add (Enter name and URL)

Add ons
URL
Subclipse
http://subclipse.tigris.org/update_1.8.x
m2e
http://subclipse.tigris.org/m2eclipse/1.0