SlideShare una empresa de Scribd logo
1 de 24
Introduction to Java
www.proximo.com
Introduction
Present the syntax of Java
Introduce the Java API
Demonstrate how to build
◦ stand-alone Java programs
◦ Java applets, which run within browsers e.g. Netscape
Example programs
Why Java?
It’s the current “hot” language
It’s almost entirely object-oriented
It has a vast library of predefined objects and operations
It’s more platform independent
◦ this makes it great for Web programming
It’s more secure
It isn’t C++
Applets, Servlets and Applications
An applet is designed to be embedded in a Web page, and run by a browser
Applets run in a sandbox with numerous restrictions; for example, they can’t
read files and then use the network
A servlet is designed to be run by a web server
An application is a conventional program
Building Standalone JAVA Programs
(on UNIX)
Prepare the file foo.java using an editor
Invoke the compiler: javac foo.java
This creates foo.class
Run the java interpreter: java foo
Java Virtual Machine
The .class files generated by the compiler are not executable binaries
◦ so Java combines compilation and interpretation
Instead, they contain “byte-codes” to be executed by the Java Virtual Machine
◦ other languages have done this, e.g. UCSD Pascal
This approach provides platform independence, and greater security
HelloWorld (standalone)
Note that String is built in
println is a member function for the System.out class
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Comments are almost like C++
/* This kind of comment can span multiple lines */
// This kind is to the end of the line
/**
* This kind of comment is a special
* ‘javadoc’ style comment
*/
Primitive data types are like C
Main data types are int, double, boolean, char
Also have byte, short, long, float
boolean has values true and false
Declarations look like C, for example,
◦ double x, y;
◦ int count = 0;
Expressions are like C
Assignment statements mostly look like those in C; you can use =, +=, *= etc.
Arithmetic uses the familiar + - * / %
Java also has ++ and --
Java has boolean operators && || !
Java has comparisons < <= == != >= >
Java does not have pointers or pointer arithmetic
Control statements are like C
if (x < y) smaller = x;
if (x < y){ smaller=x;sum += x;}
else { smaller = y; sum += y; }
while (x < y) { y = y - x; }
do { y = y - x; } while (x < y)
for (int i = 0; i < max; i++) sum += i;
BUT: conditions must be boolean !
Control statements II
Java also introduces the try statement, about which more later
switch (n + 1) {
case 0: m = n - 1; break;
case 1: m = n + 1;
case 3: m = m * n; break;
default: m = -n; break;
}
Java isn't C!
In C, almost everything is in functions
In Java, almost everything is in classes
There is often only one class per file
There must be only one public class per file
The file name must be the same as the name of that public class, but with a
.java extension
Java program layout
A typical Java file looks like:
import java.awt.*;
import java.util.*;
public class SomethingOrOther {
// object definitions go here
. . .
}
This must be in a file named SomethingOrOther.java !
What is a class?
Early languages had only arrays
◦ all elements had to be of the same type
Then languages introduced structures (called records, or structs)
◦ allowed different data types to be grouped
Then Abstract Data Types (ADTs) became popular
◦ grouped operations along with the data
So, what is a class?
A class consists of
◦ a collection of fields, or variables, very much like the named fields of a struct
◦ all the operations (called methods) that can be performed on those fields
◦ can be instantiated
A class describes objects and operations defined on those objects
Name conventions
Java is case-sensitive; maxval, maxVal, and MaxVal are three different names
Class names begin with a capital letter
All other names begin with a lowercase letter
Subsequent words are capitalized: theBigOne
Underscores are not used in names
These are very strong conventions!
The class hierarchy
Classes are arranged in a hierarchy
The root, or topmost, class is Object
Every class but Object has at least one superclass
A class may have subclasses
Each class inherits all the fields and methods of its (possibly numerous)
superclasses
An example of a class
class Person {
String name;
int age;
void birthday ( ) {
age++;
System.out.println (name + ' is now '
+ age);
}
}
Another example of a class
class Driver extends Person {
long driversLicenseNumber;
Date expirationDate;
}
Creating and using an object
Person john;
john = new Person ( );
john.name = "John Smith";
john.age = 37;
Person mary = new Person ( );
mary.name = "Mary Brown";
mary.age = 33;
mary.birthday ( );
An array is an object
Person mary = new Person ( );
int myArray[ ] = new int[5];
◦ or:
int myArray[ ] = {1, 4, 9, 16, 25};
String languages [ ] = {"Prolog", "Java"};
www.proximo.in
Address: No:3, II Floor, 100 ft Road,
BTM Layout, II Stage, Bangalore,
Karnataka (560 076) India
Tel: +91 (0)80 4900 1234
Mail: info@proximo.in
CONTACT US
Thanks for watching

Más contenido relacionado

La actualidad más candente

oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
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
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for DesignersR. Sosa
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java Hitesh-Java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaAjay Sharma
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsAnton Keks
 
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaWhat Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaEdureka!
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For SyntaxPravinYalameli
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVAKUNAL GADHIA
 
Multithread Programing in Java
Multithread Programing in JavaMultithread Programing in Java
Multithread Programing in JavaM. Raihan
 

La actualidad más candente (20)

oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
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...
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaWhat Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVA
 
Multithread Programing in Java
Multithread Programing in JavaMultithread Programing in Java
Multithread Programing in Java
 

Destacado

Old navy sales associate perfomance appraisal 2
Old navy sales associate perfomance appraisal 2Old navy sales associate perfomance appraisal 2
Old navy sales associate perfomance appraisal 2tonychoper4304
 
2.26.2014_Northern VA Realtor_Korean Forum 5
2.26.2014_Northern VA Realtor_Korean Forum 52.26.2014_Northern VA Realtor_Korean Forum 5
2.26.2014_Northern VA Realtor_Korean Forum 5Hyojung Garland
 
Executive summary slide
Executive summary slideExecutive summary slide
Executive summary slideericaball19
 
Aprendendo a programar - Programação Procedural vs OOP
Aprendendo a programar - Programação Procedural vs OOPAprendendo a programar - Programação Procedural vs OOP
Aprendendo a programar - Programação Procedural vs OOPLeonardo Bastos
 

Destacado (12)

Deidre CV October 2015 (1)
Deidre CV October 2015 (1)Deidre CV October 2015 (1)
Deidre CV October 2015 (1)
 
CV Sophio Kobakhidze_2015
CV Sophio Kobakhidze_2015CV Sophio Kobakhidze_2015
CV Sophio Kobakhidze_2015
 
Resume
ResumeResume
Resume
 
Old navy sales associate perfomance appraisal 2
Old navy sales associate perfomance appraisal 2Old navy sales associate perfomance appraisal 2
Old navy sales associate perfomance appraisal 2
 
2.26.2014_Northern VA Realtor_Korean Forum 5
2.26.2014_Northern VA Realtor_Korean Forum 52.26.2014_Northern VA Realtor_Korean Forum 5
2.26.2014_Northern VA Realtor_Korean Forum 5
 
Executive summary slide
Executive summary slideExecutive summary slide
Executive summary slide
 
World War
World WarWorld War
World War
 
Proximo Tech Soft
Proximo Tech SoftProximo Tech Soft
Proximo Tech Soft
 
Resume SKP
Resume SKPResume SKP
Resume SKP
 
CATÁLOGO INZEIN
CATÁLOGO INZEINCATÁLOGO INZEIN
CATÁLOGO INZEIN
 
Proximo
ProximoProximo
Proximo
 
Aprendendo a programar - Programação Procedural vs OOP
Aprendendo a programar - Programação Procedural vs OOPAprendendo a programar - Programação Procedural vs OOP
Aprendendo a programar - Programação Procedural vs OOP
 

Similar a Java (20)

java01.ppt
java01.pptjava01.ppt
java01.ppt
 
Java PPt.ppt
Java PPt.pptJava PPt.ppt
Java PPt.ppt
 
INTRODUCTION TO JAVA
INTRODUCTION TO JAVAINTRODUCTION TO JAVA
INTRODUCTION TO JAVA
 
Java tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.inJava tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.in
 
core java course online
core java course onlinecore java course online
core java course online
 
java development companies in Bangalore
java development companies in Bangalorejava development companies in Bangalore
java development companies in Bangalore
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
mukul Dubey.pptx
mukul Dubey.pptxmukul Dubey.pptx
mukul Dubey.pptx
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 

Último

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 

Último (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

Java

  • 2. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build ◦ stand-alone Java programs ◦ Java applets, which run within browsers e.g. Netscape Example programs
  • 3. Why Java? It’s the current “hot” language It’s almost entirely object-oriented It has a vast library of predefined objects and operations It’s more platform independent ◦ this makes it great for Web programming It’s more secure It isn’t C++
  • 4. Applets, Servlets and Applications An applet is designed to be embedded in a Web page, and run by a browser Applets run in a sandbox with numerous restrictions; for example, they can’t read files and then use the network A servlet is designed to be run by a web server An application is a conventional program
  • 5. Building Standalone JAVA Programs (on UNIX) Prepare the file foo.java using an editor Invoke the compiler: javac foo.java This creates foo.class Run the java interpreter: java foo
  • 6. Java Virtual Machine The .class files generated by the compiler are not executable binaries ◦ so Java combines compilation and interpretation Instead, they contain “byte-codes” to be executed by the Java Virtual Machine ◦ other languages have done this, e.g. UCSD Pascal This approach provides platform independence, and greater security
  • 7.
  • 8. HelloWorld (standalone) Note that String is built in println is a member function for the System.out class public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
  • 9. Comments are almost like C++ /* This kind of comment can span multiple lines */ // This kind is to the end of the line /** * This kind of comment is a special * ‘javadoc’ style comment */
  • 10. Primitive data types are like C Main data types are int, double, boolean, char Also have byte, short, long, float boolean has values true and false Declarations look like C, for example, ◦ double x, y; ◦ int count = 0;
  • 11. Expressions are like C Assignment statements mostly look like those in C; you can use =, +=, *= etc. Arithmetic uses the familiar + - * / % Java also has ++ and -- Java has boolean operators && || ! Java has comparisons < <= == != >= > Java does not have pointers or pointer arithmetic
  • 12. Control statements are like C if (x < y) smaller = x; if (x < y){ smaller=x;sum += x;} else { smaller = y; sum += y; } while (x < y) { y = y - x; } do { y = y - x; } while (x < y) for (int i = 0; i < max; i++) sum += i; BUT: conditions must be boolean !
  • 13. Control statements II Java also introduces the try statement, about which more later switch (n + 1) { case 0: m = n - 1; break; case 1: m = n + 1; case 3: m = m * n; break; default: m = -n; break; }
  • 14. Java isn't C! In C, almost everything is in functions In Java, almost everything is in classes There is often only one class per file There must be only one public class per file The file name must be the same as the name of that public class, but with a .java extension
  • 15. Java program layout A typical Java file looks like: import java.awt.*; import java.util.*; public class SomethingOrOther { // object definitions go here . . . } This must be in a file named SomethingOrOther.java !
  • 16. What is a class? Early languages had only arrays ◦ all elements had to be of the same type Then languages introduced structures (called records, or structs) ◦ allowed different data types to be grouped Then Abstract Data Types (ADTs) became popular ◦ grouped operations along with the data
  • 17. So, what is a class? A class consists of ◦ a collection of fields, or variables, very much like the named fields of a struct ◦ all the operations (called methods) that can be performed on those fields ◦ can be instantiated A class describes objects and operations defined on those objects
  • 18. Name conventions Java is case-sensitive; maxval, maxVal, and MaxVal are three different names Class names begin with a capital letter All other names begin with a lowercase letter Subsequent words are capitalized: theBigOne Underscores are not used in names These are very strong conventions!
  • 19. The class hierarchy Classes are arranged in a hierarchy The root, or topmost, class is Object Every class but Object has at least one superclass A class may have subclasses Each class inherits all the fields and methods of its (possibly numerous) superclasses
  • 20. An example of a class class Person { String name; int age; void birthday ( ) { age++; System.out.println (name + ' is now ' + age); } }
  • 21. Another example of a class class Driver extends Person { long driversLicenseNumber; Date expirationDate; }
  • 22. Creating and using an object Person john; john = new Person ( ); john.name = "John Smith"; john.age = 37; Person mary = new Person ( ); mary.name = "Mary Brown"; mary.age = 33; mary.birthday ( );
  • 23. An array is an object Person mary = new Person ( ); int myArray[ ] = new int[5]; ◦ or: int myArray[ ] = {1, 4, 9, 16, 25}; String languages [ ] = {"Prolog", "Java"};
  • 24. www.proximo.in Address: No:3, II Floor, 100 ft Road, BTM Layout, II Stage, Bangalore, Karnataka (560 076) India Tel: +91 (0)80 4900 1234 Mail: info@proximo.in CONTACT US Thanks for watching