Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Lecture I (Introduction to Java Programming)

The document provides an introduction to Java programming, focusing on object-oriented programming (OOP) concepts, the history of Java, its features, benefits, and various editions. It explains the Java platform, including the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM), as well as the process of writing and executing Java programs. Additionally, it includes practical steps for setting up Java and running a simple 'Hello World' program using both command line and Eclipse IDE.

Uploaded by

swampyaeaung085
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lecture I (Introduction to Java Programming)

The document provides an introduction to Java programming, focusing on object-oriented programming (OOP) concepts, the history of Java, its features, benefits, and various editions. It explains the Java platform, including the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM), as well as the process of writing and executing Java programs. Additionally, it includes practical steps for setting up Java and running a simple 'Hello World' program using both command line and Eclipse IDE.

Uploaded by

swampyaeaung085
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Introduction to Java

Programming

Faculty of Computer Science, University of Computer


Studies, Yangon
Introduction to OOP

• Object-oriented programming (OOP)


A computer programming model that organizes software design around data, or
objects, rather than functions and logic.
• Object
An object is an entity which has states and behaviors.
An object is an instance of a class.
• Class
A class can be defined as a template that describes the behaviors or states that
the object of its type support.
Structure Programming Vs OOP

Structure Programming Object Oriented Programming

Top to Bottom Design Object focused design

Moderately complex program Very complex program

Less data security More security

Less flexible More flexible

Less reusability More reusability


Introduction to

• Java is an object-oriented programming language with a built-in application


programming interface (API) that can handle graphics and user interfaces and that can
be used to create applications or applets.

• Because of its rich set of API's, and its platform independence, Java can also be
thought of as a platform in itself.

• Much of the syntax of Java is the same as C and C++. One major difference is that Java
does not have pointers.

• However, the biggest difference is that you must write object oriented code in Java.
History of Java

• Java was started as a project called "Oak" by James Gosling in June 1991.

• Java was developed by Sun Microsystems (which is now the subsidiary of


Oracle) in the year 1995.

• First major JDK (Java Development Kit) 1.0 was released on January 21, 1996.

• James Gosling is known as the father of Java.

• Java is intended to let programmers “Write Once, Run Anywhere” (WORA)

• The latest java version is Java™ SE Development Kit 21 (JDK 21) released on 19
September 2023.
Editions of Java

• J2ME (Java 2 Micro Edition)


J2ME is aimed at those producing embedded code for embedded systems,
mobiles and small devices.

• J2SE (Java 2 Standard Edition)


It’s the purest form of Java, a basic foundation for all other editions.
J2SE is aimed at creating applications for Desktop environment.

• J2EE (Java 2 Enterprise Edition)


J2EE is aimed at those producing distributed enterprise applications.
It has a much larger usage of Java like development of web services,
networking, server side scripting and other various web based applications.
Benefits of Java
• Get started quickly: Although the Java programming language is a powerful object-
oriented language, it's easy to learn, especially for programmers already familiar with
C or C++.
• Write better code: The Java programming language encourages good coding
practices, and automatic garbage collection helps you avoid memory leaks.
• Avoid platform dependencies: You can keep your program portable by avoiding the
use of libraries written in other languages.
• Write once, run anywhere: Because applications written in the Java programming
language are compiled into machine independent bytecodes, they run consistently on
any Java platform.
• Object-oriented : You can create modular programs and reusable code.
Java’s Features

The Java programming language is a high-level language that can be


characterized by all of the following features:

• Simple • Architecture neutral


• Object-oriented
• Portable
• Distributed
• High performance
• Interpreted
• Robust • Dynamic
• Secure
The Java platform
• A platform is the hardware or software environment in which a program runs
• Microsoft Windows, Linux and Mac OS
• The Java platform has two components:
• The Java Virtual Machine
• The Java Application Programming Interface (API)
What is JDK?
• Java Development Kit is an environment of software development used for developing
Java applications.

• One can easily install more than one version of JDK on the same computer.

• The Java developers can make use of it on macOS, Windows and Linux.

• JDK assists them in coding and running the Java programs.

• JDK is a kit(or package) that includes two things


• Development Tools(Java Debugger, JavaDoc, compilers,)

• JRE (to execute your java program).


What is JRE?

• The Java Runtime Environment (JRE) is an implementation of JVM.

• It is a type of software package that provides class libraries of Java, JVM, and various
other components for running the applications written in Java programming.

• All the versions of JDK come bundled up with the JRE (Java Runtime Environment).
What is JVM?

• Java Virtual Machine(JVM) provides a runtime environment for driving Java applications
or code.

• JVM is an abstract machine that converts the Java bytecode into a machine language.
Difference Between JDK, JRE, JVM

JVM= Only
the runtime
JRE = Libraries for running
environment
the application + JVM (Java
that helps in
Virtual Machine)
executing the
Java
bytecode

JDK = Development Tools + JRE (Java Runtime Environment)


Java Compilation & Executing
Java File & Class File

Java File

Class File
Java Installation
1. Install Java for Windows(e.g. Download and Install jdk-16.0.2_windows-
x64_bin.exe )
2. Set up Environmental Variable for Java on Windows 10
• Right-click on This PC icon
• Choose Advanced System Settings
• Click the Advanced tab
• Click Environment Variables button
• double click on Path in System Variables session
• Add your JDK path (e.g. C:\Program Files\Java\jdk-16.0.2\bin) to Path

Faculty of Computer Science, University of Computer 16


Studies, Yangon
First Java Program
1. Write Java source code in any text editor and save it on disk (HelloWorld .java)
public class HelloWorld {
public static void main(String[] args){

System.out.println("Hello World");
}
}
2. Compile the program
javac HelloWorld.java

3. Run the program


java HelloWorld
Faculty of Computer Science, University of Computer 17
Studies, Yangon
public static void main(String args[])
• public: The keyword “public” is an access specifier that declares the main method as
unprotected.

• static: It says this method belongs to the entire class and NOT a part of any objects
of class. The main must always be declared static since the interpreter uses this
before any objects are created.

• void: The type modifier that states that main does not return any value.

• A program must include a method called main where the program starts. The
argument to main must always be a string array (containing any command line
arguments).
Faculty of Computer Science, University of Computer 18
Studies, Yangon
System.out.println(“Hello World”);
• java.lang.*
• All classes/items in “lang” package of java package.
• System is really the java.lang.System class.
• System.out.println() invoke the println() method of the “out” field of
the java.lang.System class.

Faculty of Computer Science, University of Computer 19


Studies, Yangon
Closer Look at - Hello World
• The class has one method – main()
public static void main(String[] args)
{
System.out.println("Hello :"+ args[0] + " " + arg[1]);
}

• Command line input arguments are passed in the String array args[]
e.g. java HelloWorld John Jane
args[0] – John args[1] – Jane

Faculty of Computer Science, University of Computer 20


Studies, Yangon
Hello World Example using Eclipse
IDE
• Create Java Project
• Select from the menu FileNewJava Project

Faculty of Computer Science, University of Computer 21


Studies, Yangon
1. Create Java Project
• Enter “HelloWorld” as the project name. Keep rest of the settings as it is as shown in the following
screenshot.

Faculty of Computer Science, University of Computer 22


Studies, Yangon
2. Create Java Package
• Right click on ‘src’ folder and select from context menu NewPackage.

Faculty of Computer Science, University of Computer 23


Studies, Yangon
2. Create Java Package (Cont’d)
• Write ‘mypack’ in the ‘Name’ field and click ‘Finish’ button.

Faculty of Computer Science, University of Computer 24


Studies, Yangon
3. Create Java Class
• Write “HelloWorld” in the ‘Name’ field and select the check-box for ‘public static void
main(String[] args)’

Faculty of Computer Science, University of Computer 25


Studies, Yangon
4. Write Java Code
• Write the code like System.out.println("Hello World"); in the
generated ‘HelloWorld’ file

Faculty of Computer Science, University of Computer 26


Studies, Yangon
5. Run Your Code
• Right click on ‘HelloWorld.java’ and select from context menu ‘Run As’  ‘Java
Application’.

Faculty of Computer Science, University of Computer 27


Studies, Yangon
Summary
• Introduce the OOP with Java
• Learn about the history, features, benefits, and editions of Java
• Learn the Java platform and the steps in Java compilation and
execution
• How to write and run Java program in command line and Eclipse IDE

Faculty of Computer Science, University of Computer 28


Studies, Yangon

You might also like