0% found this document useful (0 votes)
2 views8 pages

Java U 1 Lec 1 Notes Marked PDF

This document provides an introduction to Java, describing it as an object-oriented, high-level programming language that facilitates communication with computers through structured instructions. It outlines the Java source file structure, including class definitions and the main method, as well as the process of compiling and executing Java programs. Additionally, it explains the Java environment components: JDK, JRE, and JVM, highlighting their roles in Java application development and execution.

Uploaded by

suhani bansal
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)
2 views8 pages

Java U 1 Lec 1 Notes Marked PDF

This document provides an introduction to Java, describing it as an object-oriented, high-level programming language that facilitates communication with computers through structured instructions. It outlines the Java source file structure, including class definitions and the main method, as well as the process of compiling and executing Java programs. Additionally, it explains the Java environment components: JDK, JRE, and JVM, highlighting their roles in Java application development and execution.

Uploaded by

suhani bansal
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/ 8

Unit-I Lecture-1

Today’s Target
 What is Java?
 Java Source File Structure
 Compilation and Execution
 Java Environment
 JDK
 JRE
 JVM
Object Oriented Programming with Java

What is ‘Java’?
"Java is an object-oriented, high-level programming language."

 Object-Oriented: Based on real-world entities (Objects and Classes).


 High-Level: Easy to read & write, closer to human language than machine code.
 Programming: A way to give instructions to a computer.
 Language: A medium of communication.

To make a computer/device perform a task, we need to communicate


our ideas to it.
A programming language helps us give instructions to the computer in
a structured way.
Java enables developers to do this in terms of objects and in a
language closer to natural language easy to understand by the
humans.
Object Oriented Programming with Java
Java Source File Structure
First Program in Java
class HelloJava
{
public static void main(String args[])
{
System.out.println("Hello, Java!");
}
}

Java source code is written in a .java file.

Class Definition
 In Java, every program must be enclosed in a class.
 A class represents a set of similar objects.
 It is recommended that the class name matches the file name.
 The basic structure of a class looks like the following:
class HelloJava
{
...
}
Object Oriented Programming with Java

Java Source File Structure

Main Method

The main method is the starting point of every Java program. When we run a Java program, execution
begins from the main method.
- Signature of the Main Method

The standard syntax of the main method is: public static void main(String args[])

public : Makes the method accessible from


anywhere.
static : Allows the method to run without creating
an object of the class.
void : Means the method does not return any value
main : This is the entry point of the Java program.
String args[]: An array of Strings (named args in the
example) is passed as parameter to main.
Object Oriented Programming with Java

Java Source File Structure

Main Method

- Definition or Body of the Main Method

The body of the main method contains the actual instructions to be executed. Statements inside the
method are written inside curly braces {}.

public static void main(String args[])


{
System.out.println("Hello, Java!");
}

 System.out.println("Hello, Java!");
prints text on the screen.

 Every statement in Java ends with a semicolon (;).


Object Oriented Programming with Java

Compiling and Executing a Java Program

Compiling the Java Program


 Command to compile the Java program:
javac HelloJava.java

 javac is the Java compiler that converts Java source code into bytecode.
 If there are no errors, it generates a file: HelloJava.class .
 This .class file contains bytecode, which is not machine-specific but can be executed on any platform
with a JVM.

Executing the Java Program


 Command to execute:
java HelloJava

 java is the Java interpreter that runs the compiled bytecode.


 Output: Hello, Java!
Object Oriented Programming with Java

Java Environment
JDK (Java Development Kit)
The JDK is a complete software development package that includes everything needed to
develop, compile, and run Java applications. It contains the JRE (Java Runtime Environment)
and development tools like the Java compiler (javac), debugger, and other utilities. Without the
JDK, we cannot develop and compile Java programs.

JRE (Java Runtime Environment)


The JRE is required to run Java applications. It includes the JVM (Java Virtual Machine) along
with core Java libraries and runtime resources. While the JRE allows you to execute Java
programs, it does not include the compiler or development tools, so you cannot develop Java
applications with just the JRE.

JVM (Java Virtual Machine)


The JVM is a key component that makes Java platform-independent. It converts Java bytecode
(.class files) into machine code so that the program can run on any operating system. JRE
contains a JVM, ensuring that Java programs can run on different devices without modification.

JDK ⊃ JRE ⊃ JVM


JDK contains JRE, and JRE contains JVM.

You might also like