DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Bridging JavaScript and Java Packages: An Introduction to Npm2Mvn
  • Node.js Unveiled: Why You Should Use It for Enterprise Apps
  • Techniques You Should Know as a Kafka Streams Developer
  • Legacy Code Refactoring: Tips, Steps, and Best Practices

Trending

  • Memory Leak Due to Time-Taking finalize() Method
  • Streamlining Event Data in Event-Driven Ansible
  • Contextual AI Integration for Agile Product Teams
  • Power BI Embedded Analytics — Part 2: Power BI Embedded Overview
  1. DZone
  2. Coding
  3. JavaScript
  4. From Java to Node.js

From Java to Node.js

By 
Chris Smith user avatar
Chris Smith
·
Jan. 10, 12 · Interview
Likes (2)
Comment
Save
Tweet
Share
28.0K Views

Join the DZone community and get the full member experience.

Join For Free
I’ve been developing for quite a while and in quite a few languages.  Somehow though, I’ve always seemed to fall back to Java when doing my own stuff – maybe partly from habit, partly because it has in my opinion the best open source selection out there, and party because I liked its mix of features and performance.

Originally authored by Matan Amir


Specifically though, in the web arena things have been moving fast and furious with new languages, approaches, and methods like RoR, Play!, and Lift (and many others!).  While I “get it” regarding the benefits of these frameworks, I never felt the need to give them more than an initial deep dive to see how they work.  I nod a few times at their similarities and move on back to plain REST-ful services in Java with Spring, maybe an ORM (i try to avoid them these days), and a JS-rich front-end.

Recently, two factors made me deep dive into Node.js.  First is my growing appreciation with the progress of the JavaScript front-end.  What used to be little JavaScript snippets to validate a form “onSubmit” have evolved to a complete ecosystem of technologies, frameworks, and stacks.  My personal favorite these days is Backbone.js and try to use it whenever I can.

Second was the first hand feedback I got from a friend at Voxer about their success in using and deploying Node.js at real scale (they have a pretty big Node.js deployment).

So I jumped in.  In the short time I’ve been using it for some (real) projects, I can say that it’s my new favorite language of choice.

First of all, the event-driven (and non-blocking) model is a perfect fit for server side development.  While this has existed in the other languages and forms (Java Servlet 3.0, Event Machine, Twisted to name a few), I connected with the easy of use and natural maturity of it in JavaScript.  We’re all used to using callbacks anyway from your typical run-of-the-mill AJAX work right?

Second is the community and how large its gotten in the short time Node has been around.  There are lots of useful open source libraries to use to solve your problems and the quality level is high.

Third is that it was just so easy to pick up.  I have to admit that my core JavaScript was decent before I started using Node, but in terms of the Node core library and feature set itself, it’s pretty lean and mean and provides a good starting point to build what you need in case you can’t find someone who already did (which you most likely can).

So having said all that, I wanted to share what resources helped me get up to speed in Node.js coming from a Java background.

Getting to know JavaScript

There are lots of good resources out there on Node.js and i’ve listed them below.  For me, the most critical piece was getting my JavaScript knowledge to the next level.  Because you’ll be spending all your time writing your server code in JavaScript, it pays huge dividends to understand how to take full advantage of it.

As a Java developer you’re probably trained to think in OO designs.  With me, this was the part that I focused the most on.  Fortunately (or unforunately), JavaScript is not a classic OO language.  It can be if you shoehorn it, but i think that defeats the purpose.

Here is my short list of JavaScript resources:

  1. JavaScript: The Good Parts - Definitely a requirement.  Chapters 4 and 5 (functions, objects, and inheritance) are probably the most important part to understand well for those with an OO background.
  2. Learning Javascript with Object Graphs (part 2, and part 3) – howtonode.org has lots of good Node material, but this 3 part post is a good resource to top off your knowledge from the book.
  3. Simple “Class” Instantiation – Another good post I read recently.  Worth digesting.

Learning Node.js

With a good JavaScript background, starting to use Node.js is pretty straightforward.  The main part to understand is the asynchronous nature of the I/O and the need to produce and consume events to get stuff done.  Here is a list of resources I used to get up to speed:

  1. DailyJS’s Node Tutorial - A multipart tutorial for Node on DailyJS’s blog.  It’s a great resource and worth going through all the posts.
  2. Mixu’s Node Book - Not complete, but still worth it.  I look forward to reading the future chapters.
  3. Node Beginner Book – A good starter read.
  4. How To Node – A blog dedicated to Node.js.  Bookmark it.

I felt that going through these was more than enough to give me the push I needed get started.  Hopefully it does for you too (thanks to the authors for taking the time to share their knowledge!).

Frameworks?

Java is all about open source frameworks.  That’s part of why it’s so popular.  While Node.js is much newer, lots of people have already done quite a bit of heavy-lifting and have shared their code with the world.  Below is what I think is a good mapping of popular Java frameworks to their Node.js equivalents (from what I know so far).

Web MVC

In Java land, most people are familiar with Web MVC frameworks like Spring MVC, Struts, Wicket, and JSF.  More recently though, the trend towards client-side JS MVC frameworks like Ember.js (SproutCore) and Backbone.js reduces the required feature-set of some of these frameworks.

Nonetheless, a good comparable Node.js web framework is Express.   In a sense, it’s even more than a web framework because it also provides most of the “web server” functionality most Java developers are used to through Tomcat, Jetty, etc (more specifically, Express builds on top of Connect)  It’s well thought out and provides the feature set needed to get things done.

Application Lifecycle Framework (DI Framework)

Spring is a popular framework in Java to provide a great deal of glue and abstraction functionality.  It allows easy dependency injection, testing, object lifecycle management, transaction management, etc.  It’s usually one of the first things I slap into a new project in Java.

In Node.js… I haven’t really missed it.  JavaScript allows much more flexible ways of decoupling dependencies and I personally haven’t felt the need to find a replacement for Spring.  Maybe that’s a good thing?

Object-Relational Mapping (ORMs)

I have mixed feelings regarding ORMs in general, but it does make your life easier sometimes.  There is no shortage of ORM librares for Node.js.  Take your pick.

Package Management Tools

Maven is probably most popular build management tool for Java.  While it is very flexible and powerful with a wide variety of plug-ins, it can get very cumbersome.  Npm is the mainstream package manager for Node.js.  It’s light, fast, and useful.

Testing Framework

Java has lots of these for sure, jUnit and company as standard.  There are also mock libraries, stub libraries, db test libraries, etc.  Node.js has quite a few as well.  Pick your poison.  I see that nodeunit is popular and is similar to jUnit.  I’m personally testing Mocha.  Testing tools are a more personal and subjective choice, but the good thing is that there definitely are good choices out there.

Logging

Java developers have quite a list of choices when choosing a logger library.  Commons logging, log4j, logback, and slf4j (wrapper) are some of the more popular ones.  Node.js also has a few.  I’m currently using winston and have no complaints so far.  It has the logging levels, multiple transports (appenders to log4j people), and does it all asynchronously as well.

Hopefully this will help someone save some time when peeking into the world of Node.  Good luck!



Source:  http://n0tw0rthy.wordpress.com/2012/01/08/from-java-to-node-js/

Node.js Java (programming language) Framework Open source JavaScript IT

Opinions expressed by DZone contributors are their own.

Related

  • Bridging JavaScript and Java Packages: An Introduction to Npm2Mvn
  • Node.js Unveiled: Why You Should Use It for Enterprise Apps
  • Techniques You Should Know as a Kafka Streams Developer
  • Legacy Code Refactoring: Tips, Steps, and Best Practices

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: