Tag Archives: java exception handling

Java Metering by Dropwizard Metrics

We saw how we can do the relaxing Java Metering using Shirt occasion audience in one of our previously content.

Here we are going to see how to use Dropwizard Analytics structure to do the metering of our relaxing source techniques. Dropwizard Analytics is using Shirt activities audience internal to accomplish this. They have offered awesome wrapper and plenty of plug-in to collect the efficiency of each source techniques without much attempt.

There are 3 actions engaged in-order to accomplish this.

Analytics reliance in Expert pom
Sign-up ‘MetricRegistry’ and ‘ConsoleReporter’ in our source configuration
Offer @Timed or @Metered annotation for source methods

Since we are going to use Analytics structure within Shirt (restful Java) structure, the second reliance is needed. If your relax support execution is NOT using Shirt structure, then you can neglect the ‘metrics-jersey2’ reliance. This will bring the essential collections in our program after the synchronize function.

Register ‘MetricRegistry’ and ‘ConsoleReporter’:

Both MetricRegistry and ConsoleReporter implementations are arriving from Analytics structure. They actually deliver the chance to catch the efficiency of our source techniques and release the aggregated lead to system as a study.

public class RestSkolApplication extends ResourceConfig {
private static final Logger logger = LogManager.getLogger(RestSkolApplication.class);
private Set<Class<?>> classes = new HashSet<Class<?>>();
public RestSkolApplication() {
initializeApplication();
}
private void initializeApplication() {
registerListeners(); // Register listeners
}
private void registerListeners() {
final MetricRegistry metricRegistry = new MetricRegistry();
register(new InstrumentedResourceMethodApplicationListener(metricRegistry));
ConsoleReporter.forRegistry(metricRegistry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build()
.start(1, TimeUnit.MINUTES);
logger.info(“Console reporter is enabled successfully!”);
}
}

The system review will review the efficiency metrics for every moment. This period can be configurable. So modify the period centered on your need.

@Timed or @Metered annotation:

The last phase is to add either @Timed or @Metered annotation in the REST source techniques like below:

@Path(“books”)
public class BookResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Timed
public Response getAllBooks() {
System.out.println(“Get all books resource is called”);
final List<Book> books = BookDataStore.getInstance().getBooks();
return Response.ok()
.entity(books)
.build();
}
@Path(“{id}”)
@GET
@Produces(MediaType.APPLICATION_JSON)
@Timed
public Response getBook(@PathParam(“id”) String id) {
final Book book = BookDataStore.getInstance().getBook(id);
return Response.ok() // (Response code)
.entity(book) // (response value)
.build();
}
}

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

A shortnote on Java8 and its default interfaces

As Java evolved over the years, the connections presented in the Java library require adding new performance. If you add new techniques in the interface without having standard techniques function, all the sessions that already implemented the connections should go through a modify. This results in changing thousands of lines of code. To avoid this, the Java 8 presented the standard technique function. That is, if you want to add any performance to the current interface, you can add it by using the standard technique function without affecting the implementations.

Let us see some examples to understand this better. For example, I am declaring “BookInterface” with start and look functionalities. The execution sessions of this interface should provide the and look technique implementations.
package org.smarttechie;
// The interface is intended to open and read. The implementors should implement the methods to open and read.
// @author Siva Prasad Rao Janapati
public interface BookInterface {
// This method opens the book
public void openTheBook();
// The method reads the book
public void readTheBook();
}
Now, we will offer the execution to the above interface.
package org.smarttechie;
// The JavaBookImpl is the implementation of BookInterface
// @author Siva Prasad Rao Janapati
public class JavaBookImpl implements BookInterface {
// This opens the book
@Override
public void openTheBook() {
System.out.println(“The Java book is opened”);
}
// This reads the book
@Override
public void readTheBook() {
System.out.println(“Reading the Java book”);
}
}
Now we want to provide near performance to the guide interface.
If you add near performance to the guide interface, the current execution class should go through a modify. With the standard technique function, we can add near performance to the guide interface. The standard technique will be available to all the implementations.

package org.smarttechie;
// The interface is intended to open and read. The implementors should implement the methods to open and read.
// @author Siva Prasad Rao Janapati
public interface BookInterface {
// The method opens the book
public void openTheBook();
// The method reads the book
public void readTheBook();
// The default method implementation
public default void closeTheBook() {
System.out.println(“Closting the book”);
}
}
package org.smarttechie;
// The JavaBookImpl is the implementation of BookInterface
// @author Siva Prasad Rao Janapati
public class JavaBookImpl implements BookInterface {
// This opens the book
@Override
public void openTheBook() {
System.out.println(“The Java book is opened”);
}
// This reads the book
@Override
public void readTheBook() {
System.out.println(“Reading the Java book”);
}
public static void main (String[] args) {
BookInterface bookInter = new JavaBookImpl();
//Call the default method declared in BookInterface
bookInter.closeTheBook();
JavaBookImpl book = new JavaBookImpl();
book.closeTheBook();
}
}

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

Do I need to learn Java for Hadoop?

People regularly ask me if it’s necessary to have Java development abilities in order to type in the interesting world of Hadoop. When I begin to describe, I’m often met with a frustration and a feeling of restriction upon studying that Java and Hadoop do, in fact, go hand-in-hand. Let me start by saying that the response to the query “Do I need to know Java to understand Hadoop?” is not a easy one. But I digress; the long run of Hadoop is shiny, and moving ahead, no specifications should be seen as restrictions or hurdles, but rather as ways to enhance your abilities and become more professional in your work. As you make your way through this, Hopefully I will be able to describe your issues, and help get you on your way to quality within Hadoop.

To get to the base of this query it’s necessary to look into the record of Hadoop. Hadoop is Apache’s open-source platform; designed to shop and procedure loads of information (orders of petabytes). It happens to be designed in Java. (Personally, I see the terminology choice as merely random.) Hadoop was initially designed as a subproject of “Nutch” (an open-source search engine). It was later designed and would go on to become Apache’s most important venture. At the time this was all occurring, the Hadoop designer group was more relaxed with Java than any other terminology.

Let’s proceed to must program

Hadoop resolves large information systems difficulties through the mature idea of allocated similar handling, but techniques it in a new way. Hadoop provides a structure to build up allocated programs, rather than fix every problem. It requires away areas (such as device problems, allocated procedure control etc.) of saving and handling the information in a allocated atmosphere because they build the primary components: HDFS and MapReduce, respectively.

HDFS is an allocated data file program that controls information storage space. It shops any given computer data file by breaking it into set dimension models known as “blocks.” Each prevent is saved on any device in the group. It provides high accessibility and mistake patience through duplication (think of it as duplication) of these prevents on different devices on the group. Regardless of all these complications, it provides a easy data file program abstraction so that the consumer need not worry about how it shops and operates.

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

Performance of Java vs C explained over here

Java is the formal development language of Android operating system and it is the foundation for many elements of the OS itself, plus it is found at the main of Android’s SDK. Java has a couple of exciting qualities that make it different to other development ‘languages’ like C.

First of all Java doesn’t (generally) gather to local device system code. Instead it gathers to medium difficulty terminology known as Java bytecode, the training set of the Java Virtual Machine (JVM). When the app is run on Android operating system it is implemented via the JVM which consequently operates the system code on the local CPU (ARM, MIPS, Intel).

Secondly, Java uses computerized storage control and as such utilizes a Garbage Collection (GC). The idea is that developers don’t need to bother with which storage needs to be released as the JVM will keep a record of what is required and once a area of storage is no longer being used the rubbish enthusiast will 100 % free it. The key advantage is enterprise run time storage leaking.

The C development terminology is the complete reverse to Java in these two aspects. First, C system code is collected to local device system code and doesn’t require the use of an online device for presentation. Second, it uses guide storage control and doesn’t have a rubbish enthusiast. In C, the developer is required to keep a record of the things that have been assigned and 100 % free them as and when necessary.

There are other variations between the two ‘languages’, however they have less of a positive change of the specific stages of efficiency. For example, Java is a product focused language, C is not. C is intensely dependent on suggestion mathematics, Java does not. And so on.

Performance

So while there are philosophical style variations between Java and C, there are also efficiency variations. The use of an online device contributes an additional part to Java that isn’t required for C. Although using an online device has its benefits such as high mobility (i.e. the same Java based Android operating system app can run on ARM and Apple gadgets without modification), Java system code operates more slowly than C system code because it has to go through the additional presentation level. There are technological innovation which have decreased this expense to the barest lowest (and we will look at those in a moment), however since Java applications aren’t collected to the local device system code of a device’s CPU then they will always be more slowly.

The other big aspect is the garbage collection. The problem is that rubbish selection needs time, plus it can run whenever you want. This means that a Java system which makes lots of short-term things (note that some types of Sequence functions can be bad for this) will often induce the rubbish enthusiast, which consequently will reduce the system

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

Java’s risk got fixed within in one and a half year

In July 2013, protection company Security Research found a security risk in Java 7u25 by which an enemy could completely evade the Java sand pit. Oracle launched a spot in upgrade 7u40, but as Security Research declared a few months ago, the spot only resolved the evidence of idea, and a simple rule adjustment still reveals the risk. Moreover, following research has exposed that the weeknesses is even more serious than originally exposed. After the problem became public, Oracle launched a spot as part of 8u77.

The risk can be seen in the new representation collection, available since Java 7, and more specifically in the new MethodHandle classification used for dynamically obtaining and invoking methods. It is related to the way sessions packed by different ClassLoaders are handled. Understanding of the problem needs some basic knowledge ofthe way Java ClassLoaders work; since classification running is one of the least recognized elements of Java, we will start working on give an intro to this idea prior to describing the problem itself.

Java ClassLoaders

Java has the capacity to fill rule dynamically at playback from a variety of resources. The actual through a special type of sessions called ClassLoaders. A standard Java execution might offer several ClassLoaders to fill sessions from data system, a URL, or a zipped computer file, among others, but also provides designers the capability to create their own customized ClassLoaders to handle customized specifications. The regular way to have interaction with a ClassLoader is by contacting its loadClass(String) method, which will agree to the name of a classification, and either return the associated Class item if found, or toss a ClassNotFoundException otherwise. Every classification in a Java application is packed this way by one ClassLoader or another.

Different ClassLoaders can be linked to each other to form a structure by giving a father or mother ClassLoader. If no mother or father is allocated, parents ClassLoader is late to the one that packed this particular ClassLoader (ClassLoaders are sessions themselves, and therefore need to be packed by some ClassLoader). When a father or mother ClassLoader is present, the standard behavior of a ClassLoader is to try to assign the running of the asked for classification to its parent; only if parents (or some grandparent) cannot fill the course, will this ClassLoader attempt to fill the asked for classification itself. However, makers of customized loaders are not required to apply this standard behavior, and they could choose to apply a different one.

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

The existence of Java vulnerabilities is proved

More Microsoft windows customers are setting up areas, but the Oracle Java and The apple company QuickTime issues are even more intense than they were last season, according to Secunia reviews on the 2010 first one fourth. Individuals may think their PCs are protected because they are working Microsoft company windows Upgrade, but most are still at threat because of risk in third-party applications.

Secunia’s figures are based on Microsoft windows PCs working its free Personal Application Examiner, so they only signify a part of the market. Because PSI encourages individuals update insecure software, most non-PSI customers are probably in a more intense place.

In the January-March one fourth, 93.9 % of UK customers had repaired their Microsoft windows based pc, and 96.2 % had repaired other Microsoft software, such as Microsoft Office (PDF). However, 11.9 % still had unpatched third-party software. The figures for the USA were a little bit worse: 93.5 % had repaired the OS, 96.1 % had repaired other Microsoft software, and 12.7 % had unpatched third-party software

The significant issues are Apple’s QuickTime and iTunes, Oracle Java JRE, and Adobe Audience.

In the UK, for example, unpatched Java set ups risen from 36 to 41 % in contrast to the first one fourth of last season, and unpatched QuickTime set ups improved from 55 to 61 %. Luckily, for most customers, both applications can be removed without a important charge. (Adobe Innovative Package customers may have a QuickTime issue.)

Java is a long-running issue, but things may enhance. Oracle has been pressured by the US FTC to apologise for misleading customers about its protection up-dates, and it has been required to weblink to something that uninstalls old editions.

Adobe Audience is another long-running problem: it had 121 weaknesses, which is almost as many as The apple company iTunes (130). Unfortunately, more than 50 percent the Adobe Audience set ups were unpatched.

QuickTime for Microsoft windows is a increasing issue because The apple company has lastly given up on it. Unfortunately, many customers may have skipped the protection signals, eg from US-CERT.

In its full review, available free on demand, Secunia mentioned at Microsoft company offered 67 % of the Top 50 programs running on PCs but third-party programs experienced 79 % of the weaknesses. (The table below reveals the 20 most-commonly set up programs.)

In the Top 50 programs, areas were already available for 84.6 % of the weaknesses found, and there were 23 zero-day weaknesses, in comparison to 20 in 2014.

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

Is Java stuck up with mobile devices?

Over the last a few several weeks, as part of my Smart cellphone Success Analyze as a dyed-in-the-wool iPhone and iOS customer, I’ve been submerging myself in the world of Android operating program — particularly, low-cost Android operating program devices made mostly in Chinese suppliers.

I’m not an extensive newbie when it comes to Android operating program. Actually I used Android operating program for several years before providing up on it this year. I am also competent in the essential techniques structure of the OS itself and how it operates on various ARM-derived rubber styles.

One of the goals of my Success Analyze is to see if a lower-cost Android operating program cellphone can, in reality, substitute my much more costly iPhone 6S. Three several weeks into quality, I am progressively of the viewpoint that the response is yes.

I still have my issues with Android operating program cellphone components and the OS itself, but they are not deal-breaker issues in any respect. All of these eventually are resolvable, and in time the OEMs, Search engines and the Android operating program designer group at large will find methods to them.

But fixing some issues will need hard options. One of those may be an extensive essential re-architecture of the Android operating program OS itself, in order to cope with what I consider to be an important flaw: considerably greater source usage in comparison to iOS.

Android’s Achilles high heel, aside from the “toxic hellstew” of protection areas and fragmentation which is outside the opportunity of this post and my Success Analyze sequence — is Java.

Java, beyond being an object-oriented development terminology with a C-like format, is the main efficiency atmosphere within Android operating program itself that operates many of the applications and user-land procedures in the cellular OS.

The execution/runtime atmosphere for applications coded in Java is a Java Exclusive Device, or JVM. A JVM can run on any processing system. That’s one of its best features. You can run Java applications on any program that operates a suitable JVM, and regardless of whether they have the same program structure.

The structure can be Apple or AMD x86, it can be IBM POWER, it can be Oracle’s UltraSPARC. Or it can be one of the many variations of ARM-derived processor chips.

So the program operating the JVM could be a mainframe, a big metal UNIX program, an x86 server, a PC, a Mac, a smartphone, a product, or even a smartwatch or a microcontroller in an included program.

Java’s mobility variety is impressive: It machines from the most important techniques with large levels of storage and CPU to the actual, low-power processor chips that are extremely resource-constrained.

The only thing they need in typical is a JVM, and the rule is basically convenient between methods with minimal variations.

There are different kinds of JVMs, such as server-side (J2EE), Java Conventional Edition on PCs and Mac pcs (J2SE) and Java Small Edition (J2ME) which was once used on foolish cellular mobile phones and the traditional BlackBerry.

Each of these sorts of JVMs have different efficiency and source usage information because they are focused towards different kinds of techniques.

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

JDK Array Sort

In this article, we will discuss one of the JDK 8 feature called parallelSort. Before getting into the details of parallel sort, we will see sort method implementation.

The sort method will use the “merge” sort algorithm or Tim Peters’s list sort algorithm to sort the elements. “Merge” sort will use divide and conquer methods to sort the elements. The lager array will be divided into two parts and then each part of the elements will be divided further until there are no possible way to divide. The individual chunks will be sorted based on an “insertion” sort algorithm and then the results will be merged. To sort the larger array, it will have performance problems.

To avoid this, in JDK 8 we have a new feature called “ParallelSort“. This method will make use of “Fork/Join” framework. This will make use of all available processing power(On multicore processors) to increase the performance. Fork/Join framework will distributes the tasks to worker threads available in the thread pool. The framework will use “work stealing” algorithm. The worker threads which doesn’t have work will steal the work from the busy worker threads.

The Arrays#parallelSort method will decide whether to sort the array in parallel or in serial. If the array size is less than or equal to 8192 or the processor has only one core, then it will use Dual-Pivot Quicksort algorithm. Otherwise, it will use parallel sort.

public
static void parallelSort(char[] a) {
int n = a.length, p, g;
if (n <= MIN_ARRAY_SORT_GRAN ||
(p = ForkJoinPool.getCommonPoolParallelism()) == 1)
DualPivotQuicksort.sort(a, 0, n - 1, null, 0, 0);
else
new ArraysParallelSortHelpers.FJChar.Sorter
(null, a, new char[n], 0, n, 0,
((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
MIN_ARRAY_SORT_GRAN : g).invoke();
}

The sample demo code is given below.

import
java.util.Arrays;
public
class SampleArrayDemo {
/**
* @param args
*/
public static void main(String[] args) {
double[] arr = new double[10000001];
for (int index = 0; index < 10000000; index++) {
arr[index]= Math.random();
}
System.out.println("The starting time" +
System.currentTimeMillis());
Arrays.parallelSort(arr);
//Arrays.sort(arr);
System.out.println("The end time" +
System.currentTimeMillis());
}
}
Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

Using Javascript Frameworks and Google’s Crawling Suggestion

At SEJ Peak on Wed, Maile Ohye from Google was requested about websites that are created using new JavaScript frameworks and modern style element they can create fantastic looking websites, but when it comes from searching viewpoint, they can definitely cause creeping and position issues with not just Google but all look for search engines.

Ohye said it is best to always check in Google Search System with the bring and provide device to make sure that Google is able to both spider and provide the site effectively. She said that there are always new Javascript frameworks being launched.

As many SEOs know, the intense websites that web developers come up with don’t always mean they are also SEO or online look for engine friendly. And there are often discussions in the Google Website owner Help boards from website owners with these wonderful websites that Googlebot can’t process effectively.

So prior to releasing a website, especially one that uses a lot of programs to provide the site, always use Google’s bring and provide device to make sure it is working – and being indexed – as designed.

Despite some labeling, syntactic, and standard collection resemblances, JavaScript and Java are otherwise irrelevant and have very different semantics. The format of JavaScript is actually produced from C, while the semantics and style suffer from the Self and Plan development ‘languages’.

JavaScript is also used in surroundings that are not Web-based, such as PDF records, site-specific web browsers, and pc icons. More recent and quicker JavaScript exclusive machines (VMs) and systems built upon them have also improved the reputation of JavaScript for server-side Web programs. On the consumer part, JavaScript has been typically applied as an considered language, but more recent web browsers perform just-in-time collection. It is also used in game development, the production of pc and mobile apps, and server-side network development with playback surroundings such as Node.js.

JavaScript was initially created in 10 days in May 1995 by Brendan Eich, while he was working for Netscape Emails Organization. Indeed, while competitive with Microsof company for user adopting of Web technological innovation and systems, Netscape considered their client-server providing a allocated OS with a transportable form of Sun Microsystems’s Java providing an atmosphere in which applets could be run. Because Java was a opponent of C++ and targeted at professional developers, Netscape also wanted a light-weight considered terminology that would supplement Java by attracting nonprofessional developers, like Windows Visible Basic.

Although it originated under the name Mocha, which was formally called LiveScript when it first delivered in try out produces of Netscape Gps 2.0 in Sept 1995, but it was relabeled JavaScript when it was implemented in the Netscape web browser edition 2.0B3.

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

Learning Java will provide you a Lurcrative Career

The Expert Choices group creates about things we think you’ll like. Company Expert has online relationships, so we may get a discuss of the income from your purchase.

Java is one of the most favored growth ‘languages’ in the globe. It’s assisted develop some of the most favored websites, such as Search engines, Facebook, YouTube, Blockbuster online, Amazon. com, and Tweets. For the ambitious web designer, a understanding of Java is important to advancing work.

If you’re completely new to programming or just getting started, there are two ways you can go about seeking your growth studies: learn a little bit of many different ‘languages’ at once or concentrate on studying one terminology inside and out before shifting to others. Anyone more enthusiastic about the former choice should check out the offer we had written about last night, which is still going on, but for those taking the latter direction, StackSocial’s Finish Java Programming Boot camp is the ideal beginning point.

The cope comprises of 10 sessions protecting each and every aspect of Java growth. To begin with, there are two programs targeted to get those completely new to which relaxed with its guidelines and format, providing you the standard information you need to go through the remaining of the sessions. From there, you’ll get training on multithreading, style styles, information components, and more — all of this should help to get you ready for the expert realm of growth.

Purchased independently these ten programs would cost $740, but through this cope you can join all of these programs for just $69. For anyone dedicated to beginning a profession in programming, there’s great value here.

Salaries are Averages

Is it reasonable that PHP designers are compensated 25% less than Java developers? No — but it’s incorrect.

Salaries are based on the value of the product you’re developing and your personal participation to the venture. It doesn’t issue whether you’re using Java, PHP, COBOL or QBasic.

Despite the numbers above, there are more PHP than Java roles; PHP operates on 80% of the world’s web web servers and WordPress abilities one in four websites. You’ll discover tasks where PHP is better compensated than Java, but you’ll also discover many tasks in concept growth or common website assistance at the budget of the wage range. The regular PHP wage is decreased.

Job Headings are Vague

You’ll hardly ever see tasks promoted for “Java Developer”, “PHP Professional” or “Python Programmer”. The top-paying part is Service-Oriented Architecture? That could explain abilities required by every designer, regardless of their terminology specialisms.

Jobs are Multi-skilled

The days of being able to create a profession with a single terminology are long gone. Most positions require a great number of abilities — such as business research, techniques structure, data source style, information return types, frameworks, graphics, front-end growth and assistance. Those working on the web will be revealed to HTML, CSS and JavaScript even when the job advertisement forgets to bring up it.

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page