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

Introduction to Java Programming Basics

Java is a versatile programming language developed by Sun Microsystems, designed for various platforms and known for its 'write once, run anywhere' capability. It includes two main types of applications: applets that run in web browsers and standalone applications. The Java Development Kit (JDK) and Java Runtime Environment (JRE) are essential for developing and running Java programs, with various integrated development environments (IDEs) available for ease of use.

Uploaded by

mayamubiru05
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)
4 views27 pages

Introduction to Java Programming Basics

Java is a versatile programming language developed by Sun Microsystems, designed for various platforms and known for its 'write once, run anywhere' capability. It includes two main types of applications: applets that run in web browsers and standalone applications. The Java Development Kit (JDK) and Java Runtime Environment (JRE) are essential for developing and running Java programs, with various integrated development environments (IDEs) available for ease of use.

Uploaded by

mayamubiru05
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

Fundamentals of Programming

Lecture 2
Introduction Java Programming
What Is Java?
• Java is a powerful and versatile programming language for
developing software running on mobile devices, desktop
computers, and servers.
• Java was developed by a team led by James Gosling at Sun
Microsystems. Sun Microsystems was purchased by Oracle
in 2010.
• Java was designed in 1991 for use in embedded chips in
consumer electronic appliances. In 1995, renamed Java, it
was redesigned for developing Web applications.

01/21/2026 Programming Methodology by [Link] 2


What Is Java?
• Java has become enormously popular. Its rapid rise and
wide acceptance can be traced to its design
characteristics, particularly its promise that you can
write a program once and run it anywhere.
• Java initially became attractive because Java programs
can be run from a Web browser. Such programs are
called applets.
• Java is simple, object oriented, distributed, robust,
secure…

01/21/2026 Programming Methodology by [Link] 3


Advantages of Java
According to Sun’s Java White paper:
“Java is a simple, objected-oriented, distributed,
interpreted, robust, secure, architecture-neutral,
portable, high-performance, multi-threaded, and
dynamic language”.

Most of the claims are justified, while others are


controversial.

01/21/2026 Programming Methodology by [Link] 4


Java Applets and Applications
• Java applications fall into two main groups: applets and
applications.
• Java applets:- are Java programs that are
downloaded over the World Wide Web and executed
by a Web browser on the reader’s machine.
• Java applications:- are more general programs
written in the Java language. Java applications don’t
require a browser to run, but run on their own.

01/21/2026 Programming Methodology by [Link] 5


Java Language Specification
• Computer language has strict rules of usage. If you do not
follow the rules when writing a program, the computer will not
be able to understand it.
• The Java language specification and the Java API define the
Java standards.
• The Java language specification is a technical definition of the
Java programming language’s syntax and semantics.
• The application program interface (API), also known as library,
contains predefined classes and interfaces for developing Java
programs.
01/21/2026 Programming Methodology by [Link] 6
Java requirements
• A Java distribution typically comes in two flavours, the Java
Runtime Environment (JRE) and the Java Development Kit
(JDK).
• The JRE consists of the JVM and the Java class libraries. Those
contain the necessary functionality to start Java programs.
• The JDK additionally contains the development tools necessary
to create Java programs. The JDK therefore consists of a Java
compiler, the Java virtual machine and the Java class libraries.
– A Library is a collection of linkable files that were supplied with your
compiler or that you created yourself.
01/21/2026 Programming Methodology by [Link] 7
Java requirements
• The JDK consists of a set of separate programs, each
invoked from a command line, for developing and
testing Java programs.
• Instead of using the JDK, you can use a Java
development tool (e.g., NetBeans, Eclipse, and
TextPad) software that provides an integrated
development environment (IDE) for developing Java
programs quickly.

01/21/2026 Programming Methodology by [Link] 8


Development Environments
• There are many programs that support the development
of Java software, including:
– Sun Java Development Kit (JDK)
– NetBeans
– Eclipse
– Borland JBuilder
– MetroWerks CodeWarrior
– BlueJ
– jGRASP
• Though the details of these environments differ, the basic
compilation and execution process is essentially the same
01/21/2026 Programming Methodology by [Link] 1-9
Check Point
2.1 Who invented Java? And which company owns Java now?
2.2 What is a Java applet?
2.3 What is a Java application
2.4 What programming language does Android use?
2.5 What is the Java language specification?
2.6 What does JDK stand for?
2.7 What does IDE stand for?
2.8 Are tools like NetBeans and Eclipse different languages from Java, or are
they dialects or extensions of Java?
01/21/2026 Programming Methodology by [Link] 10
Java Program Structure
• In the Java programming language:
– A program is made up of one or more classes
– A class contains one or more methods
– A method contains program statements

• These terms will be explored in detail throughout the


course
• A Java application always contains a method called
main

01/21/2026 Programming Methodology by [Link] 1-11


A Simple Java Program
1. public class Welcome {
2. public static void main(String[] args) {
3. // Display message Welcome to Java!
4. [Link]("Welcome to Java!");
5. }
6. }

Note that the line numbers are for reference purposes


only; they are not part of the program. So, don’t type line
numbers in your program.

01/21/2026 Programming Methodology by [Link] 12


Compiling and Running

javac [Link]
[Link]
compile
run
source code

java welcome [Link]

bytecode

01/21/2026 Programming Methodology by [Link] 13


The Program's Components
• Line 1 defines a class.
– Every Java program must have at least one class. Each class
has a name. By convention, class names start with an
uppercase letter. In this example, the class name is
Welcome.
• Line 2 defines the main method.
– The program is executed from the main method. A class
may contain several methods. The main method is the entry
point where the program begins execution.

01/21/2026 Programming Methodology by [Link] 14


The Program's Components
• A method is a construct that contains statements. The main method
in this program contains the [Link] statement. This
statement displays the string Welcome to Java!.

• String is a programming term meaning a sequence of characters. A


string must be enclosed in double quotation marks(“…”). Every
statement in Java ends with a semicolon (;), known as the statement
terminator.

• Reserved keywords, have a specific meaning to the compiler and


cannot be used for other purposes in the program. For example, when
the compiler sees the word class, it understands that the word after
class is the name for the class. Other reserved words in this program
are public, static, andProgramming
01/21/2026 void. Methodology by [Link] 15
The Program's Components
• Line 3 is a comment
– Comments help programmers to communicate and understand
the program. They are not programming statements and thus
are ignored by the compiler.
• Two slashes (//) on a line (line comment)
// This application program displays Welcome to Java!
• Enclosed between /* and */ on one or several lines.
/* This application program displays Welcome to Java! */
/* This application program
displays Welcome to Java! */

01/21/2026 Programming Methodology by [Link] 16


A Simple Java Program

Tip: An opening brace must be matched by a closing brace.


Whenever you type an opening brace, immediately type a
closing brace to prevent the missing-brace error. Most Java
IDEs automatically insert the closing brace for each opening
brace.

01/21/2026 Programming Methodology by [Link] 17


The println Method
• In the Lincoln program from Chapter 1, we invoked
the println method to print a character string
• The [Link] object represents a destination (the
monitor screen) to which we can send output

[Link] ("Whatever you are, be a good one.");

object method
information provided to the method
name
(parameters)

01/21/2026 Programming Methodology by [Link] 1-18


The print Method
• The [Link] object provides another service
as well
• The print method is similar to the println
method, except that it does not advance to the
next line
• Therefore anything printed after a print
statement will appear on the same line

01/21/2026 Programming Methodology by [Link] 1-19


Special Characters

Note: You are probably wondering why the main method is defined this way and
why
[Link](...) is used to display a message on the console. For the
time being, simply accept that this is how things are done. Your questions will be
fully answered in subsequent
01/21/2026 chapters.
Programming Methodology by [Link] 20
Check point
• Once you understand the program, it is easy to extend it
to display more messages. For example, you can rewrite
the program to display three messages,

01/21/2026 Programming Methodology by [Link] 21


Check point
• Further, you can perform mathematical computations and
display the result on the console. Given an example of
evaluating

01/21/2026 Programming Methodology by [Link] 22


Check point
• What is a keyword? List some Java keywords.
• Is Java case sensitive? What is the case for Java keywords?
• What is a comment? Is the comment ignored by the compiler?
How do you denote a comment line and a comment paragraph?
• What is the statement to display a string on the console?
• Show the output of the following code:
public class Test {
public static void main(String[] args) {
[Link]("3.5 * 4 / 2 – 2.5 is ");
[Link](3.5 * 4 / 2 – 2.5);
}
}

01/21/2026 Programming Methodology by [Link] 23


The Java program-development process consists of
repeatedly creating/modifying source code,
compiling, and executing programs.
01/21/2026 Programming Methodology by [Link] 24
• The Java language is a high-level language, but Java bytecode is a low-level
language. The bytecode is similar to machine instructions but is architecture
neutral and can run on any platform that has a Java Virtual Machine (JVM), as
shown in Figure 1.8b. Rather than a physical machine, the virtual machine is
a program that interprets Java bytecode.
• This is one of Java’s primary advantages: Java bytecode can run on a variety
of hardware platforms and operating systems. Java source code is compiled
into Java bytecode and Java bytecode is interpreted by the JVM. Your Java
code may use the code in the Java library. The JVM executes your code along
with the code in the library.
• To execute a Java program is to run the program’s bytecode. You can
execute the bytecode on any platform with a JVM, which is an interpreter. It
translates the individual instructions in the bytecode into the target machine
language code one at a time rather than the whole program as a single unit.
Each step is executed immediately after it is translated.

01/21/2026 Programming Methodology by [Link] 25


Proper Indentation and Spacing
A consistent indentation style makes programs clear and easy to read,
debug, and maintain.
Indentation is used to illustrate the structural relationships between a
program’s components or statements.
Java can read the program even if all of the statements are on the
same long line, but humans find it easier to read and maintain code
that is aligned properly. Indent each subcomponent or statement at
least two spaces more than the construct within which it is nested.
A single space should be added on both sides of a binary operator, as
shown in the following statement:
[Link](3+4*4); Bad style
[Link](3 + 4 * 4); Good style
01/21/2026 Programming Methodology by [Link] 26
END

01/21/2026 Programming Methodology by [Link] 27

You might also like