Java Programming Language Development Computer Science Essay

Published:

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

Java is a programming language developed by Sun Microsystems. It implements a strong security model, which prevents complied Java programs from illicitly accessing resources on the system where they execute or on the network. Popular World-Wide-Web browsers, as well as some World-Wide Web servers and other systems implement Java interpreters. These are used to display interactive user interfaces, and to script behavior on these systems.

While implementation problems have opened security vulnerabilities in some Java interpreters (Java Virtual Machines or JVM's), the design of this language makes it at least theoretically possible to execute program with reasonable assurances about its Security, and in particular its ability to cause harm.

Introduction to Computer Science using Java

Java is a simple and yet powerful object oriented programming language and it in many respects similar to C++. Java originated at Sun Microsystems, Inc. in 1991. It was conceived by James Gosling, Patrick Nauhton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems, Inc. It was developed to provide a platform independent programming language.

(Introduction to Java Programming, eight edition, 2007, by Y.Daniel Liang)

Platform independent

It unlikely many other programming languages including C and C++ when Java is complied, it s not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it being run.

Java Virtual Machine

What is the Java Virtual Machine? What is its role?

Java was designed with a concept for "write once and run everywhere". Java Virtual Machine plays the central role in this concept. The JVM is environment in which Java programs execute. It is software that is implemented on top of real hardware and operating system. When the source code (.java files) is complied, it is translated into byte codes and then placed into (.class) files. The JVM executes these byte codes. So Java byte codes can be through of as the machine language of the JVM. A JVM executes these byte codes. So Java byte codes can be through of as the machine language of the JVM. A JVM can either interpret the byte code one instruction at a time or the byte code can be complied further for the real microprocessor using what is called a just-in-time compiler. The JVM must be implemented on a particular platform before compiled programs can run on that platform.

Object Oriented Programming

Since java in an object oriented programming language it has following features:

Reusability of code

Emphasis on data rather than procedure

Data in hidden and cannot be accessed by external functions

Object can communicate with each other through functions

New data and functions can be easily added Java has powerful features. The following are some of them:

Simple

Reusable

Portable (Platform Independent)

Distributed

Robust

Secure

High Performance

Dynamic

Threaded

Interpreted

Object Oriented Programming is a method of implementation in which programs are organized as cooperative collection of objects, each of which represents an instance of a class, and whose classes are all remembers of a hierarchy of classes united via inheritance relationships.

(Object-Oriented Programming: From Problem solving to Java, 1st edition, 2003, by Garrido,Jose. Ebrary Olympia College. )

OOP Concepts

Four principles of Object Oriented Programming are:

Abstraction

Abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of objects and thus provide crisply defined conceptual boundaries, relative to perspective of the viewer.

Encapsulation

Encapsulation is the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior and encapsulation serves to separate the contractual interface of an abstraction and its implementation.

Inheritance

Inheritance is the process by which one object acquires the properties of another object.

Polymorphism

Polymorphism is the existence of the classes or methods in different forms or single name denoting different implementations.

Java is Distributed

It with extensive set of routines to handle TCP/IP protocols like HTTP and FTP java can open and access the objects across net via URLs.

Java is Multithreaded

The one of the powerful aspects of the Java language is that it allow multiple threads of execution to run concurrently within the same program. A single java program can have many different threads executing independently and continuously. Multiple Java applets can run on the browser at the same time sharing the CPU time.

Java is Secure

Java was designed to allow secure execution of code across network. To make Java secure many of the features of C and C++ were eliminated. Java does not use Pointers. Java programs cannot access arbitrary addresses in memory.

Garbage collection

Automatic garbage collection is another great feature of Java with which it prevents inadvertent corruption of memory. Similar to C+, Java has a new operator to allocate memory on the heap for a new object. But it does not use delete operator to free the memory as it is done in C++ to free the memory if the object is no longer needed. It is done automatically with garbage collector.

Java Applications

Java has evolved from a simple language providing interactive dynamic content for web pages to a predominant enterprise-enabled programming language suitable for developing significant and critical applications. It is used for many types of applications including Web based applications, Financial applications, Gaming applications, embedded systems, distributed enterprise applications, mobile applications, Image processors, desktop applications and many more.

(Java Programming, 6th edition, 2011, by Cengage South-Western.)

Define Question 1

Method overloading is Java allows you to have multiple methods having the same name, as long as each method accepts different sets of argument types. In other words, in our example, it is legal to have these two methods in the same class.

public String printString(String string)

public String printSrting(String string , int offset)

This technique is called method overloading. The return value of the method is not taken into consideration. As such, these two methods must not exist in the same class:

public int countRows (int number);

public String countRows (int number);

(Java Programming, 6th edition, 2011, by Cengage South-Western.)

Method Overloading is methods of the same name can be declared in the same class, as long as they have different sets of parameter.

This is called "Method Overloading".

Method overloading is commonly used to create several method with the same name that perform the same and similar tasks.

Using the Method Overloading

Public class MainClass {

Public void print (int a){

System.out.println (a);

}

Public void print (String a ) {

System.out.println (a);

}

{A method's name with the types and sequence of the parameters form the method's signature.

(Java Programming,the easy way,1st edition,1999, by Robert.)

Answer for Question 1

Method Overloading

Method overloading results when two or more methods in the same class have the same name but different parameters. Methods with the same name must differ in their types or number of parameters. This allows the compiler to match parameters and choose the correct method when a number of choices exist. Changing just the return type is not enough to overload a method, and will be a compile-time error. They must have a different signature. When no method matching the input parameters is found, the compiler attempts to convert the input parameters to types of greater precision. A match may then be found without error. At compile time, the right implementation is chosen based on the signature of the method call.

Below is an example of a class Method Overloading.

public class overloading {

public static void main ( String [] args)

{

System.out.println ("Square of integer 7 is:" + square (7));

System.out.println ("Square of double 7.5 is:" +square(7.5));

}

public static int square (int num1)

{

System.out.println ("Called square with int: "+ num1);

return num1*num1;

}

public static double square (double num2)

{

System.out.println("Called square with double:"+num2);

return num2*num2;

}

}

(Miss Liza notes, 2010, Java Programming, Method Overloading)

Output

--------------------Configuration: <Default>--------------------

Called square with int: 7

Square of integer 7 is:49

Called square with double:7.5

Square of double 7.5 is:56.25

Process completed.

Naming conventions are an important aspect of any development project, but coming up with unique names can be somewhat tedious. One way to simplify the chore is to reuse method names via overloading. Overloading is the ability to have a class that has multiple methods with the same name that are differentiated by the number and type of arguments passed into the method.

What's in a name?

When assigning names to classes, methods, and member variables, it is important to use names that are easy to understand. For example, creating a class for defining a overloading would lead to an appropriate class name of overloading. Calling it a gibberish name like abcd would be valid Java code but absolutely nonsense to any programmer working on the system in the future. The overloading class has the following designation:

public class overloading {

public static void main ( String [] args)

{

System.out.println ("Square of integer 7 is:" + square (7));

System.out.println ("Square of double 7.5 is:" +square(7.5));

}

The code listing declares a class called overloading, with two member variables of square. The names assigned to the member variables are analogous to their use, so it is easy to identify what type of data is stored in them. When developing the overloading class, we need to populate these member variables when the object is created.

Object construction

Creating a new object instance triggers the class's constructor method. The following code utilizes a basic constructor that accepts no arguments:

public static int square (int num1)

{

System.out.println ("Called square with int: "+ num1);

return num1*num1;

}

The basic constructor initializes the member variables with empty strings. Upon further investigation, it is discovered that often the objects are created with known names but sometimes only the last name. You can use method overloading to create multiple method versions, but each has its own method signature. The signature defines what parameters are accepted by the method. For example, here's the method signature for the previous constructor:

public static double square (double num2)

{

System.out.println("Called square with double:"+num2);

return num2*num2;

}

}

This method can be overloaded to accommodate first and last names or only the last name:

These two print methods output the member variables, with one method accepting text to prepend to the output and the other not.

Overloading is a powerful feature, but you should use it only as needed. Use it when you actually do need multiple methods with different parameters, but the methods do the same thing. That is, don't use overloading if the multiple methods perform different tasks. This approach will only confuse other developers who get a peek at your code.

Define Question 2

Java loop

A programming loop is a control structure that allows a programmer to execute the same instruction or group of instructions over and over until some condition is met. All loops have a basic structure to them, though there are many types:

The loop entry is the point at which the program's control enters the loop and begins executing the first instructions.

The loop test at the beginning of the loop takes over the program control and determines whether the loop can begin, repeat, or skip to the commands after the loop.

The iteration is a single cycle made through to loop, i.e. if the computer executes the loop 12 times the loop has 12 iterations.

The termination condition is whatever is built in to the loop to cause the looping to stop. The program control exits the loop and continues exiting whatever commands come after.

There are three main categories of control flow statements;

Selection statements: if, if-else and switch.

Loop statements: while, do-while and for.

Transfer statements: break, continue, return, try-catch-finally and assert.

Answer for Question 2

/**

* @(#)examplefor.java

*

*

* @author

* @version 1.00 2011/3/30

*/

public class examplefor{

public static void main (String[]args)

{

int num=5;

do

{

int temp = num;

for(int i = num; i>1; i--)

{

temp = temp*10+num;

}

System.out.println(temp);

num--;

}

while (num>0);

}

}

--------------------Configuration: <Default>--------------------

55555

4444

333

22

1

Process completed.

Conclusion & Recommendation

Method Overloading

In a class, the concept of method overloading does not allow the external user to be aware about the internal processing of the system

-- It just allows to user to use the different implementations of same name collected together and react appropriately to the supplied parameters to get the desired output.

-- Method Overloading, allows the user to achieve the compile time polymorphism.

-- Overloaded methods are always the part of the same class. These methods have the same name, but they may take different input parameters.

-- The arguments passed to a overloaded method may differ in type or in number, or both.

-- Overloaded methods may have the same or different return types.

Writing Services

Essay Writing
Service

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing
Service

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision
Service

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.