Tuesday, 27 February 2018

Java Multithreading Basics | Creating and running threads in Java with examples



This tutorial covers the basic concepts of multithreading in Java. It begins with explaining what is multithreading, and then shows how to create your first threads in Java using two basic approaches – extending Thread class and implementing Runnable interface. Both approaches are explained with Java code examples showing thread creation and execution. Lastly, the tutorial explains the reasons why ‘implementing Runnable approach for creating threads is preferred over ‘extending Thread approach.
Conceptual basics of multithreading

Usually when we talk of multi-programming we refer to multiple programs running on a processor. A program is a set of instructions which when executed provides a specific functionality. An example of a commonly used program is a word processor such as MS Word. From the operating system point-of-view executing instances of programs are individual processes with each process having its own memory address space allocated to it.
As a process runs, it might need to take care of multiple internal tasks in parallel in order to deliver the complete set of functionalities which it offers. For example, as a person types in the word processor, there are multiple tasks running in the background. One task is responsible for saving changes in the document in a recovery file. Another task checks for spelling and grammatical errors as the user types. Yet another task does the basic task of displaying what a user types in the editor and so on.
All the above mentioned tasks are internal to the word processor program, i.e. they share the same memory address space which has been allocated to the word processor by the operating system. At the same time these internal tasks need to execute together or in parallel to ensure the program’s functionalities are available to its users at the same time. Each of these parallel tasks are the smallest units of independent work carried out by program, and are instances of individual threads working to make the whole program work together.
To summarize the relation between programs, processes and threads. A program in execution is a process, and an executing process can have multiple threads running in parallel within it to accomplish multiple tasks that the process needs to carry out. The diagram below depicts the relationship between processes and threads.
A thread in Java is the smallest unit of dispatchable code which can be executed. As the bigger program executes in a process space of its own, its multiple internal threads carry out their individual tasks and communicate with each other to make the program work as a whole. These internal threads of work use a portion of the memory address space allocated to their parent program/process. As we will see in detail in forthcoming tutorials on concurrency management, this sharing of memory space has both advantages(inter-thread communication) and disadvantages(synchronization issues).
Thread management classes in Java are all designed around management of parallel internal threads of work over their entire lifecycle – from creation to destruction. As we study basic and advanced features for multithreading in Java in this and upcoming tutorials in Java Concurrency series, we will cover all aspects related to defining, managing and optimizing threads.
To run a piece of functionality in parallel, you will need to first encapsulate it as a separate thread and then execute that thread. Let us now learn how to define and run individual thread instances as per our needs.
Creating and running a thread defined by extending Thread class

The first way of defining your own thread functionality involves sub-classing the
java.lang.Thread class. An instance of Thread class holds a single thread of execution of a running program.
Creation of a new parallel thread using Thread class involves the following 3 steps –
  1. Define a class which extends Thread class.
  2. Override the run() method of Thread class, and write your custom thread logic in it.
  3. Invoke the start() method on your custom Thread subclass to start the thread execution.
Creating and running a thread defined by implementing Runnable interface

The second way to create a parallel thread is by implementing
java.lang.Runnable interface. There are 4 steps involved in creating and running a separate thread using Runnable
  1. Define a class which implements Runnable interface.
  2. Override the run() method of Runnable interface, and write your custom thread logic in it.
  3. Wrap the Runnable instance inside a new Thread instance. This is accomplished by using one of the multiple constructors provided by Thread class which accept the Runnable interface as parameter.
  4. Invoke the start() method on the newly created Thread instance to start the thread execution.

10 Website Architecture Patterns To Look For In 2018



Taking a gander at later plans, upgrades and even simply configuration changes, a couple of unmistakable patterns are beginning to rise as the leaders heading into 2018. Here's a gander at a portion of the website architecture inclines that will probably wind up prevalent. 

1. Topsy-turvy Matrices

To influence this idea to work, there should be a particular adjust of components with the goal that Web Designing Courses Bangalore one side of the plan isn't overwhelming. Space and content components regularly adjust visuals to help draw the eye over the plan.
Also, everything meets up in light of the fact that the outlines still live on a framework, which helps continue everything sorted out. (The components in the Club of the Waves outline, above, is sorted out in such a way which is the reason the deviated configuration feels so adjusted.)

2. All the more Brilliant Shading

Brilliant shading is by all accounts the plan incline that simply needs to stick around. It was a major piece of level plan and similarly vital to Material Outline, and the two ideas are as yet a piece of a great deal of ventures.
Indeed, even without attributes of level or Material, intense shading is attractive and can help draw a client into a plan. Brilliant and striking shading decisions have a new vibe and offer to more youthful clients.
These shading decisions can likewise make a surprising tasteful and make a funkier vibe for sites and organizations that won't not be known for this tone. Passage, above, doesn't strike a chord as a dynamic, hip organization, yet the plan for the Make it Drivable microsite radiates these feelings.

3. Base Sticky Components

Every one of those little promotions at the base of applications and portable sites are advancing toward work area and tablet outlines also. What's more, it's not only promotions in this down screen area, visit boxes, pop-ups, notices and even navigational components are adhering to the base of the screen.

4. Voice and Common Dialect Pursuit

From planning interfaces that can "hear" and comprehend voice Web Designing Course Bangalore summons to fusing seek terms that copy normal dialect, incorporating a universe of voice and dialect will be basic for web composition ventures.
And keeping in mind that some of these different patterns won't not be much more prevalent toward the finish of 2018, voice and common dialect seeks is just going to develop in utilization and notoriety. You should begin getting ready for it now so you'll have the capacity to fuse it into future tasks easily.

5. Liquid Shapes

Smoother lines are a characteristic movement of the polygon incline. At the point when Configuration Shack included the poly shapes slant not long ago, the portrayal read "extraordinary compared to other parts of this adaptable pattern is that every one of these outlines is so unique. … Polygons are normally level, two-dimensional shapes, in spite of the fact that in site extends a few polygons energize move and appear to have more 3-D attributes."

6. Unpretentious Movement

From drift states to cinema graphs to representations that appear to spring up, inconspicuous development can be an incredible apparatus to help make client engagement. To benefit as much as possible from unpretentious liveliness in the outline adhere to a few fundamental principles: pick only one activity "trap" and stick to it, movement should feel practical and emulate the laws of material science, don't drive sound or snap activities to movement and ensure the liveliness plays on a solid circle so clients know when the liveliness is finished. (That is an indication that they can proceed onward to do they thing they went to the site for in any case.)

7. SVG Pictures

Adaptable Vector Designs are winding up more typical as the de factor picture compose for sites. SVGs are lightweight vector pictures that guarantee illustrations, symbols and logos look pixel culminate paying little heed to screen size or determination.
All the high-determination shows are adding to the ascent of this document design.
SVGs additionally function admirably with still and sight and sound picture encounters, including 3D pictures, cinemagraphs, logo livelinesss and 360-degree photography. 

8. Split Screen Work area, Stacking Portable

While numerous early split-screen plans were genuinely part, numerous originators are settling on a split screen, in addition to an extra best layer with content or marking to give an impact that has more profundity.

9. Additional Looking over Movements

Parallax looking over movements has been popular to the point that a few architects are beginning to bashful far from them. In any case, that doesn't mean you need to jettison looking over activity’s inside and out.
There are a lot of different approaches to utilize look to empower client engagement. (Also, you can blend in a little parallax as well; simply don't run insane with it.) 

10. Blank area Without Moderation

The trade off is outlining with a lot of blank area, however with a substantially less moderate feel. By including more shading and outline components to a plan with a great deal of room, it can feel all the more full.
Originators are working with void area in a lot of different routes too. Investigate huge numbers of the other previously mentioned patterns and how much void area assumes a part there too.

             


Step by step instructions to Make Java Application more Maintainable



Here are some practical tips to make your Java application more maintainable. Always remember, maintenance cost is much higher than development cost and it's easy to give a solution but it's equally difficult to give a maintainable solution i.e. something which can withstand the test of time.

Before going to explains these 10 tips which can make your Java application more maintainable and easy to support, let me tell you that I have personally made a lot of these mistakes myself. It requires a great deal of discipline, hard work, and to be vigilant about writing quality code. Sometimes you have to push back even to your team lead or managers bringing the points like support, which is often overlooked.

Don't swallow exceptions
Please avoid swallowing the exceptions. The stack trace is the
most valuable troubleshooting information. In the production system where the priority is to bring the system up and then find the root cause, these exceptions are gold, without them, you will never be able to find what happened with your application at that moment. On the other hand, please don’t print the stack trace multiple times. Printing a stack trace is a resource intensive process and should be controlled i.e. you print more information while running on DEBUG or INFO mode and only print essential information while running in PRODUCTION mode.

Avoid excessive logging
This tip is closely related to the first one and at first it may look contradictory but in reality, it's not, in fact, they both compliment each other. When you run the Java application in your development environment (PC), nobody cares what’s the logging level you have. Go ‘DEBUG’ or ‘ALL’ if you please. But when it goes to production (or other higher environments e.g. QA or UAT ), limit your logging to ‘INFO’ or ‘ERROR’. Excessive logging has 3 major impacts:

1. It puts unnecessary load on the Application. I’ve seen throughput of application is reduced to half due to excessive logging.

2. It can fill up the file system very quickly and that can create issues for your application and other applications hosted on the same server. This is a serious problem especially if you are co-hosted with some other application. Do you know what will happen when root directory of certain flavors of Unix system fills up? - that’s right. No one can login into the host.

3. Troubleshooting will be painful, like looking for a needle in a haystack (if the poor support guy can ever get the log file to open).

Don't Forget to Close Database Connections
This is one of the most common reasons for production issues in the last decade, but thankfully with modern frameworks and library, this issue is actually slowly disappearing (as the framework takes care of opening/closing connections). However, make sure you always ‘close’ the database connection so that it is released back to the pool.
Don't underestimate production load
If you are an
experienced Java developer you would have noticed that most of the issues are exposed in the production environment rather than in UAT or QA environment, especially concurrency related issues? Do you know why? because of production load.

You might have heard developer talking to support personnel that  ‘It works fine in my development environment. But when it went to production, it crashed’.

Yes, it is the job of the load testing team to test your application with the production like load. But that does not mean that as a developer you write code that does not scale well. For example, it works fine for 1 user, but what happens when there are 500 users online simultaneously.

Avoid loading large result sets from Database
This is one of the common mistakes made by beginners and intermediate Java programmers who don't know about paging or pagination. You simply cannot load every record e.g. order or trade from database in one call. In some cases, obviously, you will run out of memory and it is also a waste of network bandwidth, CPU and memory as the user might not need all of those data.
Avoid hard coding Configuration Parameters
You might have heard this tip several times but you would be surprised if you look at the code written by many professional software engineers and programmers. There is hardly a code where something is not hard-coded but hard-coding configuration values like URLs, directory locations, username/passwords, cache sizes, log levels etc in the code results in hard to maintain Java applications.

Avoid packing multiple versions of same JAR files
Packaging utility jar files in several places, especially various versions of the same utility jar in various locations is the cause of many production issues.

You must have a clean build and versioning processing, especially for internal applications.  Consider using Maven for dependency management, it makes life a lot easier than keeping versioned JAR files in the lib folder.

Monday, 26 February 2018

Does UI Turns Out To Be Extremely Critical.



In case you're perusing this and you dissent, at that point that is extraordinary, I'd love to hear your considerations on the positive parts of Java UI, please abandon them in the remarks area toward the finish of this post. 

Most importantly, what is a UI? 

You may have seen that, up until now, there has been no genuine "communication" amongst you and the code you've been composing. All that happens is you say "Keep running as Java Application" and UI Designing Course in Bangalore afterward your code may yield something into the support. In any case, at that point your program closes and that is it! There hasn't been any genuine cooperation with you while the program is running. This is the place a UI turns out to be extremely critical.
A case of a UI is a window (or exchange) that shows a frame on your screen. This shape has fields for you to round out, as username and secret word. You can type in your username/secret key mix, at that point hit a "submit" catch, and afterward the program will spring to life and check that your username/watchword is without a doubt amend. THIS communication is made conceivable by a UI.

For what reason do I think Java UI is powerless?

I have two principle reasons why I loathe Java UI when all is said in done:
1.      It's not beautiful
2.      It's confounding
I understand these two reasons aren't the most convincing explanations behind loathing everything Java UI, however it was UI Courses in Bangalore sufficiently convincing for me and each one of my College software engineering companions to utilize something different! Furthermore all things considered, most applications you use once a day are NOT utilizing Java UI… that is on the grounds that they're either web applications (like Facebook or Kijiji) or simply based on some different items (like Visual Studio).

What UI would it be a good idea for me to utilize at that point?

Well here's the place it gets somewhat dubious. You see I am a web application designer, and subsequently I do the greater part of my work for web applications. So I am exceptionally open to utilizing the web as my Graphical UI. To do this without anyone else's help, you'll need to figure out how to utilize pages as your UI. This is the place HTML comes in!

What is HTML?

HTML remains for Hyper Content Markup Dialect, and whatever it does is characterize a dialect that enables you to converse with web programs (like Web Traveler, Google Chrome or Firefox). On the off chance that you see "how to program with HTML", at that point you can make some incredible UIs for your gathering of people… well… insofar as you're additionally great at comprehending what a decent site resembles. In case you're similar to me, most developers aren't fashioners! I may know how to code, yet to influence a site To look great may take me similarly insofar as making the majority of the usefulness for the site! 

HTML is no place close as unpredictable or troublesome as Java programming and it's substantially less demanding to begin with making your first page utilizing HTML than making your first Java program. So no stresses women and men of honor, with my direction, you could be a HTML demigod in fourteen days!

Regardless I would prefer not to begin showing HTML right now, as I need to center around Java. My objective for this blog is to in the long run develop this instructional exercise arrangement to a point where you could manufacture your own particular web application. This would mean you'll inevitably be adapting some HTML, so remain with me on this voyage folks!

What is a Java Administrator?

A Java administrator is the image that you put in the restrictive articulations of your control structures (generally). There are different cases of when you could utilize certain Java administrators, however I'll address those toward the finish of this Java instructional exercise. Along these lines, for the case over, the administrator we are utilizing is the "not as much as" administrator (<). So then you could presumably figure that there is additionally a "more noteworthy than" (>) administrator right? Right! You've likely observed me utilize it in different instructional exercises, however what else have you seen? Here's a rundown of some regular Java administrators:

Equity and Social Administrators

Operator    Description
==      Equal to
!=      Not equivalent to
>        Greater than
>=      Greater than or equivalent to
<        Less than
<=      Less than or equivalent to
These ought to appear to be genuinely straight forward to you, so I'll skip directly into the contingent Java administrator…
Math Administrators
Operator    Description
&&    Conditional-AND
+        Additive administrator (additionally utilized
for String connection)
       Subtraction administrator
*        Multiplication administrator
/        Division administrator
%       Remainder administrator
These math Java administrators are additionally truly straight-forward. You've seen that the + administrator can be utilized to add two numbers together OR to link two Strings together Subtraction, division and increase are for the most part simple, these are utilized for scientific tasks (simply like utilizing a mini-computer!). Be that as it may, one thing you haven't seen is the rest of. So what's that about?