Overview Of Java And What It Does English Language Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

In java programming language has been designed and support concurrent programming, and all execution in the java takes place in the context of thread. It is very important to understanding java programmer the power and limits of java threads.

In the Java Virtual Machine (JVM), objects and resources can be accessed by many separate thirds; each thread has its own path of execution but can potentially access any objects in this programming.

The developer should ensure that thirds do not interfere with each other, that resources are properly synchronized during both access (read and write). The java language has built-in-constructs to support coordination.

The java platform is designed for the ground up to support programming, which basic concurrency support in the java programming language and the java class libraries. Since java 5.0 include high-level concurrency APIs. The basic concurrency support and summarizes some of the high-level APIs in the

The concurrency utilizes packages provides a powerful, extensible framework of high- performance threading utilities such as third pool and block queues.

This package frees the programmers from the need to craft these utility by hand.

The concurrency is introduced through objects of the class Thread

There is always a current thread running:

Static method Thread. Current Thread ()

The start () method is used for create a new thread of control to execute the thread object's run () method.

Concurrent Collections:

The concurrent collections allow multiple operations to overlap each other

Big performance advantage

At the cost of some slight differences in semantics

Might not support atomic operations

Concurrent HashMap

Concurrent (scalable) replacement for hashtable or collections.synchronizedmap

Allow reads to overlap each other

Allow reads to overlap writes

Allows up to 16 writes to overlap

Lterator don't throw

Concurrent Modification Exception

Copy On Write Array List:

Optimized for case where iteration is much more frequent than insertion removal

Ideal for even listing

The most using packages in java concurrent programming, they are:

java.util.concurrent Packages

java.util.concurrent.atomic Package

java.util.concurrent.locks Package

java.util.concurrent Packages description:

Utility classes commonly useful in concurrent programming. This package includes a few small standardized extensible frameworks, as well as some classes that provide useful functionality and are otherwise tedious or difficult to implement. Used for The general purpose toolkit for development concurrent applications.

java.util.concurrent.atomic Package description

java.util.concurrent.locks Package description:

Interface and classes providing a framework for locking and waiting for conditions that is distinct from built-in synchronization and monitors. The framework permits much greater flexibility in the use of locks and conditions, at the expense of more awkward syntax.

Use of monitor synchronization is just fine for most application, but it has some shortcomings

Single wait set per lock

No way to interrupt or time out when waiting for a lock

Locking must be block structured

Inconverient to acquire a variable number of locks at once

Advanced techniques, such as hand over hand locking are not possible

Lock objects address these limitations

But harder to use: need finally block to ensure release

So if you don't need them stick with synchronized

Second question answer:

import java.io.IOException;

import java.io.PrintStream;

import java.util.Date;

import java.util.concurrent.Executors;

import java.util.concurrent.ScheduledExecutorServices;

import java.util.concurrent.ScheduledFurtur;

import static java.util.concurrent.TimeUnit.*;

public class MyThreads {

public static void main(String [] arguments)


MyThreads mt = new MyThreads ( arguments);


public MyThreads(String[] arguments)


PrimeFinder[] finder = new PrimeFinder [arguments.length];

for(int i=0; i<arguments.lenght; i++)




long count = Long.parseLong(arguments[i]);

finder[i] = new PrimeFinder(count);

System.out.println(" find the prime" + count);


catch (NumberFormatException nfe)


System.out.println("Error: " + nfe.getMessage());



bollean complete = false;

while (!complete)


complete = true;

for ((int j-0; j<finder.length; j++ )


if (finder[j] == null) continu;

if (!finder[j].finished)


complete = false;




displayResult(finder [j]);

finder[j] =null;







catch (InterruptedException ie)

{ // nothing here




private void displayResult(PrimeFinder findr)


System.out.println ("Prime" + finder.target + "is" + finder.prime);



Program Expiation:

The My Threads program can be use for find one or more prime numbers in sequence.

Specify the prime numbers that you're looking for as command line arguments and include as many as you want.

The program can run the application:

Expected output is java My threads 1 10 100 1000.

In this program the first for loop is used for the My Threads application creates one Prime Finder object for ease command line argument specified when the program is run.

The arguments are Strings and the Prime Finder constructor requires long values, the Long.parseLong (String) class method is used for handle the conversion. All the number parsing methods throw NumberFormatException exception, so they are enclosed in try catch blocks to deal with arguments that are not numeric.

When a Prime Finder object is create, the object starts running in it's own thread.

In the program the whiles loop check to see whether any prime finder thread has completed. Which is indicated by its finished instance variable equaling true? When a thread has completed, the display result() method is called to display the prime number that was found. The thread then is set to null, freeing the object for garbage collection.

The call to thradmin_setupead. Sleep (2000) in the program causes the while loop to pause for 2 seconds during each pass through the loop. A slowdown in loops helps keep the java interpreter from executing statement at such a furious pace that it becomes bogged down.

Stopping a thread:

Stopping a thread is a little more complicated than starting one. The thread class includes a stop () method that can be called to stop a thread, but it creates instabilities in java runtime environment and can introduce hard to detect errors into a program. For this reason the method has been deprecated, indicating that it should not be used in favor of another technique.

the try and catch block are used in this program for requires two things.

first one is protect the code that contains the method that might throw an exception inside a try block.

the second one is deal with an exception inside a catch block.

what try and catch effectively means is: "try this bit of code that might cause an exception. if it executes okay, go on with the program. if the code does not execute, catch the exception and deal with it."

Key words in this program:


It is one of reserved key word I java, which is used to import the other classes where this class is using. Using import we can import any no of classes and you can use all the classes.


Class is also reserved key word in java, is one type in java with this we can define a class and we can create object, where a object can state and behavior .state is nothing but member variables and behavior is methods.


New is also one reserved key word in java, using this new we can create object for any class which is non-abstract class, after creating the new object for a class we can access all the instance variables and instance methods. We cannot access instance variables and instance methods without creating object for the class. When we create object for the class the default constructor will be invoked of that class. If you write the default zero parameterized constructors for a class the JVM will not provide you the default constructor. If you don't write any constructor in your class, the jvm will provide you the default constructor as a zero parameterized constructor.


Public is the one the access modifiers in java, the other access modifiers are Private, protected. Public access modifiers can be applicable to class, member variables and methods. if use public for a class, that class can be used anywhere in the application. Public gives universal access to all the resources that are in the application. If you are writing the public to the methods those methods can be access in all other classes, where this class has used.


Private is another access modifiers. Private can be applied to only to methods and variables we cannot write for a class. For a class we can write only one access modifier i.e., public, the other one is by not writing any one (public, private, protected), it is a default access. If you write private to the member variables and to the methods tey can be accessible with in that class only, we cannot access outside the class.


Static is non-access modifiers in java, we can write this static to member variables, methods. By writing the static to the member variables, methods will get access without creating any object to that class, means if we have static things declared in class, to access that static thing s we no need to create object for that class. The static things will load along with the class, so the decision about the static things will be taken at compile time. The instance things decision will be taken at runtime.

Main: the main is the main method name, if class is having the main method then that class is said to be executable class.

Void: void means the main method doesn't return anything. The main method itself is static method so all the static things can directly use in the main method.