SlideShare a Scribd company logo
1 of 34
Modern Programming
Languages
HAZRAT KHAN LECTURE 1
Introduction
Java is a High Level programming Language.
The first name of Java was Oak, developed in 1991 by Sun Microsystems.
In 1995, it was renamed as Java.
A key goal of Java is to be able to write programs that:
will run on a great variety of computer systems and
computer-control devices.
This is sometimes called “write once, run anywhere.”
Java Platform
The Java platform differs from most other platforms in that it's a software-
only platform that runs on top of other hardware-based platforms.
The Java platform has two components:
The Java Virtual Machine (JVM)
The Java Application Programming Interface (API) [Built-in Java class
libraries]
The Java Virtual Machine; it's the base for the Java platform and is ported
onto various hardware-based platforms.
Why Choose Java(Features)?
Simple:
◦ Programming notation of Java is not different from the
programming language like C and C++ which makes it easier to
learn Java.
Object-oriented:
◦ Java is pure object oriented programming language
Why Choose Java(Features)?
Secure:
◦ Java program run under the control of JVM, do not instructs the
commands directly to the machine like C/C++
◦ This way any program tries to get illegal access to the system will not be
allowed by the JVM. Allowing Java programs to be executed by the JVM
makes Java program fully secured under the control of the JVM.
Portable:
◦ Java programs are portable because of its ability to run the program on
any platform and no dependency on the underlying hardware /
operating system.
Why Choose Java(Features)?
Multithreaded:
◦ Java allows you to develop program that can do multiple task
simultaneously
Architecture-Neutral:
◦ Java code does not depend on the underlying architecture and
only depends on it JVM thus accomplish the architecture neutral
programming language.
Why Choose Java(Features)?
Interpreted:
◦ The compiled code of Java is not machine instructions but rather
its a intermediate code called ByteCode. This code can be executed
on any machine that implements the Java virtual Machine. JVM
interprets the ByteCode into Machine instructions during runtime.
Performance:
◦ JVM interpret only the piece of the code that is required to
execute and untouch the rest of the code. The performance of java
is never questioned compared with another programming
language.
Java is Architecture Neutral!
The most important advantage of java over other programming
Languages is that, Java is Architecture Neutral.
This means that a Program written in java can be run by “Any
Machine” having “Any operating System”.
Java is platform-independent language
Java’s Magic(JVM & ByteCode)
Java program is first compiled and then it is interpreted.
When a java program is compiled, it is then converted into
bytecode.
Byte code is intermediate code.
Byte code is a set of instructions designed to be executed by the
JVM
Java’s Magic(JVM & ByteCode)
JVM stands for the Java Virtual Machine. The JVM is interpreter for
java byte code.
Job of JVM is to read this ByteCode and convert into machine
dependent instructions. So, JVM’s needs to be platform specific but
not the developers code.
Java’s Magic(JVM & ByteCode)
JVM vs ByteCode
JVM is platform dependent while ByteCode is not
JVM needs to be pre-installed on the machine for executing java
program.
There are different version of JVM available in the market to support
variety of platform
Downloading & Installing JDK / Netbeans
Java Development Toolkit (JDK)
Java SE 7
Java SE 8
www.oracle.com/technetwork/java/javase/downloads
Netbeans
Bundled with JDK
Can also get at netbeans.org/downloads
Phases of Java Program
Java programs normally go through five phases:
Edit
Compile
Load
Verify
Execute
Phase 1&2: Edit & Compile
Phase 3: Loading a Program into Memory
Phase 4: ByteCode Verification
Phase 5: Execution
Your First Java Program
class MyProgram
{
public static void main(String args[])
{
System.out.println("This is a simple Java program.");
}
}
Compiling The Program
Compile the Example program, as shown below:
C:>javac MyProgram.java
The javac compiler creates a file called MyProgram.class that contains the
ByteCode version of the program.
The Java ByteCode is the intermediate representation of your program
that contains instructions the Java interpreter will execute. Thus, the
output of javac is not code that can be directly executed.
Executing The Program
To actually run the program, you must use the Java interpreter, called
java.
To do so, pass the class name Example as a command-line
argument, as shown here:
C:>java MyProgram
When the program runs, the following console output is displayed:
This is a simple Java program.
Executing The Program
Because the Java VM is available on many
different operating systems, the same
.class files are capable of running on:
Microsoft Windows,
Solaris TM Operating System (Solaris OS),
Linux,
Mac OS.
class MyProgram {
This line uses the keyword class to declare that a new class is being
defined.
MyProgram is an identifier that is the name of the class.
The entire class definition, including all of its members, will be between
the opening curly brace “{“ and the closing curly brace “}”.
This is one reason why all Java programs are pure object-oriented.
A Java class name is an identifier—a series of characters consisting of
letters, digits, underscores ( _ ) and dollar signs ($ ) that does not begin
with a digit and does not contain spaces
public static void main(String args[]) {
This line begins the main( ) method.
As the comment preceding it suggests, this is the line at which the
program will begin executing.
All Java applications begin execution by calling main( ). (This is just
like C/C++.)
public
The public keyword is an access specifier, which allows the
programmer to control the visibility of class members.
When a class member is preceded by public, then that member may
be accessed by code outside the class in which it is declared.
In this case, main( ) must be declared as public, since it must be
called by code outside of its class when the program is started.
void & static
The keyword static allows main( ) to be called without having to
instantiate a particular instance of the class.
This is necessary since main( ) is called by the Java interpreter
before any objects are made.
The keyword void simply tells the compiler that main( ) does not
return a value.
main()
main( ) is the method called when a Java application begins.
Keep in mind that Java is case-sensitive. Thus, Main is different from
main. It is important to understand that the Java compiler will
compile classes that do not contain a main( ) method.
But the Java interpreter has no way to run these classes.
So, if you had typed Main instead of main, the compiler would still
compile your program. However, the Java interpreter would report
an error because it would be unable to find the main( ) method.
Parameter
Any information that you need to pass to a method is received by
variables specified within the set of parentheses that follow the
name of the method.
These variables are called parameters.
If there are no parameters required for a given method, you still
need to include the empty parentheses.
Parameter…
In main( ), there is only one parameter. String args[ ] declares a
parameter named args, which is an array of instances of the class
String.
Objects of type String store character strings. In this case, args
receives any command-line arguments present when the program is
executed.
main() revisited…
One other point:
main( ) is simply a starting place for your program.
So a complex program will have dozens of classes, only one of which
will need to have a main( ) method to get things started.
System.out.println("This is a simple Java program.");
This line outputs the string “This is a simple Java program.”
followed by a new line on the screen.
Output is actually accomplished by the built-in println( ) method.
In this case, println( ) displays the string which is passed to it.
System is a predefined class that provides access to the system, and
out is the output stream.
Example 2
class Example2{
public static void main(String args[]) {
System.out.print(“Welcome to ”);
System.out.println("Java programing course.");
System.out.printf( "%sn%sn", "Welcome to", "Java Programming!" );}
}
Differentiate between print, println & printf built-in methods?
Format Specifier with printf()
Format Specifiers are used with printf method, and begin with a percent
sign (%) followed by a character that represents the data type.
For example, the format specifier %s is a placeholder for a string
Each format specifier is a placeholder for a value and specifies the type of
data to output
%d = Integer
%c = Character
%s = String
%f = Float

More Related Content

What's hot

Lecture 3 java basics
Lecture 3 java basicsLecture 3 java basics
Lecture 3 java basicsthe_wumberlog
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsQUONTRASOLUTIONS
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz SAurabh PRajapati
 
Java Presentation
Java PresentationJava Presentation
Java Presentationpm2214
 
Java review00
Java review00Java review00
Java review00saryu2011
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Mr. Akaash
 
An Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeAn Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeOmar Bashir
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For SyntaxPravinYalameli
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technologysshhzap
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java TutorialJava2Blog
 

What's hot (19)

Lecture 3 java basics
Lecture 3 java basicsLecture 3 java basics
Lecture 3 java basics
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutions
 
Java notes
Java notesJava notes
Java notes
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Java review00
Java review00Java review00
Java review00
 
Java introduction
Java introductionJava introduction
Java introduction
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
An Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeAn Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and Runtime
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
 
Java & advanced java
Java & advanced javaJava & advanced java
Java & advanced java
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Java architecture
Java architectureJava architecture
Java architecture
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Core Java
Core JavaCore Java
Core Java
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 

Similar to Mpl 1 (20)

OOPS JAVA.pdf
OOPS JAVA.pdfOOPS JAVA.pdf
OOPS JAVA.pdf
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
 
Java
JavaJava
Java
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
 
Programming in Java
Programming in JavaProgramming in Java
Programming in Java
 
java intro.pptx
java intro.pptxjava intro.pptx
java intro.pptx
 
OOP-Chap2.docx
OOP-Chap2.docxOOP-Chap2.docx
OOP-Chap2.docx
 
INTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATIONINTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATION
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java lab1 manual
Java lab1 manualJava lab1 manual
Java lab1 manual
 
Top 10 Important Core Java Interview questions and answers.pdf
Top 10 Important Core Java Interview questions and answers.pdfTop 10 Important Core Java Interview questions and answers.pdf
Top 10 Important Core Java Interview questions and answers.pdf
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Curso de Programación Java Básico
Curso de Programación Java BásicoCurso de Programación Java Básico
Curso de Programación Java Básico
 
Java-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oopsJava-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oops
 
JAVA for Every one
JAVA for Every oneJAVA for Every one
JAVA for Every one
 

Recently uploaded

IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

Mpl 1

  • 2. Introduction Java is a High Level programming Language. The first name of Java was Oak, developed in 1991 by Sun Microsystems. In 1995, it was renamed as Java. A key goal of Java is to be able to write programs that: will run on a great variety of computer systems and computer-control devices. This is sometimes called “write once, run anywhere.”
  • 3. Java Platform The Java platform differs from most other platforms in that it's a software- only platform that runs on top of other hardware-based platforms. The Java platform has two components: The Java Virtual Machine (JVM) The Java Application Programming Interface (API) [Built-in Java class libraries] The Java Virtual Machine; it's the base for the Java platform and is ported onto various hardware-based platforms.
  • 4. Why Choose Java(Features)? Simple: ◦ Programming notation of Java is not different from the programming language like C and C++ which makes it easier to learn Java. Object-oriented: ◦ Java is pure object oriented programming language
  • 5. Why Choose Java(Features)? Secure: ◦ Java program run under the control of JVM, do not instructs the commands directly to the machine like C/C++ ◦ This way any program tries to get illegal access to the system will not be allowed by the JVM. Allowing Java programs to be executed by the JVM makes Java program fully secured under the control of the JVM. Portable: ◦ Java programs are portable because of its ability to run the program on any platform and no dependency on the underlying hardware / operating system.
  • 6. Why Choose Java(Features)? Multithreaded: ◦ Java allows you to develop program that can do multiple task simultaneously Architecture-Neutral: ◦ Java code does not depend on the underlying architecture and only depends on it JVM thus accomplish the architecture neutral programming language.
  • 7. Why Choose Java(Features)? Interpreted: ◦ The compiled code of Java is not machine instructions but rather its a intermediate code called ByteCode. This code can be executed on any machine that implements the Java virtual Machine. JVM interprets the ByteCode into Machine instructions during runtime. Performance: ◦ JVM interpret only the piece of the code that is required to execute and untouch the rest of the code. The performance of java is never questioned compared with another programming language.
  • 8. Java is Architecture Neutral! The most important advantage of java over other programming Languages is that, Java is Architecture Neutral. This means that a Program written in java can be run by “Any Machine” having “Any operating System”. Java is platform-independent language
  • 9. Java’s Magic(JVM & ByteCode) Java program is first compiled and then it is interpreted. When a java program is compiled, it is then converted into bytecode. Byte code is intermediate code. Byte code is a set of instructions designed to be executed by the JVM
  • 10. Java’s Magic(JVM & ByteCode) JVM stands for the Java Virtual Machine. The JVM is interpreter for java byte code. Job of JVM is to read this ByteCode and convert into machine dependent instructions. So, JVM’s needs to be platform specific but not the developers code.
  • 11. Java’s Magic(JVM & ByteCode)
  • 12. JVM vs ByteCode JVM is platform dependent while ByteCode is not JVM needs to be pre-installed on the machine for executing java program. There are different version of JVM available in the market to support variety of platform
  • 13. Downloading & Installing JDK / Netbeans Java Development Toolkit (JDK) Java SE 7 Java SE 8 www.oracle.com/technetwork/java/javase/downloads Netbeans Bundled with JDK Can also get at netbeans.org/downloads
  • 14. Phases of Java Program Java programs normally go through five phases: Edit Compile Load Verify Execute
  • 15. Phase 1&2: Edit & Compile
  • 16. Phase 3: Loading a Program into Memory
  • 17. Phase 4: ByteCode Verification
  • 19. Your First Java Program class MyProgram { public static void main(String args[]) { System.out.println("This is a simple Java program."); } }
  • 20. Compiling The Program Compile the Example program, as shown below: C:>javac MyProgram.java The javac compiler creates a file called MyProgram.class that contains the ByteCode version of the program. The Java ByteCode is the intermediate representation of your program that contains instructions the Java interpreter will execute. Thus, the output of javac is not code that can be directly executed.
  • 21. Executing The Program To actually run the program, you must use the Java interpreter, called java. To do so, pass the class name Example as a command-line argument, as shown here: C:>java MyProgram When the program runs, the following console output is displayed: This is a simple Java program.
  • 22. Executing The Program Because the Java VM is available on many different operating systems, the same .class files are capable of running on: Microsoft Windows, Solaris TM Operating System (Solaris OS), Linux, Mac OS.
  • 23.
  • 24. class MyProgram { This line uses the keyword class to declare that a new class is being defined. MyProgram is an identifier that is the name of the class. The entire class definition, including all of its members, will be between the opening curly brace “{“ and the closing curly brace “}”. This is one reason why all Java programs are pure object-oriented. A Java class name is an identifier—a series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ($ ) that does not begin with a digit and does not contain spaces
  • 25. public static void main(String args[]) { This line begins the main( ) method. As the comment preceding it suggests, this is the line at which the program will begin executing. All Java applications begin execution by calling main( ). (This is just like C/C++.)
  • 26. public The public keyword is an access specifier, which allows the programmer to control the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared. In this case, main( ) must be declared as public, since it must be called by code outside of its class when the program is started.
  • 27. void & static The keyword static allows main( ) to be called without having to instantiate a particular instance of the class. This is necessary since main( ) is called by the Java interpreter before any objects are made. The keyword void simply tells the compiler that main( ) does not return a value.
  • 28. main() main( ) is the method called when a Java application begins. Keep in mind that Java is case-sensitive. Thus, Main is different from main. It is important to understand that the Java compiler will compile classes that do not contain a main( ) method. But the Java interpreter has no way to run these classes. So, if you had typed Main instead of main, the compiler would still compile your program. However, the Java interpreter would report an error because it would be unable to find the main( ) method.
  • 29. Parameter Any information that you need to pass to a method is received by variables specified within the set of parentheses that follow the name of the method. These variables are called parameters. If there are no parameters required for a given method, you still need to include the empty parentheses.
  • 30. Parameter… In main( ), there is only one parameter. String args[ ] declares a parameter named args, which is an array of instances of the class String. Objects of type String store character strings. In this case, args receives any command-line arguments present when the program is executed.
  • 31. main() revisited… One other point: main( ) is simply a starting place for your program. So a complex program will have dozens of classes, only one of which will need to have a main( ) method to get things started.
  • 32. System.out.println("This is a simple Java program."); This line outputs the string “This is a simple Java program.” followed by a new line on the screen. Output is actually accomplished by the built-in println( ) method. In this case, println( ) displays the string which is passed to it. System is a predefined class that provides access to the system, and out is the output stream.
  • 33. Example 2 class Example2{ public static void main(String args[]) { System.out.print(“Welcome to ”); System.out.println("Java programing course."); System.out.printf( "%sn%sn", "Welcome to", "Java Programming!" );} } Differentiate between print, println & printf built-in methods?
  • 34. Format Specifier with printf() Format Specifiers are used with printf method, and begin with a percent sign (%) followed by a character that represents the data type. For example, the format specifier %s is a placeholder for a string Each format specifier is a placeholder for a value and specifies the type of data to output %d = Integer %c = Character %s = String %f = Float