StudentShare
Contact Us
Sign In / Sign Up for FREE
Search
Go to advanced search...
Free

Java Programming - Research Paper Example

Cite this document
Summary
From the paper "Java Programming" it is clear that generally speaking, an interface is a group of empty method definitions and constant variables that are mandatory for a collection of classes that implements them. It acts as a standard for these classes…
Download full paper File format: .doc, available for editing
GRAB THE BEST PAPER91.9% of users find it useful
Java Programming
Read Text Preview

Extract of sample "Java Programming"

?Java Programming Access Modifiers a) Difference between public, protected and private Members (variables, methods or declared private can be accessed only by the members of the same class. Accessing a private member outside the enclosing class will result in variable declaration error. In other words, private members are strictly bound within the limits of its declaring class. Members defined with protected modifier can be accessed by classes outside the enclosing class but within the same package. However members declared protected in super class can be accessed by its subclasses, but only if they are present in same package. Members declared public have no bounds, they can be accessed from anywhere by any class irrespective of whether they are in same package or not. To sum up, the access limits of each modifier are tabulated below: Members declared as Can be accessed from members of Same Class Same Package Subclass Other Packages Public Yes Yes Yes Yes Private Yes No No No Protected Yes Yes Yes No b) Span of access Variable that are declared private/protected can be accessed outside its scope by defining set and get methods for that variable in the declaring class and calling the method from outside. However, the set and get methods must be declared public. Alternatively, we can use Reflection API which provides pre-defined methods to access private members of other classes. Still private members of super class cannot be accessed through these methods. c) Example 2. Passing Parameters to methods a) Parameter handling by methods In java, we can pass parameters of any valid data type to methods. This includes both primitive data types like integer, string, float etc and reference data types like objects and arrays. In both the cases, the data is passed only by value and not by reference, which means only a copy of the variable is sent and this will not affect the original value of the variable in the internal memory. i. Changing value of a primitive-type parameter within a method: When the value of the primitive type parameter is changed within the method, it remains in effects only within the scope of the function (method). It is not reflected to the outside world and the passed variable still contains its original value, unless until we assign this returned value to the variable. ii. Changing value of a primitive-type data field of a reference-type When the value of object fields of a reference type is changed within the method, it can be reflected in the original object’s field provided it has the proper access level. However, the reference variable will still point to the same object. iii. Reassigning the reference of a reference-type parameter to a new object that you create within a method In this case, the reference variable will point to the new object. b) Example In the above example, only the fields modified inside the method is reflected outside in the reference variable. The actual reference object is not modified outside when it is assigned a new object inside the method. For this reason, the textObject2 is not modified. However, in the next line when the reference variable is assigned a new object returned from the method, it now points to the new object. 3. Static Modifier a) Using the modifier static on a variable A variable is declared static in order to make it accessible commonly among all the instances of a class. In other words, the actual variable can be directly accessed and modified from any objects/instance of a class, just like a common shared folder in a network system. This type of variable is frequently employed in situation where every instances of a class require a common variable to update or retrieve certain information which is common to all users of the application. For example, retrieving or updating the most frequently viewed products in an online shopping application. Further, static variables are employed in combination with public and final keyword to store values that remain constant throughout the application. For example a variable PI can be declared public static final PI=3.14. Static variables can be directly accessed by using the class name and it is not mandatory to use an instance/object. They are accessible by both static and non-static methods. b) Using the modifier static on a method Static methods, like static variables are directly bound to the class itself and not to any instance of the class and thus can be directly accessed using the class name. However, they cannot directly access a non-static variable or non-static method without explicitly creating an object of the class. For this same reason, static methods cannot use this and super keywords as these are considered to be non-static references in java. 4. Instance Variable Instance variables are non-static variables which are defined inside the constructor of the class and copied individually to each instances of the class. In other words, if we define 3 new objects for a class, then each object would hold its own copy of the instance variable. Each instance variable can be obtained only through their containing objects. Example: 5. Hidden Variable In class hierarchy, if we do not wish to inherit any of the variables from the super class to the sub class, then we define these variables separately in the sub class with the same name. These variables are called hidden variables as variables in super class are hidden in the sub class. However, we can access the hidden variables using super keyword. For example, in the below fragment of code: Class superClass{ String text = ‘Super Class’; } Class subClass extends superClass { String text = ‘Sub Class’; } The variable text is hidden in the sub class. The hidden variable can be referred using super keyword as super.text. 6. This Keyword This keyword is the reference to the current object whose method or constructor is being called. Any member of the current object can be referred inside the instance method or constructor using this keyword. This keyword is generally used to differentiate between the local variables in the method or constructor arguments and the actual fields of the objects. For example, in the below code: Public class thisExample{ String text; Public thisExample(String text){ this.text= text;} } The text inside the constructor argument is a local variable. Inside the constructor, the actual field ‘text’ defined in the class is assigned to this local variable having the same name using this keyword. 7. Inheritance a) Extends keyword Extends is a keyword used in the declaration of a sub class to specify the name of the super class from which this sub class is to be inherited. To declare a class named subClass which is to be inherited from an already defined class named superClass, we use the following piece of code: Public subClass extends superClass { ...} b) Super keyword Super keyword is used in sub class to refer a variable in the super class. For example, in the below code: Class superClass { Public String text = ‘Super Class’; } Class subClass extends superClass { String text = ‘Sub Class’; String text1=super.text; } The keyword super prefixed to the variable text refers to the variable text in the super class. c) Implication of using private modifier Variables in super class that are declared private are not inherited in the sub class. 8. Method Overriding/Overloading a) Method Overriding In a class hierarchy, when the sub class declared a method with the same name as its super class with same type signature, then the sub class is said to override the method in the super class. When the method is invoked in the sub class, it always points to the method in the sub class and the method with the same name in the super class is hidden. b) Method Overloading In java, we can define more than one method with the same name within the same class, as far as they are defined with different set of parameters in their arguments. This process of using the same method (name) to accept different types and different numbers of parameters is called method overloading and this concept is referred to as polymorphism. When an overloaded method is called in the program, java identifies which version of the method to invoke using the type and/or number of parameters passed to the method. c) Example 9. Final Modifier a) Final modifier on variables Variables that are declared using the final modifier can be assigned a value only once. These types of variables are used only for storing values that remains constant throughout the application. Final variables are either assigned a value during declaration or forced to assign inside the constructor. Once assigned a value, it can never be changed. Example: Public class finalExample{ Public static final double PI =3.14; //final variable Public double findArea (double x){ double area = PI *x*x; return area; }} b) Final modifier on methods Methods that are declared final cannot be overridden. Example: Public class finalExample{ Public static final double PI =3.14; //final variable Public final double findArea (double x){//final method double area = PI *x*x; return area; }} c) Final modifier on classes Classes that are declared final cannot be extended. Public final class finalExample{//final class Public static final double PI =3.14; //final variable Public double findArea (double x){ double area = PI *x*x; return area; }} 10. Abstract Class a) Definition An abstract class is one that cannot be instantiated but can be inherited or sub-classed. To mark a class as abstract, we use the abstract keyword while declaring the class. When a sub class inherits from an abstract class, it should define the implementation details of all the methods present in the abstract class unless otherwise sub class is also declared as abstract. b) Example An example for explaining abstract class would be an employee record maintenance application. Employees may come under various categories depending upon their grades and designation and each category would require different number of variables and methods to store and retrieve information about the employees under them. However, every category would need certain variables and methods that are common to all employees like variables to store employee id, name, address, designation, contact number, etc and methods to retrieve them. In this case, we can group all these common variables and methods in an abstract class and extend it in each class that are specific to each category. A fragment of code that can be employed in such application is shown below: 11. Interface/Implements a) Use of Interface An interface is a group of empty method definitions and constant variables that are mandatory for a collection of classes that implements them. It acts as a standard for these classes. In other words, it’s an agreement between the interface and the class that implements them that all the empty methods declared in the interface will be defined and implemented in the newly declared class. Missing out even a single method will result in compilation error. This makes sure that each class meets the required standard 100%. b) Use of Implements Implement is the keyword that is used by the class that implements an interface. Implement allows the class to adhere to the standards defined by the interface. c) Example 12. Wrapper Class a) Concept of Wrapper class In order for the primitive data types to participate in the activities reserved for objects like being added as a collection or returning from the method with object return value and to use various utility functions for different conversions, java provides the concept of wrapping. The primitive values are wrapped in an object using wrapper classes. There are wrapper classes available for all primitive data types, the name of which are almost same as that of its primitive data type names with the first letter capitalized except for char (wrapper class=character) and int (wrapper class= integer). Wrapper objects are created by either instantiating the wrapper class with the new operator or by invoking a static method on its corresponding wrapper class. Example: int num =10; Integer number = new Integer(num) // Instantiating the wrapper class Integer number1 = Integer.valueOf(num) // Invoking the static method on the wrapper class Read More
Cite this document
  • APA
  • MLA
  • CHICAGO
(“Java Research Paper Example | Topics and Well Written Essays - 1750 words”, n.d.)
Retrieved from https://studentshare.org/other/1395610-java
(Java Research Paper Example | Topics and Well Written Essays - 1750 Words)
https://studentshare.org/other/1395610-java.
“Java Research Paper Example | Topics and Well Written Essays - 1750 Words”, n.d. https://studentshare.org/other/1395610-java.
  • Cited: 0 times

CHECK THESE SAMPLES OF Java Programming

Information Security Implications of Using Java and AJAX

Basically, the Java Programming language encompasses its own exclusive set of safety and privacy aspects and challenges.... In this scenario, the Java Programming language and virtual machine offer a number of characteristics to ease and support common software programming issues and problems.... Also, the Java Programming and associated applications ensure illegal state at the initial opportunity.... This paper "Information Security Implications of Using Java and AJAX" analyses major aspects of Java and Ajax programming languages, information security implications of using Java and AJAX, major security-based issues that are governed by Java and Ajax programming platforms....
10 Pages (2500 words) Case Study

The Role of Interfaces in GUI Applications

These applications are written with the use of Java Programming language and as a result they are supportive of internet applications and online communications through the World Wide Web (Liqiong & Poole, 2010).... Practical application of GUI includes their significant role in solving problems in computing and the generation, design and development of programs during the processes of programming.... Mozilla is one of the common and an effective example of a software application with a GUI that supports java based application and enhances the speed and efficiency of user interaction with computer systems and World Wide Web....
4 Pages (1000 words) Research Paper

Popularity of Java Programming Language

Popularity of Java Name Institution Popularity of Java Over years, Java Programming language has had a steady growth as a popular development language.... This implies that Java Programming give developers that assurance that their software will handle memory efficiency and avoid runtime errors that could crash the application.... As compared to other programming languages like C#, PHP, Perl, Python or C++, Java has a significant following given that many developers prefer using this programming language to complete their projects....
4 Pages (1000 words) Research Paper

Java programming and written exercises

tring[] strArr = {"Java", "programming", "if", "array","LinkedList", "queue", "iterator"};LinkedList myList = new LinkedList();private int i;for(i=0;i 5) { Insert(string strArr[i], LinkedListIterator p);}}public voidinsert(stringx,LinkedListIteratorp){ if(p!... The following program provides the partial java code for the class Account declaration.... Part of the java code has been provided as below.... Write a java code segment that uses the LinkedList myList and the String array strArr....
3 Pages (750 words) Essay

Introduction to Java Programming

The first row in the library class diagram contains the java Program: Library Application (Section) Due) Introduction It involves the development of a library application which forms part of an upgrade initiative with two main users as the borrowers and the employee with employees interacting with the application more than the borrowers....
2 Pages (500 words) Research Paper

Object Oriented Programming

Java Programming.... This is in marked contrast to procedural programming where program flow is given the central focus.... In object –oriented programming, the.... Finally, the system behavior is modeled after the interactions of these data items of the of the of the Object Oriented programming Object oriented programming is a programming methodology, where data and its interactions are of central focus rather than processes....
1 Pages (250 words) Essay

History of Java / History of CPU Speed (clock rate)

The Java Programming language was started in the early 90's by a team led by James Gosling at Sun Microsystems as a means to implement virtual machination as an improvement of C++.... , and is used in different machines and applications, especially over Internet Java Programming The Java Programming language was started in the early 90's by a team led by James Gosling at Sun Microsystems as a means to implement virtual machination as an improvement of C++....
1 Pages (250 words) Essay

The Operation of Java Applications in the Context of Operating Systems

n the Java Programming source code language, every source code is first written at the end with the '.... Java' is a programming language that developers utilize to build applications on computers.... This term paper "The Operation of java Applications in the Context of Operating Systems" evaluates the operations of java applications in the context of computer hardware and operating systems with a special focus on the various features and capabilities of java....
6 Pages (1500 words) Term Paper
sponsored ads
We use cookies to create the best experience for you. Keep on browsing if you are OK with that, or find out how to manage cookies.
Contact Us