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

OOP - Introduction To Java Programming

The document provides an introduction to Java programming, detailing its history, features, and basic structure. It covers essential concepts such as classes, methods, identifiers, and the compilation and execution process of Java programs. Additionally, it explains the use of comments and user input handling through the Scanner class.

Uploaded by

kusaltharindu739
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)
6 views27 pages

OOP - Introduction To Java Programming

The document provides an introduction to Java programming, detailing its history, features, and basic structure. It covers essential concepts such as classes, methods, identifiers, and the compilation and execution process of Java programs. Additionally, it explains the use of comments and user input handling through the Scanner class.

Uploaded by

kusaltharindu739
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/ 27

ITC 1233 - OBJECT ORIENTED

PROGRAMMING
INTRODUCTION TO JAVA PROGRAMMING

Ms.Nirasha Kulasooriya,
Lecturer, Dept. of ICT, FOT,USJ.
WHAT IS JAVA?
DO YOU KNOW HIM?
WHAT IS JAVA?

• Java was developed in the mid-1990s by James A. Gosling,


a former computer scientist with Sun Microsystems.
• Java is an Imperative, Object-Oriented, General Purpose
programming language.

• Cross-platform: Write Once, Run Anywhere (WORA) as


opposed to Write Once, Compile Anywhere (WOCA)
EVOLUTION
OF JAVA?
EVOLUTION OF MODELS IN JAVA CODE
GENERATION
HOW DOES C/C++ WORK?
HOW DOES JAVA WORK?
JRE, JVM, JDK
FEATURES IN JAVA
INTEGRATED DEVELOPMENT ENVIRONMENT (IDE)
FIRST JAVA PROGRAM
ExampleClass.java
Class name The main
method
Starting point of
a Java program

Prints out the text into


the command-line.
Output: Welcome to Java Programming!
COMMENTS
End-of-line comments (single-line comments)
• Comment begins with // and terminates at the end of the
line
• Similar to C single-line comments

Traditional comments (multi-line comments)


• These begin with the delimiter /* and end with */
• Similar to C multi-line comments.
JAVADOC COMMENTS
• These are delimited by /** and */. The compiler ignores all text

between the delimiters.

• Javadoc comments enable you to embed program documentation


directly in your programs.

• These comments are the preferred Java documentation format in industry.

• The Javadoc utility program (part of the JDK) reads Javadoc comments and uses
them to prepare program documentation in HTML5 web-page format.
CLASS
• Every Java program consists of at least one class that you define.

• The class keyword introduces a class declaration and is immediately


followed by the class name (class ExampleClass).

• Keywords are reserved for use by Java and are spelled with all lowercase
letters.
• In Java, as a programming practice, class names usually follow the
UpperCamelCase naming convention. (e.g. ExampleClass)
Begins with a capital letter and capitalizes the first letter of each word they include

• A public class must be placed in a file that has a filename of the form
ClassName.java, so class Example is stored in the file Example.java

• A left brace begins the body of the class declaration. A corresponding right
brace ends the class declaration.
CLASS: EXAMPLE
Since the class is
public, this class
should be stored in a Class name
file named Upper camel case
ExampleClass.java

Body of the class


IDENTIFIERS
• Identifiers are the names of:
🢝 variables, methods, classes, packages and interfaces

• An identifier is series of characters consisting of –


🢝 letters, digits, underscores (_) and dollar signs ($)
🢝 that does not begin with a digit
🢝 and does not contain spaces

• Java is case-sensitive
🢝 Uppercase and lowercase letters are different in Java
🢝 a1 and A1 are different identifiers
LET’S TEST
QUESTION: WHICH OF THESE ARE VALID
IDENTIFIERS IN JAVA?
1. e Welcome1
2. $value
3. 67value
4. _value
5. input field
6. m_inputField1
7. 7_button
METHODS: THE ‘MAIN’ METHOD
• The main method is the starting point of every Java application.

• The parentheses after the identifier main indicate that it’s a program

building block called a method.

• Java class declarations normally contain one or more methods.

• For a Java application, one of the methods must be called main and
must be defined as above; otherwise, the program will not execute.
METHODS: THE ‘MAIN’ METHOD
• Methods perform tasks and can return information when they
complete their tasks.
• Keyword void indicates that this method will not return any
information.
• The left brace begins the body of the method
declaration. A corresponding right brace ends it.
void means nothing is returned from
the method

Name of the method


Body of the method
OUTPUT
• The below code instructs the computer to display the
characters between the double quotation marks.
• The quotation marks themselves are not displayed.
• Together, the quotation marks and the characters between
them are a known as a string literal. White-space characters in
strings are not ignored by the compiler.

• Strings cannot span multiple lines of code.


COMPILING A PROGRAM
To compile the java program, type the following in the
command-line:

Syntax javac JavaFileName.java

Example javac ExampleClass.java

If the program does not contain compilation errors, this command


creates the file: ExampleClass.class containing the platform
independent Java bytecodes that represents the application.
EXECUTING A PROGRAM
To run the java program, type the following in the command-line:
Syntax java JavaFileName

Example java ExampleClass


When we use the java command to execute the application on a
given platform, the JVM will translate these bytecodes into
instructions that are understood by the underlying operating system
and hardware.
IMPORT DECLARATIONS
• A great strength of Java is its rich set of predefined classes that
you can reuse rather than “reinventing the wheel.”

• These classes are grouped into packages – named groups of


related classes and are collectively referred to as the Java class
library, or the Java Application Programming Interface. (Java
API)
USER INPUT
• The Scanner (package java.util) enables a program to read
data to be used in a program.
• Integers, floats, doubles, Strings etc.
ANY QUESTIONS?

You might also like