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

Lecture 2.

This document provides an overview of Object Oriented Programming with Java, focusing on the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM). It outlines the structure of a Java source file, including package declarations, import statements, class and interface declarations, and how to run a Java program. The document serves as a foundational guide for understanding Java programming concepts and execution.
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)
9 views14 pages

Lecture 2.

This document provides an overview of Object Oriented Programming with Java, focusing on the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM). It outlines the structure of a Java source file, including package declarations, import statements, class and interface declarations, and how to run a Java program. The document serves as a foundational guide for understanding Java programming concepts and execution.
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/ 14

Object Oriented Programming with Java

(Subject Code: BCS-403)

Unit 1
Lecture 2

Department of Computer Science ,ABES Engineering College


Lecture 2
• JVM, JRE, Java Environment
• Java Source File Structure
• Compilation

Department of Computer Science ,ABES En


gineering College
JDK
The Java Development Kit (JDK) is a cross-
platformed software development environment
that offers a collection of tools and libraries
necessary for developing Java-based software
applications.
It is a core package used in Java, along with the
JVM (Java Virtual Machine) and the JRE (Java
Runtime Environment).

Department of Computer Science ,ABES En


gineering College
JDK
• JDK is an acronym for Java Development Kit.It physically
exists.It contains JRE + development tools.

Department of Computer Science ,ABES En


gineering College
JVM
• JVM (Java Virtual Machine) is an abstract
machine.
• It is a specification that provides runtime
environment in which java byte code can be
executed.
• JVMs are available for many hardware and
software platforms.
• JVM, JRE and JDK are platform dependent
because configuration of each OS differs. But,
Java is platform independent.
Department of Computer Science ,ABES En
gineering College
JRE
• JRE is an acronym for Java Runtime
Environment.
• It is used to provide runtime environment. It is
the implementation of JVM.
• It physically exists.
• It contains set of libraries + other files that
JVM uses at runtime.

Department of Computer Science ,ABES En


gineering College
JRE

Department of Computer Science ,ABES En


gineering College
Java Source File Structure
• In Java, a source file typically follows a specific
structure to define classes, interfaces, and other
elements of the program.
• Package Declaration (Optional):
The package declaration is used to organize related classes
and interfaces into a package. It is the first non-comment line
in the file and is optional.
For example: package com.example.myapp;

Department of Computer Science ,ABES En


gineering College
• Import Statements (Optional): Import statements are used to
bring in classes or entire packages from other packages to use
in the current source file. They appear after the package
declaration (if present) and before the class declaration.
For example:
import java.util.ArrayList;
import java.util.List;
• Class Declaration: A Java source file can contain one public
class (with the same name as the file) and any number of non-
public classes. The class declaration consists of the class
keyword followed by the class name and optional modifiers
(e.g., public, abstract, final). For example:

Department of Computer Science ,ABES En


gineering College
• Interface Declaration (Optional): Similar to classes, a
Java source file can also contain interfaces. The interface
declaration consists of the interface keyword followed by the
interface name and optional modifiers.
For example:
public interface MyInterface {
// interface body
}
• Class or Interface Body: The body of a class or interface
contains fields, methods, constructors, and nested classes or
interfaces. It is enclosed in curly braces {}.
For example:

Department of Computer Science ,ABES En


gineering College
public class MyClass {
private int myField;
public MyClass(int value) {
myField = value;
}
public void myMethod() {
System.out.println("Hello, world!");
}
// nested class
private class NestedClass {
// nested class body
}
}

Department of Computer Science ,ABES En


gineering College
• Comments: Java supports single-line comments (//)
and multi-line comments (/* */) for adding
explanations or documentation to the code.

Department of Computer Science ,ABES En


gineering College
How to Run Java Program
• Write Your Java Program: Create a Java source file with
a .java extension.
• For example, let's say you have a simple program called
HelloWorld.java
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, world!");
}
}
Department of Computer Science ,ABES En
gineering College
• Compile Your Java Program:
Open a command prompt and navigate to the
directory containing your Java source file.
Use the javac command to compile your
program.
javac HelloWorld.java
• Run Your Java Program: Use the java
command to run your compiled Java program.
java HelloWorld
This will execute your HelloWorld class, and you
should see the output Hello, world! printed to
the console. Department of Computer Science ,ABES En
gineering College

You might also like