SlideShare uma empresa Scribd logo
1 de 20
CMP-2123 Object Oriented Programming
OOP with Java
Lecture # 1
History
• In 1991, Java was developed by a team led by James Gosling and
Sun Microsystems for use in embedded chips.
• Sun microsystems was purchased by oracle (Oak) in 2010.
• Java, May 20, 1995, Sun World, redesigned for web applications.
• HotJava ( first Java-enabled Web browser )
Version History of Java
Features of Java
• Java is simple
• Java is object-oriented
• Java is distributed
• Java is interpreted
• Java is robust
• Java is secure
• Java is portable
• Java’s performance
• Java is multithreaded
• Java has garbage
Collector
Java Features (1)
Simple
• fixes some clumsy features of C++
• no pointers
• automatic garbage collection
• rich pre-defined class library
Object oriented
• focus on the data (objects) and methods manipulating the data
• all functions are associated with objects
• almost all data types are objects (files, strings, etc.)
• potentially better code organization and reuse
Java Features (2)
Interpreted
• java compiler generate byte-codes, not native machine code
• the compiled byte-codes are platform-independent
• java bytecodes are translated on the fly to machine readable
instructions in runtime (Java Virtual Machine)
Portable
• same application runs on all platforms
• the sizes of the primitive data types are always the same
Java Features (3)
Reliable
• extensive compile-time and runtime error checking
• no pointers. Memory corruptions or unauthorized memory
accesses are impossible
• automatic garbage collection tracks objects usage over time
Secure
• usage in networked environments requires more security
• memory allocation model is a major defense
• access restrictions are forced (private, public)
Java Features (4)
Multithreaded
• multiple concurrent threads of executions can run
simultaneously
• utilizes a sophisticated set of synchronization primitives (based
on monitors and condition variables paradigm) to achieve this
Java Disadvantages
Slower than compiled language such as C
• an experiment in 1999 showed that Java was 3 or 4 times slower than C or C++
• title of the article: “Comparing Java vs. C/C++ Efficiency Issues to Interpersonal
Issues” (Lutz Prechelt)
• adequate for all but the most time-intensive programs
JDK Editions
• Java Standard Edition (J2SE)
J2SE can be used to develop client-side standalone applications or
applets.
• Java Enterprise Edition (J2EE)
J2EE can be used to develop server-side applications such as Java
servlets and Java ServerPages.
• Java Micro Edition (J2ME).
J2ME can be used to develop applications for mobile devices such as
cell phones.
Java Applet
• Java programs can be run from a Web browser. Such programs are
called applets. Applets employ a modern graphical interface with
buttons, text fields, text areas, radio buttons, and so on, to interact
with users on the Web and process their requests.
• You can use a Java development tool (e.g., NetBeans, Eclipse, and
Text Pad)—software that provides an integrated development
environment (IDE) for developing Java programs quickly.
Compile and Run
Creating..Compiling .. Executing
Source Code
Create/Modify Source
Code
Bytecode
Run Byteode
i.e. java Welcome
Result
Compile Source Code
i.e. javac Welcome.java
If compilation errors
If runtime errors or
incorrect result
Java
Interpreter
on Windows
Java
Interpreter
on Sun Solaris
Java
Interpreter
on Linux
Bytecode
...
Java is case sensitive
1. // Your First Program
2. class HelloWorld
{
3. public static void
main(String[] args)
{
4.
System.out.println("Hello
, World!");
}
}
In line 1; In Java, any line starting
with // is a comment
In line 2; in the program, HelloWorld is
the name of the class, and the class
definition is: class helloworld
In line 3; This is the main method.
Every application in Java must contain
the main method. The Java compiler
starts executing the code from the
main method.
In line 4; The code above is a print
statement. It prints the text Hello,
World! to standard output (your
screen). The text inside the quotation
marks is called String in Java.
Anatomy of a Java Program
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 */.
Package :
The second line in the program (package javaapplication1;) specifies a package
name, javaapplication1, for the class javaapplication1. It compiles the source code
in javaapplication1.java, generates javaapplication1.class, and stores
javaapplication1.class in the javaapplication1 folder.
Anatomy of a Java Program
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 are public, static, and voidetc.
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 through reserve
words
CE&ME, NUST
Anatomy of a Java Program
Statements:
A statement represents an action or a sequence of actions. The statement
System.out.println(“Hello Java world!") in the program in Example is a statement
to display the greeting " Hello Java world! “. Every statement in Java ends with a
semicolon (;).
Blocks:
A pair of braces in a program forms a block that groups components of aprogram.
public class JavaApplication1 {
public static void main(String[] args) {
System.out.println("Hello Java World !");
}
}
Class block
Meth
CE&ME, NUST
od block
Assignment:
Reserved word vs Modifiers
Package vs libraries
JVM version
JVM vs JDK

Mais conteúdo relacionado

Semelhante a OOP with Java

Semelhante a OOP with Java (20)

Java1
Java1Java1
Java1
 
Java
Java Java
Java
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Java intro
Java introJava intro
Java intro
 
Core java
Core javaCore java
Core java
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Lecture - 1 introduction to java
Lecture - 1 introduction to javaLecture - 1 introduction to java
Lecture - 1 introduction to java
 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdf
 
JAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptxJAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptx
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
01slide
01slide01slide
01slide
 
01slide
01slide01slide
01slide
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
java slides
java slidesjava slides
java slides
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to Java
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Java ms harsha
Java ms harshaJava ms harsha
Java ms harsha
 

Último

Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night StandCall Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
only4webmaster01
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
amitlee9823
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
amitlee9823
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 

Último (20)

5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night StandCall Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 

OOP with Java

  • 1. CMP-2123 Object Oriented Programming OOP with Java Lecture # 1
  • 2. History • In 1991, Java was developed by a team led by James Gosling and Sun Microsystems for use in embedded chips. • Sun microsystems was purchased by oracle (Oak) in 2010. • Java, May 20, 1995, Sun World, redesigned for web applications. • HotJava ( first Java-enabled Web browser )
  • 4.
  • 5. Features of Java • Java is simple • Java is object-oriented • Java is distributed • Java is interpreted • Java is robust • Java is secure • Java is portable • Java’s performance • Java is multithreaded • Java has garbage Collector
  • 6. Java Features (1) Simple • fixes some clumsy features of C++ • no pointers • automatic garbage collection • rich pre-defined class library Object oriented • focus on the data (objects) and methods manipulating the data • all functions are associated with objects • almost all data types are objects (files, strings, etc.) • potentially better code organization and reuse
  • 7. Java Features (2) Interpreted • java compiler generate byte-codes, not native machine code • the compiled byte-codes are platform-independent • java bytecodes are translated on the fly to machine readable instructions in runtime (Java Virtual Machine) Portable • same application runs on all platforms • the sizes of the primitive data types are always the same
  • 8. Java Features (3) Reliable • extensive compile-time and runtime error checking • no pointers. Memory corruptions or unauthorized memory accesses are impossible • automatic garbage collection tracks objects usage over time Secure • usage in networked environments requires more security • memory allocation model is a major defense • access restrictions are forced (private, public)
  • 9. Java Features (4) Multithreaded • multiple concurrent threads of executions can run simultaneously • utilizes a sophisticated set of synchronization primitives (based on monitors and condition variables paradigm) to achieve this
  • 10. Java Disadvantages Slower than compiled language such as C • an experiment in 1999 showed that Java was 3 or 4 times slower than C or C++ • title of the article: “Comparing Java vs. C/C++ Efficiency Issues to Interpersonal Issues” (Lutz Prechelt) • adequate for all but the most time-intensive programs
  • 11. JDK Editions • Java Standard Edition (J2SE) J2SE can be used to develop client-side standalone applications or applets. • Java Enterprise Edition (J2EE) J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. • Java Micro Edition (J2ME). J2ME can be used to develop applications for mobile devices such as cell phones.
  • 12. Java Applet • Java programs can be run from a Web browser. Such programs are called applets. Applets employ a modern graphical interface with buttons, text fields, text areas, radio buttons, and so on, to interact with users on the Web and process their requests. • You can use a Java development tool (e.g., NetBeans, Eclipse, and Text Pad)—software that provides an integrated development environment (IDE) for developing Java programs quickly.
  • 14. Creating..Compiling .. Executing Source Code Create/Modify Source Code Bytecode Run Byteode i.e. java Welcome Result Compile Source Code i.e. javac Welcome.java If compilation errors If runtime errors or incorrect result Java Interpreter on Windows Java Interpreter on Sun Solaris Java Interpreter on Linux Bytecode ...
  • 15. Java is case sensitive
  • 16. 1. // Your First Program 2. class HelloWorld { 3. public static void main(String[] args) { 4. System.out.println("Hello , World!"); } } In line 1; In Java, any line starting with // is a comment In line 2; in the program, HelloWorld is the name of the class, and the class definition is: class helloworld In line 3; This is the main method. Every application in Java must contain the main method. The Java compiler starts executing the code from the main method. In line 4; The code above is a print statement. It prints the text Hello, World! to standard output (your screen). The text inside the quotation marks is called String in Java.
  • 17. Anatomy of a Java Program 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 */. Package : The second line in the program (package javaapplication1;) specifies a package name, javaapplication1, for the class javaapplication1. It compiles the source code in javaapplication1.java, generates javaapplication1.class, and stores javaapplication1.class in the javaapplication1 folder.
  • 18. Anatomy of a Java Program 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 are public, static, and voidetc. 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 through reserve words CE&ME, NUST
  • 19. Anatomy of a Java Program Statements: A statement represents an action or a sequence of actions. The statement System.out.println(“Hello Java world!") in the program in Example is a statement to display the greeting " Hello Java world! “. Every statement in Java ends with a semicolon (;). Blocks: A pair of braces in a program forms a block that groups components of aprogram. public class JavaApplication1 { public static void main(String[] args) { System.out.println("Hello Java World !"); } } Class block Meth CE&ME, NUST od block
  • 20. Assignment: Reserved word vs Modifiers Package vs libraries JVM version JVM vs JDK

Notas do Editor

  1. The code above is a print statement. It prints the text Hello, World! to standard output (your screen). The text inside the quotation marks is called String in Java.
  2. // This is a comment System.out.println("Hello World"); /* The code below will print the words Hello World to the screen, and it is amazing */ System.out.println("Hello World");