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

Java Week1a

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

Java Week1a

Java programming language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

COURSE: INF217D

PROGRAMMING AND PROBLEM SOLVING


ANALYSIS-C++
Lecture I

Prepared by Linda Otoo


OUTLINE
• Introduction
• Basics to Computer programming
• Overview of programming languages and
Paradigms
• What is Java
• Features of Java
• Uses of Java
• Importance of Java
• IDE’s for Java
• Traditional Hello world! Prepared by Linda Otoo
Introduction to Programming and Java

• What is Programming?
programming is the set of instructions given
to the computer to perform a particular task.
• Why Programming?
Computer programming is essential because it
enables the creation, operation, and
enhancement of software that powers modern
technology and digital devices, solving complex
problems and improving human Prepared
life by Linda Otoo
Introduction to Programming and C++
• Algorithms:
Algorithms are the sequential step by step set of
instructions given to a computer to perform a
particular task.
• Computer programming languages:
These are formal languages that enables
communication to the computer

Prepared by Linda Otoo


Introduction to Programming and Java
• Programming Paradigms:
Computer programming paradigm is an
approach to classify the various existing
computer programming languages into different
groups based on design, behaviour and features.
• Most commonly used programming
paradigms:
Object-oriented, functional, imperative,
declarative, procedural, structural, etc.
Prepared by Linda Otoo
Introduction to Programming and Java
• What is Java?
Java is a high-level, class-based, object-oriented programming language that
is designed to have as few implementation dependencies as possible. Here is
a brief history of Java :
1. Development: Java was developed by James Gosling at Sun Microsystems
(which is now a subsidiary of Oracle Corporation) and released in 1995. It
was originally conceived as a language for digital devices such as set-top
boxes and televisions.
2. Philosophy: The language was initially called "Oak" after an oak tree that
stood outside Gosling's office, later being renamed to Java. Java's design
was driven by the principles of "Write Once, Run Anywhere" (WORA),
meaning that compiled Java code can run on all platforms that support
Java without the need for recompilation.

Prepared by Linda Otoo


Introduction to Programming and Java
• What is Java?
3. Evolution: Java quickly gained popularity as a language for web
server- side applications . It introduced a garbage-collected heap for
memory management, eliminating the need for manual memory
allocation and deallocation.
4. Standardization: Java has been maintained and standardized by Sun
Microsystems and later by Oracle through the Java Community
Process. This has involved a series of updates and enhancements, which have
been captured in different versions known as Java 1.0, Java 2, and
subsequent releases like Java SE 8, Java SE 11, and Java SE 17.
5. Updates and Improvements: Each version of Java has brought
significant updates, such as the introduction of the "Swing" graphical
API in JDK 1.2, annotations in Java 5, lambda expressions in Java 8, and
modules in Java 9. These have improved the language's robustness,
efficiency, and ease of use.
Prepared by Linda Otoo
Introduction to Programming and Java
• Features of Java:
Here are the features of Java:

1. Object-Oriented: Java is inherently object-oriented, which means it focuses on data (objects)


and methods to operate on that data. This promotes better organization and a modular
approach where the problem is divided into objects and builds data and functions around
these objects.
2. Platform Independent: Java code is compiled into byte code that runs on Java Virtual
Machine (JVM) regardless of the underlying computer architecture. This adheres to the
philosophy of "Write Once, Run Anywhere" (WORA), meaning a Java program is portable
across different platforms provided a JVM is available.
3. High-Level with Automatic Memory Management: Java abstracts away complex details of
the machine, such as memory allocation and deallocation, through its automatic garbage
collection, which runs in the background and frees up memory that is no longer in use.
4. Good Execution Speed: While Java might not be as fast as statically compiled languages like
C++ because it runs on a virtual machine, it is still considered to have good execution speed
due to various optimizations in the JVM, such as Just-In-Time (JIT) compilation.
5. Restricted Pointer Access: Java includes a feature to reference objects which is similar to
pointers but doesn't allow direct manipulation of memoryPrepared
addresses,bywhich
Lindahelps
Otoo in
securing the program against unauthorized access and potential errors.
Introduction to Programming and C++
• Uses of Java
1. Enterprise Applications: Java is widely used in the enterprise
sector; many banks, retailers, and insurance companies use Java
for their server-side applications. Java's stability and scalability
make it well-suited for large-scale applications that require
reliability over time.
2. Mobile Applications: Java is the primary language for developing
Android applications. The Android SDK includes Java libraries and
has been the traditional way of developing Android apps, which
have a large market due to the widespread use of Android devices.
3. Web Applications: Java is also used on the server side for many
web application servers and web services. Technologies like Java
EE (Enterprise Edition) offer a robust framework for developing
and running large-scale, multi-tiered, scalable, and secure network
applications.
Prepared by Linda Otoo
Introduction to Programming and C++

• IDE’s for Java


1. Open source
2. Commercialized
3. Language specific
4. Multi-language specific

Prepared by Linda Otoo


Setting Up the Environment
• Installing a C++ compiler and IDE (Integrated Development Environment)
Step 1: Install Java Development Kit (JDK)
Download JDK:
Visit the Oracle website or an OpenJDK provider like AdoptOpenJDK.
Choose the appropriate JDK version for your operating system (Windows, macOS,
Linux).
Install JDK:
Run the installer you downloaded.
Follow the instructions. Default settings are usually fine.
Set Environment Variables (especially on Windows):
Right-click on 'My Computer' or 'This PC' on your desktop or in File Explorer.
Click 'Properties' > 'Advanced system settings'.
Click 'Environment Variables'.
Under 'System Variables', click 'New' to add a JAVA_HOME variable that points to
the JDK installation directory (e.g., C:\Program Files\Java\jdk-11.0.1).
Locate the 'Path' variable and add a new entry that points to the JDK's bin
Prepared by Linda Otoo
directory, like %JAVA_HOME%\bin.
Setting Up the Environment
• Installing a C++ compiler and IDE (Integrated Development
Environment)
Step 2: Install Integrated Development Environment (IDE)
Choose an IDE:
Popular Java IDEs include IntelliJ IDEA, Eclipse, and NetBeans.
Download the installer for your preferred IDE.
Install IDE:
Run the installer and follow the on-screen instructions.
Configure IDE:
Upon first launch, you might need to configure the JDK within
the IDE. Most modern IDEs detect the JDK automatically.
You can create a new Java project to test your Prepared
setup. by Linda Otoo
Setting Up the Environment
• Writing your first C++ program
Kindly start by creating our first Java Project in the IDE by clicking on File on the menu bar of the text
editor then new followed by New Project and select "Java" under "Categories." Choose "Java
Application" and click "Next."
Enter a project name and specify the project location. Click "Finish" to create the project.
Right-click on the "Source Packages" folder in the Project view and select "New" > "Java Package."
Provide a package name and click "Finish."
After creating the new package, Right-click on the package you just created and select "New" >
"Java Class." Give the class a name and click "Finish."
Kindly write down the following codes within your declared class in the text editor.
public static void main(String[] args) {
System.out.println("Hello, World!");
}
After writing these codes correctly in the text editor, kindly click on File and select “save as” to
save your file.
Click on “Build Project” at the menu bar and afterwards Click on Run Project to compile and
execute the codes respectively.
After compiling and executing the codes, you will have the Hello World printed in theby
Prepared Output
Lindawindow
Otoo at
the bottom of the NetBeans IDE.
Setting Up the Environment
• Writing your first C++ program
You might have followed the instructions to execute “Hello World!” on your console and
learnt about the Java programming structure without understanding the set of
instructions written on the text editor. Let us go through the instructions line by line to
fully understand what we did to actually see “Hello World!” on our console. After creating
the package and the class, we started by
1. Having defaults comments from line 1 to 4. The first comment provides guidance on
how to change the default license file used in the project while the second comment
specifies a file path within the NetBeans IDE file system.
2. In line 5 we have the statement “package newpackage;” – this is just the syntax to
declare a user defined package to organize related classes and interfaces.
3. Line 7 to 10 is a special type of comment indicating that the author is “2BE
COMPUTERS”
4. “public class NewClass {” in line 11 represents the declaration of a new class named
"NewClass". The keyword "public" indicates that the class can be accessed from other
classes and the class is the keyword used in creating the class named “NewClass”.
5. Prepared by Linda Otoo
Setting Up the Environment
• Writing your first C++ program
5. public static void main(String[] args) { at line 13 is known as the main
method of the program. This is what we termed as main method in Java. It
always includes open and close curly brackets {} and any codes written in
this curly bracket will be executed. In your first programme codes, the close
curly bracket is found at line 15. Anytime a Java program is executed, the
code inside the main method is executed first. It serves as the starting point
for the program's execution
6. System.out.println("Hello, World!"); This statement prints the string
Hello, World! to the console. System.out.println is an object usually used to
print out a text on the console and in this case “Hello, World! And you could
have written any other text. Please note that there are no restrictions to the
number of times you can print a text on the console.
Dear student, kingly note that all the Java statements ends with a semicolon
Prepared by Linda Otoo
(;).
Setting Up the Environment
• Writing your first C++ program
Syntax of Comments and New lines in Java
Comments are used in explaining Java codes to enhance its human readable and comprehension. It is
also used to avoid execution when testing alternative codes. There are two main types of comments,
singled-line and multi-line.
• Single-line Comments
Single-line comments starts the statement with two forward slashes (//) and any text found
between // and the end of the line is ignored by the compiler.

Eg.
System.out.println("what is your name?"); // this is a comment

• Multi-line Comments
Multi-line comments start with the statements with one forward slash and asterisks (/*) and ends
with asterisks and forward slash (*/). Any text found in between /* and */ will not be executed.
Eg.
/* I am a student programmer learning about comments in Java */
Prepared
Dear Student, kindly note that comments in Java is the same as we discussed by Linda Otoo
in C++.
Use of the output syntax
1. Pick a special character symbol(s) of your
choice and use it to design your full name
and print to the console
2. Use a special character symbol(s) of your
choice and create shapes such as square,
rectangle, triangle, trapezoid, circle, etc and
print to the console
3. Use a special character symbol(s) of your
choice to design any object (footballer, MTN
logo, bicycle, android, apple, etc.)
Questions and Answers
Thank You!!!

You might also like