Java Programing FPT University Assignment
Java Programing FPT University Assignment
Learner declaration:
I certify that the work submitted for this assignment is my own and research sources are fully acknowledged.
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.
Summative feedback:
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.
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.
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 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.
+ Error handling mechanism to help the handling and error recovery easier.
Security:
+ 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.
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:
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:
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.
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.
+ 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.
+ One-dimensional array
+ Multidimensional arrays
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.
+ The following constructor takes the file name as a string to create an Input Stream object to read the
file:
+ 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:
+ 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
+ Execute code
The JVM provides definitions for: memory area, class file format, registry settings, garbage collector
heap, and fatal error messages.
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.