0% found this document useful (0 votes)
4 views16 pages

Java Assingment

The document is an assignment submission by Tashinga Ncube for the Programming in Java course at the University of Edenberg, detailing the history and evolution of Java, its development kit, and programming concepts. It covers Java's milestones from its inception in the 1990s to recent updates, as well as fundamental programming structures, data types, operators, control flow, and object-oriented principles like encapsulation, inheritance, polymorphism, and abstraction. The assignment includes code examples illustrating these concepts and references for further reading.

Uploaded by

lindapaul281010
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views16 pages

Java Assingment

The document is an assignment submission by Tashinga Ncube for the Programming in Java course at the University of Edenberg, detailing the history and evolution of Java, its development kit, and programming concepts. It covers Java's milestones from its inception in the 1990s to recent updates, as well as fundamental programming structures, data types, operators, control flow, and object-oriented principles like encapsulation, inheritance, polymorphism, and abstraction. The assignment includes code examples illustrating these concepts and references for further reading.

Uploaded by

lindapaul281010
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIVERSITY OF EDENBERG

SCHOOL OF COMPUTER SCIENCE & INFORMATION


TECHNOLOGY
BACHELOR OF (SC) (AI&ML&DS) (CS&DF)

SUBMISSION OF ASSIGNMENT

STUDENT NAME Tashinga Ncube

STUDENT NUMBER 20250137

COURSE NAME Programming In Java

COURSE CODE 501CSE231

ASSIGNMENT TITLE

ASSIGNMENT NO 1

YEAR OF STUDY 2026

SEMESTER NO 1

LECTURERS NAME Ms. Briskilla

TOTAL ASSIGNMENT MARKS

TOTAL ASSIGNMENT MARKS SCORED

(OFFICIAL USE ONLY)


Question 1

JAVA, which is one of the most popular programming language was developed by
James Gosling and his team at Sun Microsystems around 1990s. Before it came to be
named Java, it was first called “Green”, then changed to “Oak” , there were also other
suggestions that they favored like “Lyric and “Silk” but after the Indonesian coffee
bean, they settled on the official name which we know today as Java.

Evolution of Java
The History of Java is filled with important breakthrough and milestones that helped
it from just a tool for smart devices to becoming one of the best and powerful
programming languages. It was purposefully built to be robust, portable ,
independent , high performance and multithreading capabilities. Some of the most
defining moments in the evolution of Java:

1991 - 1994 The green project begins


 Project initiated as the Green Project by Microsystems
 Oak was developed as the first prototype
 Renamed to Java to avoid trademark issues, the team saw great potential in the
project and focused more on creating a language for web-based applications.

1995 introduction of Java


 Java was officially released to the public with the slogan “ Write Once, Run
Anywhere”.
1997 Java Becomes a standard
 Java was recognized by ISO and ANSI as a standard, which increased its
adoption by developers and enterprises worldwide

1999 Introduction of Java 2 Platform


 Java was then split into three editions:
 J2SE (Standard Edition) for desktop apps
 J2EE (Enterprise Edition) for server side applications
 J2ME (Micro Edition) for mobile and embedded systems

2004 Java 5 and Major Enhancements


 J2SE 5.0 came with a game changing features like generics, enhanced for-loop,
annotations.
 Generics allowed for stronger type checks at compile time
 Enhanced for-loops, provided a simpler more readable way to iterate over
collections and arrays included.
 Annotations provided metadata for the java code, enabling code documentation
and integration with tools and frameworks.

2006 - 2009 Open Source and Acquisition


 Sun Microsystems made Java open source by releasing the Open Java
Development Kit (OpenJDK)
 Oracle took over the development and continued to support Java’s open-source
nature in 2009

2011 Java SE 7 Enhancing Readability and Efficiency


 This version introduced changes to simplify coding, like try-with-resources,
multi-catch blocks and more readable switch statements.
 These updates aimed to boost productivity, streamline development whilst still
maintaining Java’s robustness and backward compatibility.

2014 - 2017 Java 8 and Rapid Releases


 Introduction of Lambda expressions which allowed developers to write more
concise, readable code by enabling functional- style programming within Java.
 Stream API was introduced to handle sequences of data in a functional style.
 New date and Time API provided a more comprehensive and accurate approach
to working with time, replacing the old data and calender classes.
 In 2017, Java 9 was released and Oracle adopted a six-month release cycle,
accelerating the pace of Java updates. This year also marked the introduction of
the Java platform module system (referred to as Project Jigsaw) to modularize the
JDK, which helped improve, scalability and maintainability.

2021 Java 17
 With the release of Java 17, as a Long-Term Support (LTS) version, this marked
the period of stability and focused incremental improvements. It als streamlined
Java’s feature set. Which focused on security and performance enhancements and
also continued the trends toward more predictable, regular updates with long-term
reliability.

2023 Release of Java 20 and 21


 The introduction of virtual thread introduced a more efficient handling of
concurrent tasks, greatly enhanced java’s scalability and simplified the
development of multi-threaded applications.
 Enhanced performance Optimizations ensured that Java continues to meet
modern software demands focusing more on resource management and response
time improvements

Present Day and the Future of Java


Java continues to be a core part of modern software development. Thanks to its
consistent updates, strong community, and platform independence, Java has evolved
beyond just desktop apps—it now powers a wide range of technologies that shape our
digital world.[1][2][3]
Question 2

a) The Java Development Kit is responsible for the providing the core tools and the
libraries needed to compile, to run and to debug java programs, while the Integrated
Development Environment sits on top of the JDK to give an integrated, automated
environment that makes java development faster and more productive.[4][5]

The Role of Java in Java Development.[4][5][6]


 This kit is the an integral component in the development, running and the testing
of all java applications and applets.
 It is responsible for compiling the source code into platform independent
bytecode that can run on any standard java virtual machine, enabling the write
once, run anywhere portability.
 It bundles the java compiler, the java virtual machine and the key utilities such as
the debugger, disassembler and the packaging tools.
The Role of Integrated Development Environments[7][8]
 This is an application that combines a code editor, build and compile tools and
the debugger to help developers write, compile and debug code efficiently.
 IDEs provide a graphical configuration interface which is user friendly for those
who are not keen on using the the manual command line interface
 They improve the overall productivity of programming or coding through
features like syntax highlighting, code completion, intelligent navigation and
refactoring tools among other features.

b)

// 1. Package declaration
package myfirstprogram;

// 2. Import statement
import [Link].*;

// 3. Class definition
public class HelloWorld {

// 4. Main method – entry point


public static void main(String[] args) {

// 5. Statement
[Link]("Hello, World!");
}
}

The structure of every java program is usually well-defined, which ensures clarity,
maintainability and proper flow. Included in the structure is:

1. Package declaration - this defines the namespace of the class though this is
optional
2. Import statements - also optional, allows the use of classes form other packages
3. Class Definitions - It is a must that every Java program should at least have one
class
4. Main Method - This is where the program starts the execution, mandatory
5. Statement - This is the code inside the main method that performs the actions.

Question 3

a) Java’s primitive data types are predefined by the language and serve as the
building blocks for data manipulation and these are:[9][10]

1. Boolean - Used for simple flags that tack true/false conditions. Holds only two
possible values True or either False
2. Byte - An 8-bit signed integer with a range from - 128 to 127. Useful for saving
memory in large arrays. Eg; 10
3. Int - A 32-bit signed integer which is a default choice for integers. Eg; 1000
4. Long - Used when a larger range than Int is needed. Eg; 123456789L
5. Float - A single-precision 32-bit IEEE 754 floating point used for saving memory
in large arrays of floating point numbers.
6. Double - A double-precision 64-bit IEEE 754 floating-point used for decimal
values and also a default choice for floating-point numbers. Eg; 3.14159d
7. Char - A single 16-bit Unicode character used for storing characters
8. Short - Used for saving memory in large arrays, it is a 16-bit signed integer which
ranges form -32,768 to 32,767.

b)
public class OperatorsDemo {
public static void main(String[] args) {
// Declare two integer variables
int x = 8;
int y = 4;

// Arithmetic Operators, + adds two numbers


[Link]("Addition: " + (x + y));
// * multiplies two numbers
[Link]("Multiplication: " + (x * y));

// Relational Operators, > checks if x is greater than y


[Link]("x > y: " + (x > y));

// == checks if x is equal to y
[Link]("x == y: " + (x == y));

// Logical Operators, && checks if both conditions are true


boolean result = (x > y) && (y > 0);

// Display the logical result


[Link]("Logical AND result: " + result);
}
}

Question 4

a) These are what determines the flow of statements in programming.

1. If-else - is used for decision making when executing different code blocks based
on certain conditions. All conditions are evaluated sequentially, it works well
with boolean expressions and can handle other complex conditions using logical
operators.

Example:
// runs if condition is true
if (condition) {

// runs if first is false and this is true

} else if (otherCondition) {
// runs if all above are false
} else {
}

2. Switch-case - Used for multi-way branching when comparing a single


variable/expression against multiple constant values. It works best with discrete
values like integers but it requires a break to prevent a fall-through in the code.

Example:
switch (variable) {
// code
case value1:
// Prevents "falling through" to the next case
break;
case value2:
// code
break;
// runs if no cases match
default:
}

3. Loop - These following statements are used to repeat a code until a certain
condition is met.
 For loop - best used when the number of iterations is known, includes the
initialization, a condition and an increment/decrement all in one line.

Example:
// repeats 10 times
for (int i = 0; i < 10; i++) {
}

 While loop - used when the number of iterations in unknown, checks the
conditions to be met before executing the code.
Example:
// runs as long as condition is true
while (condition) {
}

 Do-while - Executes the code block before checking the conditions, usually used
when the code needs to be run at least once.

Example:
// runs once, then repeats if condition is true
do {
} while (condition);

b)
import [Link];

public class SimpleCalculator {


public static void main(String[] args) {

// Create Scanner object to read user input


Scanner input = new Scanner([Link]);

// Declare variables
double num1, num2;
char operator;

// Ask the user to enter two numbers


[Link]("Enter first number: ");
num1 = [Link]();

[Link]("Enter second number: ");


num2 = [Link]();
// Ask the user to choose an operator
[Link]("Enter operator (+, -, *, /): ");
operator = [Link]().charAt(0);

// Use switch-case to perform calculation


switch (operator) {
case '+':
[Link]("Result = " + (num1 + num2));
break;

case '-':
[Link]("Result = " + (num1 - num2));
break;

case '*':
[Link]("Result = " + (num1 * num2));
break;

case '/':
if (num2 != 0)
[Link]("Result = " + (num1 / num2));
else
[Link]("Error: Division by zero is not allowed.");
break;

default:
[Link]("Invalid operator.");
}

// Close the scanner


[Link]();
}
}
Question 5

a) Encapsulation is the practice of wrapping data and methods into a single unit which
restricts direct access to some of the components. This is achieved by using access
modifiers (private, public, protected) to restrict access to class members and by also
providing public getter and setter methods to interact with the private fields. [11]

Example:
class BankAccount {
// Encapsulated field
private double balance;

public BankAccount(double initialBalance) {


[Link] = initialBalance;
}

// Getter
public double getBalance() {
return balance;
}

// Controlled access
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
}
}
}

Inheritance is a mechanism that allows one class (child or subclass) to inherit


properties and behaviors (fields and methods) from another class (parent or superclass)
allowing for code reusability .

Example:
class Animal {
public void eat() {
[Link]("This animal eats food.");
}
}

class Dog extends Animal {


public void bark() {
[Link]("Dog barks.");
}
}

Polymorphism offers the ability to objects to take many forms, it does this in two
main ways, method overloading and the other method overriding. Method overloading
is resolved at compile-time while method overriding is resolved at runtime using
dynamic method dispatch. Polymorphism allows for flexible and scalable coding as
object can be treated more generically, whilst utilizing the correct specific behaviour
at run-time.

Example:
class Animal {
public void sound() {
[Link]("Animal makes a sound");
}
}
class Dog extends Animal {
@Override
public void sound() {
[Link]("Dog barks");
}
}
class Cat extends Animal {
@Override
public void sound() {
[Link]("Cat meows");
}
}

Abstraction is the principle of hiding the complexity of the system and only exposing
the necessary parts. This is achieved by using abstract classes and interfaces, which
only defines the methods but does not provide implementations.

Example:
abstract class Shape {
// Abstract method

abstract void draw(); }

class Circle extends Shape {


@Override
void draw() {
[Link]("Drawing a circle");
}
}

b) Encapsulation is implemented using access modifiers such as private, public and


protected. The variables are usually declared as private . The getter and setter methods
are provided to control access and the modification of [Link] there is inheritence
which uses the the extends keyword, allowing for subclasses to inherit properties and
methods form a superclass.

Polymorphism in java is implemented through method overloading and method


overriding. Method overriding is usually indicated using the @Override annotation
when a subclass provides its own version of a parent method. And the other concept
in java is abstraction which uses the keywords, abstract to declare the classes and the
methods, interface keyword which defines a contract that classes must implement
using also another keyword which is implement.[11]
References

[1] GeeksforGeeks, "The Complete History of Java Programming Language,"


GeeksforGeeks. [Link]
programming-language (accessed Mar. 10, 2026).

[2] WsCube Tech, "Full History of Java Programming Language (1991–2026),"


WsCube Tech. [Link] (accessed Mar. 10,
2026).

[3] Unstop, "History Of Java | Complete Timeline + Infographic & Versions," Unstop.
[Link] (accessed Mar. 10, 2026).

[4] IBM, "Java Development Kit," IBM Documentation.


[Link] (accessed
Mar. 11, 2026).

[5] [Link], "What role does the Java Development Kit (JDK) play in Java
development?," [Link]. [Link]
development-kit-jdk-play-in-java-development (accessed Mar. 11, 2026).

[6] TechTarget, "What is Java Development Kit (JDK)? | Definition," TechTarget.


[Link] (accessed Mar.
11, 2026).

[7] Qodo, "Advantages of IDE: How Does It Enable Faster Development," Qodo.
[Link]
(accessed Mar. 11, 2026).

[8] SonarSource, "What is an IDE? Definition Guide & Benefits," Sonar.


[Link] (accessed Mar. 11, 2026).
[9] Oracle, "Primitive Data Types (The Java™ Tutorials > Learning the Java
Language > Language Basics)," Oracle Documentation.
[Link] (accessed
Mar. 11, 2026).

[10] GeeksforGeeks, "Java Data Types," GeeksforGeeks.


[Link] (accessed Mar. 11, 2026).

[11] NextGenML, "OOP principles: Inheritance, Encapsulation, Polymorphism, and


Abstraction," Medium, Oct. 18, 2024. [Link]
principles-inheritance-encapsulation-polymorphism-and-abstraction-607d8e73e9c5
(accessed Mar. 11, 2026).

You might also like