[go: up one dir, main page]

0% found this document useful (0 votes)
7 views23 pages

Introduction To Course PT2: @garima Sharma, Geu

The document provides an introduction to Java programming, covering key terminologies such as Java Virtual Machine (JVM), Bytecode, Java Development Kit (JDK), and Java Runtime Environment (JRE). It outlines the features of Java, the object-oriented programming paradigm, and the structure of a Java program, including sections like documentation, package, import, and class. Additionally, it discusses Java tokens, keywords, and identifiers, as well as steps for running a Java program.
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)
7 views23 pages

Introduction To Course PT2: @garima Sharma, Geu

The document provides an introduction to Java programming, covering key terminologies such as Java Virtual Machine (JVM), Bytecode, Java Development Kit (JDK), and Java Runtime Environment (JRE). It outlines the features of Java, the object-oriented programming paradigm, and the structure of a Java program, including sections like documentation, package, import, and class. Additionally, it discusses Java tokens, keywords, and identifiers, as well as steps for running a Java program.
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/ 23

TCS 608

INTRODUCTION TO COURSE – PT2

@GARIMA SHARMA, GEU 1


Java Terminologies
1. Java Virtual Machine(JVM): This is generally referred to as JVM.
There are three execution phases of a program. They are written, compile and run the program.
•Writing a program is done by any java programmer.
•The compilation is done by the JAVAC compiler which is a primary Java compiler included in the
Java development kit (JDK). It takes Java program as input and generates bytecode as output.
•In the Running phase of a program, JVM executes the bytecode generated by the compiler.
2. Bytecode : The JavaC compiler of JDK compiles the java source code into bytecode so that it
can be executed by JVM.
It is saved as .class file by the compiler. To view the bytecode, a disassembler like javap can be
used.
3. Java Development Kit(JDK): While we were using the term JDK, when we learn about
bytecode and JVM . So, as the name suggests, it is a complete Java development kit that
includes everything including compiler, Java Runtime Environment (JRE), java debuggers, java
docs, etc.
For the program to execute in java, we need to install JDK on our computer in order to create,
compile and run the java program.
4. Java Runtime Environment (JRE): JDK includes JRE. JRE installation on our computers allows
the java program to run, however, we cannot compile it.
JRE includes a browser, JVM, applet supports, and plugins. For running the java program, a
computer needs JRE.
5. Garbage Collector: In Java, programmers can’t delete the objects. To delete or recollect that
memory JVM has a program called Garbage Collector. Garbage Collectors can recollect the of
objects that are not referenced. So Java makes the life of a programmer easy by handling
memory management. However, programmers should be careful about their code whether they
are using objects that have been used for a long time. Because Garbage cannot recover the
memory of objects being referenced.
Features of Java
1. Platform Independent
2. Object-Oriented Programming Language
3. Robust
4. Secure
5. Distributed
6. Multithreaded
7. Portable
8. Write once Read Anywhere
05 phases in
Java Program
Object Oriented
Paradigm
Object = Data +
Method
Oops Features
• The data of an object can only be accessed by its methods.
• The method of one object can access method of other object.
• Emphasis is on data rather than procedure.
• Programs are divided into objects.
• Data is hidden and cannot be accessed by external functions.
• New data, methods can be easily added whenever required.
• Follows bottom up approach in program design.
Demo Program
// Demo Java program
// Importing classes from packages
import java.io.*;
// Main class
public class GFG {
// Main method
public static void main(String[] args)
{
// Print statement
System.out.println("We are Graphians! ");
}
}
Comments
❑ Single Line - //
❑ Multiline- /*… */
Objects
Object is a basic runtime entity in
any oop system.
They can present a person, place,
name, or any noun.
Class
The wrapping of data and methods into a single unit is called a class. Also known as
Encapsulation.
In java everything is required to be inside a class.
“class” is a keyword and declares a new class definition to be followed.
Here, SampleOne is a java identifier specifying the name of the class to be defined.
Main line
This is quite similar to main method in C or C++.
Any java application can have number of classes but only one of them must include main
method to initiate the execution.

Public – access specifier declaring method main as unprotected and accessible to all.
Static – class method , this will be called by interpreter before any objects are created, so it is
static.
Void – main method does not return any value.
String args[] – can contain array of objects of the class String.
Java Program
Structure
Sections
1. Documentation Section
Set of comments lines giving the name of the author, date and other details.
It should contain why and what of classes and how of algos.

2. Package Section
First statement is package statement. //OPTIONAL

3. Import Section
This statement instructs the interpreter to load the classes, as we have import in C.

4. Class Section
A program may contain multiple class definitions
Java Tokens
Any program is a collection of classes in Java.
A class is set of declaration statements, methods containing
executable statements.
Most of these contains expression , describing some actions
carried out on data.

Smallest individual units in a program are known as tokens.


Compiler recognises them for building up expressions and
statements.
Steps for Running a
Java Program
1. Creating
2. Compiling
3. Running

1 – Writing the Source Code.


2- To compile your program use statement –
javac ProgName.java
3- To run your program use statement – java
ProgName
Practice
Questions
1. WAP in Java to calculate square root
of a number.
Practice
Questions
2. WAP in Java to calculate area of a
room.
1. WAP in Java to calculate area of rectangle,
Homework Question triangle and circle using multiple classes.
Sample Program
Keywords
• For any language, it is most essential part.
• Java language has 50 keywords or reserved words.
• These keywords combined with operators and separators according to a
syntax, form definition of the Java language.
• Since each keyword has some specific meaning, we cannot use them as
names for variables, classes, methods, and so on.
• All keywords are required to be in lower case letters.
• Java is highly case-sensitive, so by changing the case these keywords can
be used as identifiers.
• However it is a bad practice and should be importantly avoided.
Identifiers
These are programmer designed tokens.
These can be used for naming methods, classes, variables, objects, labels, packages, interfaces
and so on.
Basic Rules :

You might also like