You are on page 1of 26

ASSIGNMENT 1

Qualification BTEC HND Diploma in Computing and Systems Development

Unit number and title Unit 41: Programming in Java

Assignment due Assignment submitted

Learners name Assessor name T Hoi Vit

Learner declaration:
I certify that the work submitted for this assignment is my own and research sources are fully acknowledged.

Learner signature Date

Grading grid

P1.1 M3
Assignment title Assignment 1: Understand the principles of Java Programming

In this assignment, you will have opportunities to provide evidence against the following criteria.
Indicate the page numbers where the evidence can be found.

Assessment criteria Expected evidence Task Assessors Feedback


no.

LO1. Understand the principles of programming in Java

- Reasons for choice of language,


- Object models
1.1 Understand the - Data structures 1
principles of programming in - Data types
Java - Environment
- Programming Syntax
- Standards

Assessment criteria Expected Evidence Feedback


(note on Merit/Distinction if applicable)
Merit descriptor No. (M3) The communication is
appropriate for familiar and
unfamiliar audiences and
appropriate media have
been used

Summative feedback:

Assessors Signature: Date:


Preface, I want to confirm that Java is one of the powerful programming language, and is widely used
throughout the world. The Java language is a large application in software development, web pages or
mobile games. Here I will present a few typical set point of the Java programming language and the
reason why choose Java.

History developed the Java programming language:

Java was started by James Gosling and colleagues at Sun Microsystems in 1991. Java was released in
1994 and by 2010 was Oracle acquired from Sun Microsystems. And the characteristics of the Java
language.

Features of the Java programming language and the reason why choosing
Java:
Java language similar to C ++ and entirely object oriented:

To serve the purpose to run cross-platforms, Java uses the syntax of C and C ++. However, in Java to
manipulate the cursor omitted to protect the safety island and easier to use. The overload operation,
goto or structures like struct and union also been removed from Java.

Independent hardware and operating systems:

A program written in Java can run well in many different environments. Called the ability to "cross-
platform". The ability independent of hardware and operating systems are shown in 2 level is level
source code and binary levels.

+ At the level of source: data type in Java is consistent for all operating systems and different
hardware. Has its own Java library to support this issue. Programs written in Java language can compile
on different types of machines without an error.

+ In the binary level: A compiled code can run on many different platforms without compiling
source code. However need Java Virtual Machine to interpret this code.

Language interpreter:

Java programming language is the language of the interpreter. More precisely, both Java as the language
translation and interpreting.

+ Pros: This method helps code written in Java can run on many different platforms. Provided
that the JVM that supports running on this platform.
+ Cons: Like other interpreted languages, the process of running the Java code is slower than the
other compiled languages.

Mechanism of automatic garbage collection:

When creating objects in Java, JRE automatically allocates memory space for the object on the heap. Java
garbage collector will trace the natural resources has been granted. When there are no references to
memory areas, garbage collection will take action to allocated memory area.

Multithread:

Java supports multi-process programming (multithread) to execute the tasks simultaneously. It also
provides solutions to synchronization between processes (solutions using priority ...).

Safety:

+ Java programming language stricter requirements on data type:

+ Data must be declared explicitly.

+ Do not use pointers and pointer arithmetic.

+ Java strictly control the access to the array, string. Not allowed to use the techniques
overflow. Therefore the access will not exceed the size of the array or string.

+ The process of allocating and freeing memory is done automatically.

+ Error handling mechanism to help the handling and error recovery easier.

Security:

Java provides an environmental management program with many different levels.

In addition to these features Java also has some other advantages:

+ Java is easy to get acquainted and learn.

+ The support tools and development languages, such as Eclipse and NetBeans.

+ A lot of websites and multi-user Java. Creating a community for exchange and learning
enormously.

+ Java is Free.

+ Excellent support materials.


Next we will learn about some of the special features of Java Object models:

OOP simplifies maintenance and software development by providing a


number of concepts:
1. Inheritance:
Inheritance in Java is a technique in which an object is obtained all the attributes and behavior of the
parent object. The idea behind the inheritance in Java is that you can create new classes that are based
on existing classes. When you inherit from an existing class, you can re-use the methods and fields of the
superclass, and you can also add additional methods and other fields. Inheritance performances parent-
child relationship.

When we talk about inheritance, keywords most often used is extends and implements. Using these
keywords, we can create an object using the properties of another object. We use the keyword extends
to subclass can inherit the properties of the superclass, unless the superclass's private property.

Advantages:

+ To override the method (Method Overriding), so can be obtained at runtime polymorphism.

+ To increase the reuse of code.

Inheritance syntax of the Java:


Next is another equally important feature of Java.

2. Polymorphism:
Polymorphism in Java is a concept from which we can perform a single action in many different ways.
Poly means many and morphs mean shape, form. There are two types of polymorphism in Java:
Polymorphism at compile time and runtime polymorphism. We can do polymorphism in Java by
overloading methods and override methods.

The important thing to know is there any way to access an object through reference variables. A
reference variable can only kind. Once declared, the type of reference variable cannot be changed.

Reference variables can be assigned to other objects are provided that are not declared final. The type of
reference variable determines the methods that can be summoned on the object.

A reference variable can be directed to any object with any kind of declaration or any subtype of the
declared type. A reference variable can be declared as a class or an interface.
Example:

Now suppose we extend Employee class as follows


Now, you study the following program carefully and try to determine its output

Output:
Next we will research about Objects,classes and methods.

3. Object,classes,methods:

4. Encapsulation:
Encapsulation in Java, is a packaging process code and data together into one unit. We can create a class
entirely in Java closures by making all data members of the class are private. Now, we use the setter and
getter methods to set and retrieve the data in it. Java Bean class is an example of how a class is
completely closed.

Advantages of Encapsulation in Java:

By providing setter or getter, you can make the class as read-only or write-only. It gives you the control
over your data.

+ All classes can have only read-only mode or recording (getter or setter functions only).

+ An entire class can have control over what is stored in its fields.
+ Users of the class do not know how the data storage class. A class can change the data type of a class
field and the user does not need a change in the code.

Data structures:
1. Attribute (or instance variable) in Java:
+ Attributes are declared in a class, but outside a method, constructor, or any block.

+ When a memory space is allocated to an object in a given heap, a slot for each attribute value is
created.

+ Properties are created when an object is created using the new keyword and is destroyed when the
object is destroyed.

+ Attributes hold values that must be referenced by more than one method, constructor or block, or key
parts of the object state that must be present throughout the class.

+ Properties can be declared in class before or after use.

+ Access specifies can be provided for attributes.

+ Attributes are visible to all methods, constructors, and blocks in the class. However, visibility for
subclasses can be provided for these variables with the use of access specifies.

+ Properties have default values. With numbers, the default value is 0, with Boolean being false and with
the object null. Values can be assigned during declaration or in constructor.

+ Properties can be accessed directly by calling variable names inside that class. However, with static
methods and different classes (when the attribute is provisioned access), it should be called by using the
fully qualified name as follows: ObjectReference.VariableName.
Rules for naming in Java
Arrays:
+ Often, an array is a collection of elements of a similar type that is adjacent to an adjacent cell. Arrays in
Java is an object that contains elements of the same data type. It is a data structure where we can store
similar elements. We can only store a fixed set of elements in an array in Java.

There are two types of arrays in Java:

+ One-dimensional array

+ Multidimensional arrays

+ One-dimensional array in Java:

You follow the simple example of a one-dimensional array. Here, we declare, initialize, initialize and
array the array.

When processing (processing) array elements, we usually use either the for loop or the for each loop
because all elements in an array are of the same type and size of known array.

Two dimensional and multidimensional arrays in Java:


Java provides a very powerful data structure package and performs many
functions:
Loops:
There may be a situation when we need to execute a block of code a few times, this can be considered as
a loop.

Conditional statements and case statements:


As with other programming languages, the Java language also supports flow control structures. With this
structure, the program checks one or more conditions, and if these conditions are true, then the
command or commands that correspond to this true condition will be executed. The false statement will
be executed.
The logical Operators:
The assignment statements:
Input and output statements:
FileInputStream in Java:
+ This stream is used to read data from files. Objects can be created using the new keyword and there
are several types of constructors available.

+ The following constructor takes the file name as a string to create an Input Stream object to read the
file:

Input Stream f = new FileInputStream("C:/java/hello");

+ The following constructor takes a File object to create an Input Stream object to read the file. We first
create a file object using the File () method as follows:

File f = new File("C:/java/hello");

InputStream f = new FileInputStream(f);

+ When we have an InputStream object, then there is a list of methods that can be used to read the
stream or to perform any other operation on the stream.
FileOutPutSteam in Java:
+ FileOutputStream is used to create a file and write data into it. This stream will create a file, if it did not
exist, before opening it to write the output.

+ Here are two constructors that can be used to create a FileOutputStream object in Java.

+ When you have this OutputStream object, the following methods can be used to record the stream or
to perform other operations on the stream:
Data types:
And Java also support some special character for escapes sequence:

Furthermore, your code can not directly generate software, all your code needs an environment to
execute. And Java has created the JVM (Java Virtual Machine)

Environment:
The JVM (short for Java Virtual Machine) is an abstract (virtual) device that can help a computer run Java
programs. It provides the runtime environment in which Java Bytecode can be executed. And what is
JVM: The JVM performs the following major tasks:

+ Download code

+ Check the code

+ Execute code

+ Provides runtime environment

The JVM provides definitions for: memory area, class file format, registry settings, garbage collector
heap, and fatal error messages.

The internal structure of the JVM:


You follow the following diagram to understand the internal structure of the JVM. It includes Classloader,
Memory Area, Excetution Engine, ...

JRE (short for Java Runtime Environment) is used to provide a runtime environment. It is a JVM
implementer. The JRE includes a set of libraries and other files that the JVM uses at runtime. The JVM
deployment is also announced by companies other than Sun Microsystems.

As specified before, framework libraries in java are an arrangement of libraries that have been outlined
by specialists. It is available in numerous information structures and calculations to stay away from
replication. Knowing how to utilize these libraries is a valuable aptitude.
There will be some rules regarding code language that you must adhere to:
Standard:
Java give a capacity that let you remark in your code to help you to recollect what you have code and
another software engineer comprehend what are you doing here. Remark admirably will evade miss
understanding.

There are three approach to make a remark in java:


To end this assignment, I will let you see how professional in coding make
the code layout and indentation:

You might also like