0% found this document useful (0 votes)
9 views41 pages

Lecture 1 Intro To Java

This lecture introduces Java as a high-level programming language, explaining its structure, including classes and methods. It provides detailed instructions for installing the Java Development Kit (JDK) and setting up the environment, as well as installing Eclipse IDE for Java development. Additionally, it covers basic Java programming concepts, including comments, identifiers, and the translation of Java code into bytecode.

Uploaded by

ramii
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)
9 views41 pages

Lecture 1 Intro To Java

This lecture introduces Java as a high-level programming language, explaining its structure, including classes and methods. It provides detailed instructions for installing the Java Development Kit (JDK) and setting up the environment, as well as installing Eclipse IDE for Java development. Additionally, it covers basic Java programming concepts, including comments, identifiers, and the translation of Java code into bytecode.

Uploaded by

ramii
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

LECTURE 1

INTRODUCTION TO JAVA
Prepared by Dr. Donghoon Kwon
What is Java?
• A computer is made up of hardware and software
• hardware – the physical, tangible pieces that support the
computing effort
• program – a series of instructions that the hardware
executes one after another
• Programs are sometimes called applications
• software – consists of programs and the data those
programs use
What is Java? (Cont’)
• Java is one of the high-level programming languages to

make a program.

•A programming language specifies the words and


symbols that we can use to write a program

• A programming language employs a set of rules that

dictate how the words and symbols can be put together to


form valid program statements
What is Java? (Cont’)
• 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

• A Java application always contains a method called main


Java Integrated Development Environment
(IDE)
Java Installation
1. Java Development Kit (JDK) installation
1) Go to https://www.oracle.com/java/technologies/downloads/

1. Select the JDK version. I recommend


JDK 17 due to updates.
2. Select your OS.
Java Installation (Cont’)
1. Java Development Kit (JDK) installation (Cont’)
2) Since my OS is Windows, I download the x64 installer file
Java Installation (Cont’)
1. Java Development Kit (JDK) installation (Cont’)
2) If you are a mac user using an M1 chip, download the Arm 64
DMG installer file. Otherwise, download the x64 DMG installer
File
Java Installation (Cont’)
1. Java Development Kit (JDK) installation (Cont’)
3) After downloading, double click the installation file.
4) Click the next button.
Java Installation (Cont’)
1. Java Development Kit (JDK) installation (Cont’)
5) You can change the jdk file installation directory by clicking the
change button, but I recommend using the default directory.
Java Installation (Cont’)
1. Java Development Kit (JDK) installation (Cont’)
6) When installation is done, click the close button.
Java Installation (Cont’)
2. Environment variable setting
1) Make sure you have the jdk-17.0.3.1 folder. You can find this
folder through the following directory if you are a Windows user:
C:\Program Files\Java\jdk-17.0.3.1
Java Installation (Cont’)
2. Environment variables setting (Cont’)

2) Copy the following path: C:\Program Files\Java\jdk-17.0.3.1

3) In the search box, type “system environment”

4) Click “Edit the system environment variables”


Java Installation (Cont’)
2. Environment variables setting (Cont’)
5) Select the Advanced tab
6) Click the Environment Variables button
Java Installation (Cont’)
2. Environment variables setting (Cont’)
7) In the System variables section, click the New Button.
Java Installation (Cont’)
2. Environment variables setting (Cont’)
8) In the System variables section, click the New Button.

9) Type JAVA_HOME in the variable name box and paste


C:\Program Files\Java\jdk-17.0.3.1 in the variable value box

10) Click the OK button


Java Installation (Cont’)
2. Environment variables setting (Cont’)
11) In the System variables section, find Path and double click it.
Java Installation (Cont’)
2. Environment variables setting (Cont’)
12) Click the New Button and copy and paste the following file

directory: C:\Program Files\Java\jdk-17.0.3.1\bin


Java Installation (Cont’)
2. Environment variables setting (Cont’)
13) To check your work, open “CMD”

14) Type java –version and javac –version, respectively


Eclipse Installation
1. Go to https://www.eclipse.org/downloads/
2. Click the download button
Eclipse Installation (Cont’)
3. Click Eclipse IDE for Java Developers
Eclipse Installation (Cont’)
4. I recommend using the default directory.
5. Click the install button
Eclipse Installation (Cont’)
6. Click the Launch button
Hello World in Java
1. Create a new folder for java programming and use it
from now on for better file management
2. Check “Use this as the default and do not ask again”
Hello World in Java (Cont’)
3. Close the welcome tab
Hello World in Java (Cont’)
4. Click “Create a Java project” or File-New-Java Project
Hello World in Java (Cont’)
5. Type the project name
6. Click the Finish button
Hello World in Java (Cont’)
7. Click the “Don’t create” button
Hello World in Java (Cont’)
8. Expand the Lecture 1 project
9. Move the mouse cursor to the src icon and click the
right mouse button
10. Click New-Class
Hello World in Java (Cont’)

11. Expand the Lecture 1 project


12. Move the mouse cursor to the src icon
and click the right mouse button
13. Click New-Class
14. Type the class name and check the
“public static void matin(String[] args)
method box
15. Click the Finish button
Hello World in Java (Cont’)
• Now, everything is ready for Java programming
Hello World in Java (Cont’)
• Type System.out.println(“Hello World!”);
• Click the Run button
• Check output
Java Program

public class Lecture1


{
class header

class body

Comments can be placed almost anywhere


}
Java Program (Cont’)
// comments about the class
public class Lecture1
{

// comments about the method


public static void main(String[] args)
{
method header
method body
}

}
Comments
• Comments should be included to explain the purpose of
the program and describe processing
• They do not affect how a program works
• Java comments can take three forms:

// Single line comments

/* Multi-line comments */

/** this is a javadoc comment */


Documentation comments are usually used to write large
programs for a project or software application as it helps to create
documentation API.
Identifiers
• Identifiers are the words a programmer uses in a program
• can be made up of letters, digits, the underscore character ( _ ), and
the dollar sign
• cannot begin with a digit

• Java is case sensitive

• Total, total, and TOTAL are different identifiers

• By convention, programmers use different case styles for


different types of identifiers, such as
• title case for class names - Lincoln

• upper case for constants - MAXIMUM


Identifiers (Cont’)
• A reserved word cannot be used in any other way
Format
//********************************************************************
// Lecture1.java Java Foundations
//
// Demonstrates a poorly formatted, though valid, program.
//********************************************************************

public class Lecture1{public static void main(String[]args){


System.out.println("Hello World!");}}
Format (Con’t)
//********************************************************************
// Lecture1.java Java Foundations
//
// Demonstrates another valid program that is poorly formatted.
//********************************************************************

public class
Lecture1
{
public
static
void
main
(
String
[]
args )
{
System.out.println (
"Hello World!" )
;
}
}
Java Translation
• The Java compiler translates Java source code into a special

representation called bytecode

• Java bytecode is not the machine language for any traditional

CPU

• Another software tool, called an interpreter, translates bytecode

into machine language and executes it

• Therefore the Java compiler is not tied to any particular

machine

• Java is considered to be architecture-neutral


Classes and Objects
• A class is like a blueprint from which you can create many
of the "same" house with different characteristics

You might also like