Why and How to use JRebel in Java

First of all you should know about what is JRebel and why you should use it with your Java program. This post reviews some of the great advantages of using JRebel in Java development, and how eradicating the daily, time-consuming process of redeploying your application to see your changes has long-lasting effects on the way that you will write code in the future.

What is JRebel ?

According to their website -

"JRebel is an anything-Java plugin that speeds up JVM-based development (Java, Scala, Groovy) by reloading changes made in your workspace into a running JVM, without restarts or redeploys, maintaining the state of the application while you’re coding."

What would you rather be doing?

According to above image you can easily find that when you make a Java web application then whenever you change in your Java code you need to build, deploy and then run your changes which take some crucial time. But when you use JRebel then it save your time to build and deploy. Now you just change your Java code and test your program instead of build and deploy your application.

How to add JRebel in your IDE(Eclipse, MyEclipse, Netbeans etc.)

After activating right click on your project in IDE and find JRebel option.

Add JRebel in that project which create rebel.xml in WEB-INF/classes.

Thats it. Change your code and run the program.

Demo :

Why you use JRebel ?

Advantage #1: See all changes immediately

Does your code smell? Find out really quickly and run your own mini-tests throughout the day. Remove bad code before it goes to QA and they make fun of you.

With JRebel, you get to see the your changes immediately after compiling them. When the IDE builds classes automatically, the process is as fast as using a scripting language or testing your latest HTML changes. In fact, I urge you to try compiling the following code snippet, start it up with JRebel enabled, and change the “Hello World” part to something else while the program is running.

This opens up a world of possibilities that have never before been available for developers. It combines the power of Java with the fast turnaround of dynamic scripting languages. You don’t have to queue up gazillion changes before redeploying. You can code by making small incremental changes and alt-tabbing to your browser to verify the results.

Advantage #2: Fine-tuning through incremental changes

This works best when you have to implement some logic that is tricky to get just right. Imagine you have to add validation to your form. With JRebel, you can add the rules field by field and play around with the way errors should be displayed until satisfied by the results. You may want to add some new fields to your controller or validator. That is supported, too. By the way, JRebel preserves all application state, which means it does not matter how you reached the page you’re modifying.

JRebel actually goes way beyond “simple” class reloading. Applications today take advantage of frameworks and JEE technologies, such as EJBs, Hibernate, Spring Framework, JSF, Seam, Struts, etc. The thing with those frameworks and technology implementations is that they initialize themselves when the application starts up and generate lots of metadata. It is usually a good thing since nobody wants Hibernate to re-initialize itself for every HTTP request (that’s what PHP programs have to do, by the way, even with opcode caching enabled).

JRebel has addressed this by having explicit support for almost 60 popular frameworks and application containers. This means when you make a change to a “special” resource such as adding a new EJB, changing JPA mappings (either via xml or annotations), or add new Spring Beans (again, either via xml or annotations), JRebel updates the metadata to reflect those changes. Your job is to press F5 in the browser.

Advantage #3: Debug remotely for fun and profit

JRebel makes remote debugging more useful than ever. Imagine you are using it to hunt down some difficult bug. Now you can hit a breakpoint, investigate what’s going on, make a change, resume execution, and see the result almost immediately!

The new code kicks in right after compiling the code, next time when the affected method is invoked. You can use this approach to fix discovered bugs immediately or to quickly add some debugging statements in the code (just remember to avoid committing them). You can even drop to a parent frame and check the effect immediately!

Advantage #4: Explore the code with ease

One of the benefits of small turnaround is that you can test the framework features interactively. You can write a small method to test some functionality of a new framework and learn hands-on how it works. Python and Scala even have interactive shells.

The problem here is the applicability in real world. While exploring the API of Java libraries is easy (even if they lack documentation), it can be ridiculously tedious in some other languages, especially when they are dynamic in nature, lack documentation, and/or miss out on good IDE support.

Even if you can indeed enjoy the fast turnaround with PHP and the like, it has little net value when you have to dig into some big and obscure framework (like Joomla CMS, which I actually tried that a few years ago, and it wasn’t pleasant) to see how it works. The ability to ctrl-click and dive into the code, as well as enjoy the auto-completion would be great, if only they were there. Granted, there is some support for it in modern IDEs, but it is nowhere nearly as useful. The difference is in the order of magnitudes.

Java, on the other hand, suffers from the fact that while the 3rd-party code is easily navigable, writing the stubs and running them can be tedious or time consuming. Writing stand-alone tests requires effort to set up and are not exactly a substitute for a real-world use case.

Embedding a test code into an existing application is simple and easy, but restarting the server or redeploying the app to see the changes takes time...unless you’re using JRebel to eliminate the need to restart.

Advantage #5: Deploying code locally or remotely

It’s great when a developer can check out code from a repository, compile it, and deploy the thing in his own machine. Sometimes this is not possible due to performance reasons, or the whole system is simply too complex. Sometimes the system has to run in a different network than the developer’s, which cannot be easily simulated. Some developers may be using low-powered laptops. Whatever the reason, sometimes running the app in the same machine is not an option.

I can almost hear developers cry (myself included) when that is the case. JRebel can help even in this case and the capability to make a system deployable on a developer’s machine is not crucial anymore.

JRebel Remoting (beta) was introduced from version 4.6, which lets you push changes from a developer’s machine to a remote server. It works over HTTP on the same port as the server is serving the application itself, therefore needs close to zero configuration to set up and no changes to firewall settings. In the screencast, we show JRebel Remoting in action when deploying to Amazon EC2, so if it can work well in the cloud far away, it will definitely work in your LAN or on the other side of the city.

You can even let multiple developers loose on a single application instance on a remote machine (but not simultaneously). By default, JRebel Remoting reverts back to the initial codebase when the app server is restarted. You can set up an application on the remote machine, have a developer have his way with it, restart it (ok, there’s one redeploy, sorry), and allow another developer do his magic on the app. This is the case when both developers are making changes to the same application. When there are several apps deployed to the remote server, developers can bombard them without stepping on each other’s toes.

Advantage #6: No restarts = More time for better stuff

No restarts means no forced interruptions, which means devs have more time for doing better things. Sometimes it’s hard to maintain concentration on a single task for more than a few minutes, and that’s when the level of focus is totally up to me. If there was a circus clown jumping out from behind a door every 6 minutes to frighten me, I couldn’t imagine working properly throughout the day.

With JRebel, you get more time to meet your deadlines, research & learn and *gasp* communicate with people. According to a recent report on Developer Stress, it came out that developers really do care about making deadlines and their level of expertise, wishing they had more time to spend on education. We also discovered that for every 1 hour developers spend writing code, they spend 30 minutes dealing with communication overhead (i.e., meetings, chats, reporting/timesheets, etc.). JRebel’s instantly class reloading magic simply frees up more time for doing the things that developers are already spending time on. The 2012 Developer Productivity Report is FREE and packed with Java stats, analysis and interviews. Inside you’ll find expanded coverage on technologies and tools used by Java development teams along with analysis and interviews with Java experts on “What makes developers tick?”

Final words

JRebel will give you the best of both worlds—the performance, scalability and robustness of Java, as well as the FTL-turnaround and the feeling of lightness, which are typically associated with 100-line guestbook applications, not with big mature systems. JRebel behaves as if it’s in Rome—you don’t have to make changes to your code, architecture or sysops. It adapts to your environment and requirements. All you have to do is start using it. You get to keep all the effort and investments already made to your infrastructure.

Today i am telling you trick for Android in which you can control an Android phone using PHP by using Termux which is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required.
What is PHP Termux API?Termux App is a useful Android app which enables us to use a sort of Linux console inside our Android devices, like phones, tablets, and so on.

It needs the Termux:API add-on app to be installed, so it can use a command line programs that expose Android functions to Termux system. Inside Termux we can access networking (wi-fi and mobile internet).

Recently i added a post on animated moving marker on Google map with full source code. But now i am giving you demo of that source code by which you can easily find out how it feel to work.
You can be download source code from here.

How to check below demo :
Here you'll got two text field(for starting and end point) with submit button. Just add both destination and click on submit button. You got the magic.
Demo :
Review :
If you think this post is helpful then please comment below for appreciation.