0% found this document useful (0 votes)
4 views

Assessment1_SadipNeupane

The document provides a comprehensive overview of Java, covering its introduction, history, principles, versions, and editions. It details the Java environment, including the installation and configuration of the JDK and IDEs like Eclipse, as well as fundamental programming concepts such as data types, operators, and comments. Additionally, it includes guidelines for structuring Java programs and managing projects within Eclipse.

Uploaded by

Sadip Neupane
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 views

Assessment1_SadipNeupane

The document provides a comprehensive overview of Java, covering its introduction, history, principles, versions, and editions. It details the Java environment, including the installation and configuration of the JDK and IDEs like Eclipse, as well as fundamental programming concepts such as data types, operators, and comments. Additionally, it includes guidelines for structuring Java programs and managing projects within Eclipse.

Uploaded by

Sadip Neupane
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
You are on page 1/ 14

Contents

1. Introduction to Java .................................................................................................................................. 1


2. History of Java ........................................................................................................................................... 1
3. Principles of Java ....................................................................................................................................... 2
4. Versions of Java ......................................................................................................................................... 2
5. Editions of Java .......................................................................................................................................... 3
6. Environment of Java .................................................................................................................................. 3
7. Download, Installation, and Configuration of JDK .................................................................................... 4
8. Structure of Java Program ......................................................................................................................... 4
9. Hello World of Java ................................................................................................................................... 5
10. Download, Install, and Configure Java IDE (Eclipse)................................................................................ 5
11. Project Management in Eclipse............................................................................................................... 6
12. Package Management in Eclipse ............................................................................................................. 6
13. Class Management in Eclipse .................................................................................................................. 6
14. Character Set of Java ............................................................................................................................... 7
15. Keywords of Java ..................................................................................................................................... 7
16. Identifiers ................................................................................................................................................ 8
17. Data Types ............................................................................................................................................... 9
18. Operators, Precedence, and Associativity............................................................................................. 10
19. Expression and Statements ................................................................................................................... 11
20. Comments ............................................................................................................................................. 12
Works Cited ................................................................................................................................................. 13
1. Introduction to Java
Java is a high-level, object-oriented programming language that is designed to be
platform independent. It allows developers to write code once and run it anywhere,
thanks to the Java Virtual Machine (JVM).
Key Features:
• Object-Oriented: Supports concepts like encapsulation, inheritance, and
polymorphism.
• Platform Independence: Java code is compiled into bytecode, which can be
executed on any device with a JVM.
• Rich API: Java provides a comprehensive set of libraries and frameworks for
various applications.
• Automatic Memory Management: Java includes garbage collection, which
automatically manages memory allocation and deallocation.

2. History of Java
• Origins: Java was developed by Sun Microsystems in the early 1990s. The project was
initiated by a small team known as the Green Team, led by James Gosling.
• Initial Purpose: Originally designed for interactive television, Java was too advanced for
the digital cable television industry at the time.
Name Evolution:
• Initially called "Greentalk" then renamed "Oak" after the oak tree, a symbol of
strength.
• Finally renamed "Java" in 1995 due to trademark issues with Oak Technologies.
The name was inspired by Java coffee, which the team enjoyed.
• Release: Java was officially released in 1995 and quickly gained popularity, especially for
web development. (Anon., n.d.)

1
3. Principles of Java
Java was designed with several core principles in mind:
• Simple: Java's syntax is easy to learn and understand, making it accessible for beginners.
• Robust: Java emphasizes strong memory management and error handling, reducing the
likelihood of crashes.
• Portable: Java programs can run on any device with a JVM, making it highly portable.
• Platform-Independent: The "Write Once, Run Anywhere" (WORA) philosophy allows
Java applications to be executed on any platform without modification.
• Secure: Java provides a secure environment through its classloader and bytecode
verifier, which help prevent unauthorized access and code execution.
• High Performance: Java uses Just-In-Time (JIT) compilation to improve performance by
converting bytecode into native machine code at runtime.
• Multithreaded: Java supports multithreading, allowing multiple threads to run
concurrently, which is essential for modern applications.
• Architecture Neutral: Java bytecode is not tied to any specific hardware architecture.
• Object-Oriented: Java is built around the concept of objects, which encapsulate data
and behavior.
• Interpreted: Java code is compiled into bytecode, which is interpreted by the JVM.
• Dynamic: Java can adapt to changing environments, allowing for dynamic loading of
classes and methods. (Anon., n.d.)

4. Versions of Java
Java has evolved through several major versions, each introducing new features and
improvements:
• Java 1.0 (1996): The first official release, which included basic features for applets and
GUI applications.
• Java 2 (1998): Introduced the Swing GUI toolkit and the Collections Framework.
• Java 5 (2004): Added generics, annotations, enumerated types, and the enhanced for
loop.

2
• Java 8 (2014): Introduced lambda expressions, the Stream API, and the new Date and
Time API.
• Java 11 (2018): A Long-Term Support (LTS) version that included new features like the
HTTP Client API and local-variable syntax for lambda parameters.
• Java 17 (2021): The latest LTS version, which includes features like sealed classes and
pattern matching for switch expressions.

5. Editions of Java
Java is available in several editions, each tailored for different types of applications:
• Java Standard Edition (SE): The core Java platform for general-purpose programming,
including libraries for GUI development, networking, and data structures.
• Java Enterprise Edition (EE): A set of specifications that extend Java SE with features for
building large-scale, distributed applications, including servlets, JSP, and EJB.
• Java Micro Edition (ME): A subset of Java SE designed for mobile and embedded
devices, providing a lightweight environment for applications.

6. Environment of Java
The Java environment consists of several key components:
• Java Development Kit (JDK): A software development kit that includes tools for
developing Java applications, such as the Java compiler (javac), the Java Runtime
Environment (JRE), and various utilities.
• Java Runtime Environment (JRE): Provides the libraries and components necessary to

3
7. Download, Installation, and Configuration of JDK
• Download: Visit the Oracle JDK download page or use OpenJDK.
• Installation:
Windows: Run the installer and follow the prompts.
macOS: Use the .dmg file to install.
Linux: Use package managers like apt or yum to install.
• Configuration:
• Set the JAVA_HOME environment variable to point to the JDK installation directory.
• Add the bin directory of the JDK to the PATH variable to run Java commands from the
command line.

8. Structure of Java Program


• Class definition: public class ClassName { ... }
• Main method: public static void main(String[] args) { ... }
• Syntax and conventions.

Simple example showcasing structure of Java Program

4
9. Hello World of Java

10. Download, Install, and Configure Java IDE (Eclipse)


Eclipse is a popular open-source IDE for Java development, offering features like code
completion, debugging, and project management.
Installation:
• Download from the Eclipse website.
• Extract the downloaded file and run the Eclipse

5
11. Project Management in Eclipse

• Open Eclipse and select File > New > Java Project.
• Enter the project name
• Click Finish to create the project.

12. Package Management in Eclipse


• Right-click on the src folder and select New > Package.
• Enter the package name
• Packages help organize classes and avoid naming conflicts.
NOTE :
The project will have src folder for source files, a bin folder for compiled bytecode, and
a lib folder for external libraries.

13. Class Management in Eclipse


• Creating and Managing Classes:
Right-click on a package and select New > Class.
Enter the class name and select options like public static void main(String[] args) to
create a main method.

6
14. Character Set of Java
• The uppercase letters 'A' through 'Z'
• The lowercase letters 'a' through 'z'
• The digits '0' through '9'
• The dash character '-'
• The plus character '+'
• The period character '.'
• The colon character ':'
• The underscore character '_'

15. Keywords of Java


• Keywords have predefined meanings in Java
• Cannot be used as identifiers.
- Examples include class, public, static, void, int, if, else, for, while, try, catch, and
many more.

7
16. Identifiers
• All Java variables must be identified with unique names. These unique names are
called identifiers.
• Identifiers can be short names (like x and y) or more descriptive names (age, sum,
totalVolume). It is preferred to have a descriptive name.

There are some soft rules for identifiers. Some are listed below:

• Names can contain letters, digits, underscores, and dollar signs


• Names must begin with a letter
• Names should start with a lowercase letter, and cannot contain whitespace
• Names can also begin with $ and _
• Names are case-sensitive ("myVar" and "myvar" are different variables)
• Reserved words (like Java keywords, such as int or boolean) cannot be used as names

Exercise
Which is NOT a legal variable name?
A.int myInteger = 20;
B.int int = 20;
C.int myNum = 20;
D.int num = 20;

8
17. Data Types
• Reference types include objects and arrays.
• They store references to the actual data rather than the data itself.
Data types include:
1. Numeric
byte bn;
short sn;
int in;
long ln;
loat fn;
double dn;

2. Non-Numeric
boolean res; //true|false
char ch; //single quote character
string strl; //Double quote character
objects obj1; //all of above

9
18. Operators, Precedence, and Associativity

Operator, Precedence and Associativity defines which operator should be taken into account
first. It is similar to the BODMAS rule we have learned in our school mathematics.

A Java operator is a special symbol that performs a certain operation on multiple operands and
gives the result as an output.
Operators can be classified as following:
-Arithmetic
- relational
- logical
-bitwise operators

Operator Precedence
Operator precedence defines the priority of operators in an expression.
For example, in the expression 3 + 4 * 5,
the multiplication operator (*) has higher precedence than the addition operator (+), so the
multiplication is performed first, resulting in 3 + 20, which equals 23.

Operator Associativity
Associativity determines the order of evaluation for operators of the same precedence level. It
can be either left-to-right or right-to-left:
• Left-to-Right: Most operators (like +, -, *, /, and &) are left associative, meaning they are
evaluated from left to right. For example, in the expression 10 - 5 + 2, it is evaluated
as (10 - 5) + 2, resulting in 7.

• Right-to-Left: Some operators (like the assignment operator = and the ternary
conditional operator ? :) are right associative. For example, in the expression a = b = 5, it
is evaluated as a = (b = 5).

(Anon., n.d.)

10
19. Expression and Statements
• A Java expression consists of variables, operators, literals, and method calls.

Here score=90 is an expression. To be more clear

• In Java, each statement is a complete unit of execution.


• In Java, expression are part of statement.

(Anon., n.d.)

11
20. Comments
comments are used to explain the code, which makes it easier to understand for anyone reading
it, including the original author.

• Single-line comments: Use // for brief comments.


• Multi-line comments: Use /* ... */ for longer comments.
• Javadoc comments: Use /** ... */ for documentation generation.

Example

(Anon., n.d.)

12
Works Cited
Anon., n.d. [Online]
Available at: https://www.programiz.com/java-programming/expressions-statements-blocks
[Accessed 19 01 2025].

Anon., n.d. [Online]


Available at: https://www.geeksforgeeks.org/operator-precedence-and-associativity-in-programming/
[Accessed 19 01 2025].

Anon., n.d. [Online]


Available at: https://www.geeksforgeeks.org/comments-in-java/
[Accessed 19 01 2025].

Michael T., Roberto T., Michael H, 2014. In: Data Structures and Algorithms in Java. s.l.:Wiley Press.

Paul D, Harvey D, (2012) Java How to Program. 9th edn. Newyork USA: Pearson

13

You might also like