SlideShare uma empresa Scribd logo
1 de 31
Introduction to
Java Programming
T.LOGESWARI
What is Java
• Java is a programming language and a platform.
• Java is a high level, robust, secured and object-
oriented programming language.
• Platform: Any hardware or software
environment in which a program runs, is known
as a platform. Since Java has its own runtime
environment (JRE) and API, it is called platform.
•
2
Where it is used?
• According to Sun, 3 billion devices run java. There are
many devices where java is currently used. Some of
them are as follows:
• Desktop Applications such as acrobat reader, media
player, antivirus etc.
• Web Applications such as irctc.co.in, javatpoint.com
etc.
• Enterprise Applications such as banking applications.
• Mobile
• Embedded System
• Smart Card
• Robotics
• Games etc.
3
Java Applications
• We can develop four types of Java programs:
– Stand-alone applications
– Web applications (applets)
– Enterprise Application
– Mobile Application
Types of Java Applications
1) Standalone Application
• It is also known as desktop application or
window-based application.
• An application that we need to install on every
machine such as media player, antivirus etc.
• AWT and Swing are used in java for creating
standalone applications.
2) Web Application
• An application that runs on the server side and
creates dynamic page, is called web application.
• Currently, servlet, jsp, struts, jsf etc. technologies
are used for creating web applications in java.
5
3) Enterprise Application
• An application that is distributed in nature, such
as banking applications etc.
• It has the advantage of high level security, load
balancing and clustering.
• In java, EJB is used for creating enterprise
applications.
4) Mobile Application
• An application that is created for mobile devices.
• Currently Android and Java ME are used for
creating mobile applications.
6
Applets v/s Applications
• Different ways to run a Java executable are
Application- A stand-alone program that can be
invoked from command line . A program that has
a “mainmain” method
Applet- A program embedded in a web page , to
be run when the page is browsed . A program
that contains no “main” method
• Application –Executed by the Java interpreter.
• Applet- Java enabled web browser.
Java is Compiled and Interpreted
Text Editor Compiler Interpreter
Programmer
Source Code
.java file
Byte Code
.class file
Hardware and
Operating System
Notepad,
emacs,vi
javac java
appletviewer
netscape
Compiled Languages
Text Editor Compiler linker
Programmer
Source Code
.c file
Object
Code
.o file
Notepad,
emacs,vi
gcc
Executable
Code
a.out file
Total Platform Independence
JAVA COMPILERJAVA COMPILER
JAVA BYTE CODEJAVA BYTE CODE
JAVA INTERPRETERJAVA INTERPRETER
Windows 95 Macintosh Solaris Windows NT
(translator)
(same for all platforms)
(one for each different system)
Architecture Neutral & Portable
• Java Compiler - Java source code (file with
extension .java) to bytecode (file with
extension .class)
• Bytecode - an intermediate form, closer to
machine representation
• A interpreter (virtual machine) on any target
platform interprets the bytecode.
Getting Started with Java
Programming
• A Simple Java Application
• Compiling Programs
• Executing Applications
12
A Simple Application
Example 1.1
//This application program prints Welcome
//to Java!
package chapter1;
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
13
RunRunSourceSource
NOTE: To run the program,
install slide files on hard
disk.
Creating and Compiling Programs
• On command line
– javac file.java
14
Source Code
Create/Modify Source Code
Compile Source Code
i.e. javac Welcome.java
Bytecode
Run Byteode
i.e. java Welcome
Result
If compilation errors
If runtime errors or incorrect result
Executing Applications
• On command line
– java classname
15
Java
Interpreter
on Windows
Java
Interpreter
on Sun Solaris
Java
Interpreter
on Linux
Bytecode
...
Example
javac Welcome.java
java Welcome
output:...
16
Anatomy of a Java Program
• Comments
• Package
• Reserved words
• Modifiers
• Statements
• Blocks
• Classes
• Methods
• The main method
17
Comments
•In Java, comments are preceded by two slashes (//) in a line, or
enclosed between /* and */ in one or multiple lines.
•When the compiler sees //, it ignores all text after // in the same line.
• When it sees /*, it scans for the next */ and ignores any text
between /* and */.
18
Package
•The second line in the program (package chapter1;) specifies a
package name, chapter1, for the class Welcome.
• Forte compiles the source code in Welcome.java, generates
Welcome.class, and stores Welcome.class in the chapter1 folder.
19
Reserved Words
•Reserved words or keywords are words that have a specific meaning to
the compiler and cannot be used for other purposes in the program.
• For example, when the compiler sees the word class, it understands
that the word after class is the name for the class.
•Other reserved words in Example 1.1 are public, static, and void.
20
Modifiers
•Java uses certain reserved words called modifiers that specify the
properties of the data, methods, and classes and how they can be used.
• Examples of modifiers are public and static. Other modifiers are
private, final, abstract, and protected.
•A public datum, method, or class can be accessed by other programs.
• A private datum or method cannot be accessed by other programs.
21
Statements
•A statement represents an action or a sequence of actions.
•The statement System.out.println("Welcome to Java!") in the program
in Example 1.1 is a statement to display the greeting "Welcome to
Java!" Every statement in Java ends with a semicolon (;).
22
Blocks
23
•A pair of braces in a program forms a block that groups components of
a program.
public class Test {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
Class block
Method block
Classes
•The class is the essential Java construct.
•A class is a template or blueprint for objects.
• To program in Java, you must understand classes and be able to write
and use them.
•For now, though, understand that a program is defined by using one or
more classes.
24
Methods
What is System.out.println?
•It is a method: a collection of statements that performs a sequence of
operations to display a message on the console.
• It can be used even without fully understanding the details of how it works.
•It is used by invoking a statement with a string argument.
•The string argument is enclosed within parentheses. In this case, the
argument is "Welcome to Java!" You can call the same println method with a
different argument to print a different message.
25
main Method
•The main method provides the control of program flow. The Java interpreter
executes the application by invoking the main method.
•The main method looks like this:
public static void main(String[] args) {
// Statements;
}
26
Program Processing
• Compilation
# javac hello.java
results in HelloInternet.class
• Execution
# java HelloInternet
Hello Internet
#
Summary
• class keyword is used to declare a class in java.
• public keyword is an access modifier which
represents visibility, it means it is visible to all.
• static is a keyword, if we declare any method as
static, it is known as static method.
– The core advantage of static method is that there is
no need to create object to invoke the static method.
– The main method is executed by the JVM, so it
doesn't require to create object to invoke the main
method. So it saves memory.
28
• void is the return type of the method, it
means it doesn't return any value.
• main represents startup of the program.
• String[] args is used for command line
argument.
• System.out.println() is used print statement.
29
• What happens at compile time?
• At compile time, java file is compiled by Java
Compiler (It does not interact with OS) and
converts the java code into bytecode.
30
• What happens at runtime?
• At runtime, following steps are performed:
31
Classloader: is the subsystem of JVM that
is used to load class files.
Bytecode  Verifier: checks the code
fragments for illegal code that can violate
access right to objects.
Interpreter: read bytecode stream then
execute the instructions.

Mais conteúdo relacionado

Mais procurados (19)

Learn Java Part 1
Learn Java Part 1Learn Java Part 1
Learn Java Part 1
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
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...
 
core java
core javacore java
core java
 
Java introduction
Java introductionJava introduction
Java introduction
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
 
Features of java - javatportal
Features of java - javatportalFeatures of java - javatportal
Features of java - javatportal
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java essential notes
Java essential notesJava essential notes
Java essential notes
 
JVM
JVMJVM
JVM
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Java architecture
Java architectureJava architecture
Java architecture
 
Java features
Java featuresJava features
Java features
 
Java & advanced java
Java & advanced javaJava & advanced java
Java & advanced java
 
Java byte code presentation
Java byte code presentationJava byte code presentation
Java byte code presentation
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
JAVA Program Examples
JAVA Program ExamplesJAVA Program Examples
JAVA Program Examples
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Java notes
Java notesJava notes
Java notes
 

Semelhante a Java introduction (20)

JAVA PROGRAMMING-Unit I - Final PPT.pptx
JAVA PROGRAMMING-Unit I - Final PPT.pptxJAVA PROGRAMMING-Unit I - Final PPT.pptx
JAVA PROGRAMMING-Unit I - Final PPT.pptx
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
unit1.pptx
unit1.pptxunit1.pptx
unit1.pptx
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdf
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
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
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
 
Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
 
java intro.pptx
java intro.pptxjava intro.pptx
java intro.pptx
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
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
 

Mais de logeswarisaravanan

unit II Mining Association Rule.pdf
unit II Mining   Association    Rule.pdfunit II Mining   Association    Rule.pdf
unit II Mining Association Rule.pdflogeswarisaravanan
 
Data Mining Appliction chapter 5.pdf
Data Mining  Appliction    chapter 5.pdfData Mining  Appliction    chapter 5.pdf
Data Mining Appliction chapter 5.pdflogeswarisaravanan
 
Chapter 2 Data Preprocessing part3.ppt
Chapter 2  Data  Preprocessing part3.pptChapter 2  Data  Preprocessing part3.ppt
Chapter 2 Data Preprocessing part3.pptlogeswarisaravanan
 
Introduction-to-DBMS-and-Data-Mining.pptx
Introduction-to-DBMS-and-Data-Mining.pptxIntroduction-to-DBMS-and-Data-Mining.pptx
Introduction-to-DBMS-and-Data-Mining.pptxlogeswarisaravanan
 
Introduction-to-Text-Classification.pptx
Introduction-to-Text-Classification.pptxIntroduction-to-Text-Classification.pptx
Introduction-to-Text-Classification.pptxlogeswarisaravanan
 
Fundamentals of Data Science: Introduction.pptx
Fundamentals of Data Science:  Introduction.pptxFundamentals of Data Science:  Introduction.pptx
Fundamentals of Data Science: Introduction.pptxlogeswarisaravanan
 
UNIT 4 E Introduction to linear model.pptx
UNIT 4 E Introduction to linear model.pptxUNIT 4 E Introduction to linear model.pptx
UNIT 4 E Introduction to linear model.pptxlogeswarisaravanan
 
A Introduction-to-Forms-of-Learning.pptx
A Introduction-to-Forms-of-Learning.pptxA Introduction-to-Forms-of-Learning.pptx
A Introduction-to-Forms-of-Learning.pptxlogeswarisaravanan
 
AI: Introduction-to-Goal-Based-Agents.pptx
AI: Introduction-to-Goal-Based-Agents.pptxAI: Introduction-to-Goal-Based-Agents.pptx
AI: Introduction-to-Goal-Based-Agents.pptxlogeswarisaravanan
 
Artificial Intelligence: Intelligent Agents
Artificial Intelligence: Intelligent AgentsArtificial Intelligence: Intelligent Agents
Artificial Intelligence: Intelligent Agentslogeswarisaravanan
 

Mais de logeswarisaravanan (10)

unit II Mining Association Rule.pdf
unit II Mining   Association    Rule.pdfunit II Mining   Association    Rule.pdf
unit II Mining Association Rule.pdf
 
Data Mining Appliction chapter 5.pdf
Data Mining  Appliction    chapter 5.pdfData Mining  Appliction    chapter 5.pdf
Data Mining Appliction chapter 5.pdf
 
Chapter 2 Data Preprocessing part3.ppt
Chapter 2  Data  Preprocessing part3.pptChapter 2  Data  Preprocessing part3.ppt
Chapter 2 Data Preprocessing part3.ppt
 
Introduction-to-DBMS-and-Data-Mining.pptx
Introduction-to-DBMS-and-Data-Mining.pptxIntroduction-to-DBMS-and-Data-Mining.pptx
Introduction-to-DBMS-and-Data-Mining.pptx
 
Introduction-to-Text-Classification.pptx
Introduction-to-Text-Classification.pptxIntroduction-to-Text-Classification.pptx
Introduction-to-Text-Classification.pptx
 
Fundamentals of Data Science: Introduction.pptx
Fundamentals of Data Science:  Introduction.pptxFundamentals of Data Science:  Introduction.pptx
Fundamentals of Data Science: Introduction.pptx
 
UNIT 4 E Introduction to linear model.pptx
UNIT 4 E Introduction to linear model.pptxUNIT 4 E Introduction to linear model.pptx
UNIT 4 E Introduction to linear model.pptx
 
A Introduction-to-Forms-of-Learning.pptx
A Introduction-to-Forms-of-Learning.pptxA Introduction-to-Forms-of-Learning.pptx
A Introduction-to-Forms-of-Learning.pptx
 
AI: Introduction-to-Goal-Based-Agents.pptx
AI: Introduction-to-Goal-Based-Agents.pptxAI: Introduction-to-Goal-Based-Agents.pptx
AI: Introduction-to-Goal-Based-Agents.pptx
 
Artificial Intelligence: Intelligent Agents
Artificial Intelligence: Intelligent AgentsArtificial Intelligence: Intelligent Agents
Artificial Intelligence: Intelligent Agents
 

Último

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Java introduction

  • 2. What is Java • Java is a programming language and a platform. • Java is a high level, robust, secured and object- oriented programming language. • Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has its own runtime environment (JRE) and API, it is called platform. • 2
  • 3. Where it is used? • According to Sun, 3 billion devices run java. There are many devices where java is currently used. Some of them are as follows: • Desktop Applications such as acrobat reader, media player, antivirus etc. • Web Applications such as irctc.co.in, javatpoint.com etc. • Enterprise Applications such as banking applications. • Mobile • Embedded System • Smart Card • Robotics • Games etc. 3
  • 4. Java Applications • We can develop four types of Java programs: – Stand-alone applications – Web applications (applets) – Enterprise Application – Mobile Application
  • 5. Types of Java Applications 1) Standalone Application • It is also known as desktop application or window-based application. • An application that we need to install on every machine such as media player, antivirus etc. • AWT and Swing are used in java for creating standalone applications. 2) Web Application • An application that runs on the server side and creates dynamic page, is called web application. • Currently, servlet, jsp, struts, jsf etc. technologies are used for creating web applications in java. 5
  • 6. 3) Enterprise Application • An application that is distributed in nature, such as banking applications etc. • It has the advantage of high level security, load balancing and clustering. • In java, EJB is used for creating enterprise applications. 4) Mobile Application • An application that is created for mobile devices. • Currently Android and Java ME are used for creating mobile applications. 6
  • 7. Applets v/s Applications • Different ways to run a Java executable are Application- A stand-alone program that can be invoked from command line . A program that has a “mainmain” method Applet- A program embedded in a web page , to be run when the page is browsed . A program that contains no “main” method • Application –Executed by the Java interpreter. • Applet- Java enabled web browser.
  • 8. Java is Compiled and Interpreted Text Editor Compiler Interpreter Programmer Source Code .java file Byte Code .class file Hardware and Operating System Notepad, emacs,vi javac java appletviewer netscape
  • 9. Compiled Languages Text Editor Compiler linker Programmer Source Code .c file Object Code .o file Notepad, emacs,vi gcc Executable Code a.out file
  • 10. Total Platform Independence JAVA COMPILERJAVA COMPILER JAVA BYTE CODEJAVA BYTE CODE JAVA INTERPRETERJAVA INTERPRETER Windows 95 Macintosh Solaris Windows NT (translator) (same for all platforms) (one for each different system)
  • 11. Architecture Neutral & Portable • Java Compiler - Java source code (file with extension .java) to bytecode (file with extension .class) • Bytecode - an intermediate form, closer to machine representation • A interpreter (virtual machine) on any target platform interprets the bytecode.
  • 12. Getting Started with Java Programming • A Simple Java Application • Compiling Programs • Executing Applications 12
  • 13. A Simple Application Example 1.1 //This application program prints Welcome //to Java! package chapter1; public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } 13 RunRunSourceSource NOTE: To run the program, install slide files on hard disk.
  • 14. Creating and Compiling Programs • On command line – javac file.java 14 Source Code Create/Modify Source Code Compile Source Code i.e. javac Welcome.java Bytecode Run Byteode i.e. java Welcome Result If compilation errors If runtime errors or incorrect result
  • 15. Executing Applications • On command line – java classname 15 Java Interpreter on Windows Java Interpreter on Sun Solaris Java Interpreter on Linux Bytecode ...
  • 17. Anatomy of a Java Program • Comments • Package • Reserved words • Modifiers • Statements • Blocks • Classes • Methods • The main method 17
  • 18. Comments •In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines. •When the compiler sees //, it ignores all text after // in the same line. • When it sees /*, it scans for the next */ and ignores any text between /* and */. 18
  • 19. Package •The second line in the program (package chapter1;) specifies a package name, chapter1, for the class Welcome. • Forte compiles the source code in Welcome.java, generates Welcome.class, and stores Welcome.class in the chapter1 folder. 19
  • 20. Reserved Words •Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. • For example, when the compiler sees the word class, it understands that the word after class is the name for the class. •Other reserved words in Example 1.1 are public, static, and void. 20
  • 21. Modifiers •Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. • Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. •A public datum, method, or class can be accessed by other programs. • A private datum or method cannot be accessed by other programs. 21
  • 22. Statements •A statement represents an action or a sequence of actions. •The statement System.out.println("Welcome to Java!") in the program in Example 1.1 is a statement to display the greeting "Welcome to Java!" Every statement in Java ends with a semicolon (;). 22
  • 23. Blocks 23 •A pair of braces in a program forms a block that groups components of a program. public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Class block Method block
  • 24. Classes •The class is the essential Java construct. •A class is a template or blueprint for objects. • To program in Java, you must understand classes and be able to write and use them. •For now, though, understand that a program is defined by using one or more classes. 24
  • 25. Methods What is System.out.println? •It is a method: a collection of statements that performs a sequence of operations to display a message on the console. • It can be used even without fully understanding the details of how it works. •It is used by invoking a statement with a string argument. •The string argument is enclosed within parentheses. In this case, the argument is "Welcome to Java!" You can call the same println method with a different argument to print a different message. 25
  • 26. main Method •The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method. •The main method looks like this: public static void main(String[] args) { // Statements; } 26
  • 27. Program Processing • Compilation # javac hello.java results in HelloInternet.class • Execution # java HelloInternet Hello Internet #
  • 28. Summary • class keyword is used to declare a class in java. • public keyword is an access modifier which represents visibility, it means it is visible to all. • static is a keyword, if we declare any method as static, it is known as static method. – The core advantage of static method is that there is no need to create object to invoke the static method. – The main method is executed by the JVM, so it doesn't require to create object to invoke the main method. So it saves memory. 28
  • 29. • void is the return type of the method, it means it doesn't return any value. • main represents startup of the program. • String[] args is used for command line argument. • System.out.println() is used print statement. 29
  • 30. • What happens at compile time? • At compile time, java file is compiled by Java Compiler (It does not interact with OS) and converts the java code into bytecode. 30
  • 31. • What happens at runtime? • At runtime, following steps are performed: 31 Classloader: is the subsystem of JVM that is used to load class files. Bytecode  Verifier: checks the code fragments for illegal code that can violate access right to objects. Interpreter: read bytecode stream then execute the instructions.

Notas do Editor

  1. First Class: Introduction, Prerequisites, Advices, Syllabus Lab 1: Create a Java Project, Compile, and Run. Show syntax errors Print program Capture screen shots, and save it in Word, and print it. Homework One: Check in the class randomly.