SlideShare a Scribd company logo
1 of 29
Tuesday,September10,2013TOPSTechnologies-JavaTutorial
1
TOPSTechnologies–JavaIntroductoryTutorial
2
INTRODUCTION TO JAVA
TOPS Technologies – Java Introductory Tutorial
Module :1( theory)
http://www.tops-int.com/
TOPS Technologies – Java Introductory tutorial M1 3
WELCOME
• History
• First Java Application
• Data types
• Variables
• Strings
• Assignments
• Math, Boolean expressions
• Relational operations
• If statements
• System.exit
TOPS Technologies – Java Introductory tutorial M1 4
VERY BRIEF HISTORY
• Started in 1991 by SUN Microsystems
• Targeted at consumer electronics. Wanted reliable
programming language.
• Integrated into browsers
• Evolved into write once run anywhere, integrates
into Netscape
• General purpose libraries released
TOPS Technologies – Java Introductory tutorial M1 5
COURSE INFORMATION
 Textbook: Java in a Nutshell
Reading class 1
chapters 1,2
6
BASIC DEFINITIONS
• Java is an object oriented language.
• Object
• Method
• Class
• Applications
• Applets
• Native classes
• Threads
• Exceptions
TOPS Technologies – Java Introductory tutorial M1
TOPS Technologies – Java Introductory tutorial M1 7
FIRST APPLICATION
/**
*Hello World, first application, only output.
*/
import java.io.*;
public class hello{
public static void main (String [] args) {
System.out.println(“Hello Worldn”);
} //end main
}//end class
8
HOW TO GET IT RUNNING
• Text in hello.java file
• Why?
• To compile:
• javac hello.java
• To run:
• java hello
TOPS Technologies – Java Introductory tutorial M1
9
NOTICE:
• Java is CASE SENSITIVE!!
• Whitespace is ignored by compiler
• Whitespace makes things easier to read…hence it
affects your grade 
• File name has to be the same as class name in
file.
• Need to import necessary class definitions
TOPS Technologies – Java Introductory tutorial M1
10
VARIABLES
• Variables:
• Name
• Type
• Value
• Naming:
• May contain numbers,underscore,dollar sign, or
letters
• Can not start with number
• Can be any length
• Reserved keywords
• Case sensitive
TOPS Technologies – Java Introductory tutorial M1
11
PRIMITIVE DATA TYPES
Byte 8 -27 27-1
Short 16 -215 215-1
Int 32 -231 231-1
Long 64
Float 32
Double 64
Boolean 1 0 1
Char 16
TOPS Technologies – Java Introductory tutorial M1
12
ASSIGNMENT
• =
• Example:
• int n;
• n = 10;
• or
• int n = 10; //same
TOPS Technologies – Java Introductory tutorial M1
13
STRINGS
• Not a primitive class, its actually something called a
wrapper class
• To find a built in class‟s method use API
documentation.
• String is a group of char‟s
• A character has single quotes
• char c = „h‟;
• A String has double quotes
• String s = “Hello World”;
• Method length
• int n = s.length;
TOPS Technologies – Java Introductory tutorial M1
14
USING STRINGS
public class hello{
public static void main (String [] args) {
String s = “Hello Worldn”;
System.out.println(s); //output simple
string
} //end main
}//end class hello
TOPS Technologies – Java Introductory tutorial M1
15
MATH
• Unary
• int x = -9;
• Regular math (+,-,*,/)
• int y = 3+x;
• % modulo operator
TOPS Technologies – Java Introductory tutorial M1
16
INCREMENTING
• Increment and Decrement
• i++ equivalent to i = i + 1;
• Can also do ++i, which uses i before incrementing
it.
• Decrementing: i--;
TOPS Technologies – Java Introductory tutorial M1
17
CASTING
int n = 40;
Wrong : byte b = n;
why??
Right: byte b = (byte) n;
Type casting converts to target type
TOPS Technologies – Java Introductory tutorial M1
18
CASTING II
• Type char is stored as a number. The ASCII value
of the character.
• A declaration of :
• char c = „B‟;
stores the value 66 in location c
can use its value by casting to int
how??
TOPS Technologies – Java Introductory tutorial M1
19
ASSIGNMENT
• +=
• -=
• *=
• /=
• %=
TOPS Technologies – Java Introductory tutorial M1
20
BOOLEAN EXPRESSIONS
• boolean b
b will be either true (1) or false (0)
• Logical operations: !(not), && (and) || (or)
• boolean a,b;
a = true;
b = false;
System.out.println (“a && b is “ + (a && b));
TOPS Technologies – Java Introductory tutorial M1
21
RELATIONAL OPERATORS
 == equality
 != inequality
 > greater than
 < less than
 >= greater than or equal to
 <= less than or equal to
TOPS Technologies – Java Introductory tutorial M1
22
THE IF - BRANCHING STATEMENT
• if ( x < y) {
• x = y;
• }
• if ( x < y ) {
x = y;
}
else {
x = 88;
}
TOPS Technologies – Java Introductory tutorial M1
23
IF/ELSE
• if (logic condition) {
something
}
else if (logic condition) {
something
}
else {
something else
}
TOPS Technologies – Java Introductory tutorial M1
24
NESTED IF
if ( x < 0 ) {
System.out.println( “ x is negative “ );
}
else {
if ( x > 0 ) {
System.out.println ( “x is positive” );
}
//end if x > 0
else {
System.out.println ( “x is zero “ );
}
} //end else x >=0
TOPS Technologies – Java Introductory tutorial M1
25
SWITCH/CASE
Switch(variable)
{
case(1): something;
break;
case(23): something;
break;
default: something;
}
TOPS Technologies – Java Introductory tutorial M1
26
EXCEPTIONS
• Java exception object.
• java.io.Exception
most general one.
Some exception like in Throwable class define
methods to get the message.
TOPS Technologies – Java Introductory tutorial M1
27
TRY….CATCH BLOCKS.
Try {
…….
}
catch ( IOException v) {
……….
}
TOPS Technologies – Java Introductory tutorial M1
28
SYSTEM.OUT.PRINTLN
• println is a method in the Printstream class.
• Defined:
• public void println(String x)
can be any type of string or combination string using
addition to join parts.
Example:
println(“hello “ + “world “ + x);
TOPS Technologies – Java Introductory tutorial M1
29
SYSTEM.EXIT()
• One method in java.lang.System
• Defined:
public static void exit ( int status)
• Terminates currently running Java VM
• Status is status code, non zero will usually
mean something abnormal.
• Used at end to indicate success, or in
middle to signal problems.
TOPS Technologies – Java Introductory tutorial M1

More Related Content

Similar to Introduction to Java programming

Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101kankemwa Ishaku
 
chapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptxchapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptxnafsigenet
 
Java Course — Mastering the Fundamentals
Java Course — Mastering the FundamentalsJava Course — Mastering the Fundamentals
Java Course — Mastering the Fundamentalsnehash4637
 
Guglielmo iozzia - Google I/O extended dublin 2018
Guglielmo iozzia - Google  I/O extended dublin 2018Guglielmo iozzia - Google  I/O extended dublin 2018
Guglielmo iozzia - Google I/O extended dublin 2018Guglielmo Iozzia
 
How to start learning java
How to start learning javaHow to start learning java
How to start learning javabillgatewilliam
 
Natural Language Query to SQL conversion using Machine Learning Approach
Natural Language Query to SQL conversion using Machine Learning ApproachNatural Language Query to SQL conversion using Machine Learning Approach
Natural Language Query to SQL conversion using Machine Learning ApproachMinhazul Arefin
 
02-Basic-Java-Syntax.pdf
02-Basic-Java-Syntax.pdf02-Basic-Java-Syntax.pdf
02-Basic-Java-Syntax.pdferusmala888
 

Similar to Introduction to Java programming (20)

Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
chapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptxchapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptx
 
Core Java Presentation
Core Java PresentationCore Java Presentation
Core Java Presentation
 
PROGRAMMING IN JAVA
PROGRAMMING IN JAVAPROGRAMMING IN JAVA
PROGRAMMING IN JAVA
 
Java Course — Mastering the Fundamentals
Java Course — Mastering the FundamentalsJava Course — Mastering the Fundamentals
Java Course — Mastering the Fundamentals
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
Guglielmo iozzia - Google I/O extended dublin 2018
Guglielmo iozzia - Google  I/O extended dublin 2018Guglielmo iozzia - Google  I/O extended dublin 2018
Guglielmo iozzia - Google I/O extended dublin 2018
 
Core java
Core javaCore java
Core java
 
Core java
Core javaCore java
Core java
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Introduction what is java
Introduction what is javaIntroduction what is java
Introduction what is java
 
How to start learning java
How to start learning javaHow to start learning java
How to start learning java
 
1.Java_programming2017.pdf
1.Java_programming2017.pdf1.Java_programming2017.pdf
1.Java_programming2017.pdf
 
Javascript
JavascriptJavascript
Javascript
 
Natural Language Query to SQL conversion using Machine Learning Approach
Natural Language Query to SQL conversion using Machine Learning ApproachNatural Language Query to SQL conversion using Machine Learning Approach
Natural Language Query to SQL conversion using Machine Learning Approach
 
02-Basic-Java-Syntax.pdf
02-Basic-Java-Syntax.pdf02-Basic-Java-Syntax.pdf
02-Basic-Java-Syntax.pdf
 

More from TOPS Technologies

Learn java objects inheritance-overriding-polymorphism
Learn java objects  inheritance-overriding-polymorphismLearn java objects  inheritance-overriding-polymorphism
Learn java objects inheritance-overriding-polymorphismTOPS Technologies
 
Surat tops conducted one hour seminar on “corporate basic skills”
Surat tops conducted  one hour seminar on “corporate basic skills”Surat tops conducted  one hour seminar on “corporate basic skills”
Surat tops conducted one hour seminar on “corporate basic skills”TOPS Technologies
 
Word press interview question and answer tops technologies
Word press interview question and answer   tops technologiesWord press interview question and answer   tops technologies
Word press interview question and answer tops technologiesTOPS Technologies
 
Software testing and quality assurance
Software testing and quality assuranceSoftware testing and quality assurance
Software testing and quality assuranceTOPS Technologies
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programmingTOPS Technologies
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applicationsTOPS Technologies
 
What is ui element in i phone developmetn
What is ui element in i phone developmetnWhat is ui element in i phone developmetn
What is ui element in i phone developmetnTOPS Technologies
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applicationsTOPS Technologies
 
Software testing live project training
Software testing live project trainingSoftware testing live project training
Software testing live project trainingTOPS Technologies
 
Web designing live project training
Web designing live project trainingWeb designing live project training
Web designing live project trainingTOPS Technologies
 
iPhone training in ahmedabad by tops technologies
iPhone training in ahmedabad by tops technologiesiPhone training in ahmedabad by tops technologies
iPhone training in ahmedabad by tops technologiesTOPS Technologies
 
08 10-2013 gtu projects - develop final sem gtu project in i phone
08 10-2013 gtu projects - develop final sem gtu project in i phone08 10-2013 gtu projects - develop final sem gtu project in i phone
08 10-2013 gtu projects - develop final sem gtu project in i phoneTOPS Technologies
 
GTU PHP Project Training Guidelines
GTU PHP Project Training GuidelinesGTU PHP Project Training Guidelines
GTU PHP Project Training GuidelinesTOPS Technologies
 
GTU Asp.net Project Training Guidelines
GTU Asp.net Project Training GuidelinesGTU Asp.net Project Training Guidelines
GTU Asp.net Project Training GuidelinesTOPS Technologies
 

More from TOPS Technologies (20)

Learn java objects inheritance-overriding-polymorphism
Learn java objects  inheritance-overriding-polymorphismLearn java objects  inheritance-overriding-polymorphism
Learn java objects inheritance-overriding-polymorphism
 
Surat tops conducted one hour seminar on “corporate basic skills”
Surat tops conducted  one hour seminar on “corporate basic skills”Surat tops conducted  one hour seminar on “corporate basic skills”
Surat tops conducted one hour seminar on “corporate basic skills”
 
Word press interview question and answer tops technologies
Word press interview question and answer   tops technologiesWord press interview question and answer   tops technologies
Word press interview question and answer tops technologies
 
How to install android sdk
How to install android sdkHow to install android sdk
How to install android sdk
 
Software testing and quality assurance
Software testing and quality assuranceSoftware testing and quality assurance
Software testing and quality assurance
 
Basics in software testing
Basics in software testingBasics in software testing
Basics in software testing
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applications
 
What is ui element in i phone developmetn
What is ui element in i phone developmetnWhat is ui element in i phone developmetn
What is ui element in i phone developmetn
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applications
 
Java live project training
Java live project trainingJava live project training
Java live project training
 
Software testing live project training
Software testing live project trainingSoftware testing live project training
Software testing live project training
 
Web designing live project training
Web designing live project trainingWeb designing live project training
Web designing live project training
 
Php live project training
Php live project trainingPhp live project training
Php live project training
 
iPhone training in ahmedabad by tops technologies
iPhone training in ahmedabad by tops technologiesiPhone training in ahmedabad by tops technologies
iPhone training in ahmedabad by tops technologies
 
Php training in ahmedabad
Php training in ahmedabadPhp training in ahmedabad
Php training in ahmedabad
 
Java training in ahmedabad
Java training in ahmedabadJava training in ahmedabad
Java training in ahmedabad
 
08 10-2013 gtu projects - develop final sem gtu project in i phone
08 10-2013 gtu projects - develop final sem gtu project in i phone08 10-2013 gtu projects - develop final sem gtu project in i phone
08 10-2013 gtu projects - develop final sem gtu project in i phone
 
GTU PHP Project Training Guidelines
GTU PHP Project Training GuidelinesGTU PHP Project Training Guidelines
GTU PHP Project Training Guidelines
 
GTU Asp.net Project Training Guidelines
GTU Asp.net Project Training GuidelinesGTU Asp.net Project Training Guidelines
GTU Asp.net Project Training Guidelines
 

Recently uploaded

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 

Recently uploaded (20)

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 

Introduction to Java programming

  • 2. TOPSTechnologies–JavaIntroductoryTutorial 2 INTRODUCTION TO JAVA TOPS Technologies – Java Introductory Tutorial Module :1( theory) http://www.tops-int.com/
  • 3. TOPS Technologies – Java Introductory tutorial M1 3 WELCOME • History • First Java Application • Data types • Variables • Strings • Assignments • Math, Boolean expressions • Relational operations • If statements • System.exit
  • 4. TOPS Technologies – Java Introductory tutorial M1 4 VERY BRIEF HISTORY • Started in 1991 by SUN Microsystems • Targeted at consumer electronics. Wanted reliable programming language. • Integrated into browsers • Evolved into write once run anywhere, integrates into Netscape • General purpose libraries released
  • 5. TOPS Technologies – Java Introductory tutorial M1 5 COURSE INFORMATION  Textbook: Java in a Nutshell Reading class 1 chapters 1,2
  • 6. 6 BASIC DEFINITIONS • Java is an object oriented language. • Object • Method • Class • Applications • Applets • Native classes • Threads • Exceptions TOPS Technologies – Java Introductory tutorial M1
  • 7. TOPS Technologies – Java Introductory tutorial M1 7 FIRST APPLICATION /** *Hello World, first application, only output. */ import java.io.*; public class hello{ public static void main (String [] args) { System.out.println(“Hello Worldn”); } //end main }//end class
  • 8. 8 HOW TO GET IT RUNNING • Text in hello.java file • Why? • To compile: • javac hello.java • To run: • java hello TOPS Technologies – Java Introductory tutorial M1
  • 9. 9 NOTICE: • Java is CASE SENSITIVE!! • Whitespace is ignored by compiler • Whitespace makes things easier to read…hence it affects your grade  • File name has to be the same as class name in file. • Need to import necessary class definitions TOPS Technologies – Java Introductory tutorial M1
  • 10. 10 VARIABLES • Variables: • Name • Type • Value • Naming: • May contain numbers,underscore,dollar sign, or letters • Can not start with number • Can be any length • Reserved keywords • Case sensitive TOPS Technologies – Java Introductory tutorial M1
  • 11. 11 PRIMITIVE DATA TYPES Byte 8 -27 27-1 Short 16 -215 215-1 Int 32 -231 231-1 Long 64 Float 32 Double 64 Boolean 1 0 1 Char 16 TOPS Technologies – Java Introductory tutorial M1
  • 12. 12 ASSIGNMENT • = • Example: • int n; • n = 10; • or • int n = 10; //same TOPS Technologies – Java Introductory tutorial M1
  • 13. 13 STRINGS • Not a primitive class, its actually something called a wrapper class • To find a built in class‟s method use API documentation. • String is a group of char‟s • A character has single quotes • char c = „h‟; • A String has double quotes • String s = “Hello World”; • Method length • int n = s.length; TOPS Technologies – Java Introductory tutorial M1
  • 14. 14 USING STRINGS public class hello{ public static void main (String [] args) { String s = “Hello Worldn”; System.out.println(s); //output simple string } //end main }//end class hello TOPS Technologies – Java Introductory tutorial M1
  • 15. 15 MATH • Unary • int x = -9; • Regular math (+,-,*,/) • int y = 3+x; • % modulo operator TOPS Technologies – Java Introductory tutorial M1
  • 16. 16 INCREMENTING • Increment and Decrement • i++ equivalent to i = i + 1; • Can also do ++i, which uses i before incrementing it. • Decrementing: i--; TOPS Technologies – Java Introductory tutorial M1
  • 17. 17 CASTING int n = 40; Wrong : byte b = n; why?? Right: byte b = (byte) n; Type casting converts to target type TOPS Technologies – Java Introductory tutorial M1
  • 18. 18 CASTING II • Type char is stored as a number. The ASCII value of the character. • A declaration of : • char c = „B‟; stores the value 66 in location c can use its value by casting to int how?? TOPS Technologies – Java Introductory tutorial M1
  • 19. 19 ASSIGNMENT • += • -= • *= • /= • %= TOPS Technologies – Java Introductory tutorial M1
  • 20. 20 BOOLEAN EXPRESSIONS • boolean b b will be either true (1) or false (0) • Logical operations: !(not), && (and) || (or) • boolean a,b; a = true; b = false; System.out.println (“a && b is “ + (a && b)); TOPS Technologies – Java Introductory tutorial M1
  • 21. 21 RELATIONAL OPERATORS  == equality  != inequality  > greater than  < less than  >= greater than or equal to  <= less than or equal to TOPS Technologies – Java Introductory tutorial M1
  • 22. 22 THE IF - BRANCHING STATEMENT • if ( x < y) { • x = y; • } • if ( x < y ) { x = y; } else { x = 88; } TOPS Technologies – Java Introductory tutorial M1
  • 23. 23 IF/ELSE • if (logic condition) { something } else if (logic condition) { something } else { something else } TOPS Technologies – Java Introductory tutorial M1
  • 24. 24 NESTED IF if ( x < 0 ) { System.out.println( “ x is negative “ ); } else { if ( x > 0 ) { System.out.println ( “x is positive” ); } //end if x > 0 else { System.out.println ( “x is zero “ ); } } //end else x >=0 TOPS Technologies – Java Introductory tutorial M1
  • 25. 25 SWITCH/CASE Switch(variable) { case(1): something; break; case(23): something; break; default: something; } TOPS Technologies – Java Introductory tutorial M1
  • 26. 26 EXCEPTIONS • Java exception object. • java.io.Exception most general one. Some exception like in Throwable class define methods to get the message. TOPS Technologies – Java Introductory tutorial M1
  • 27. 27 TRY….CATCH BLOCKS. Try { ……. } catch ( IOException v) { ………. } TOPS Technologies – Java Introductory tutorial M1
  • 28. 28 SYSTEM.OUT.PRINTLN • println is a method in the Printstream class. • Defined: • public void println(String x) can be any type of string or combination string using addition to join parts. Example: println(“hello “ + “world “ + x); TOPS Technologies – Java Introductory tutorial M1
  • 29. 29 SYSTEM.EXIT() • One method in java.lang.System • Defined: public static void exit ( int status) • Terminates currently running Java VM • Status is status code, non zero will usually mean something abnormal. • Used at end to indicate success, or in middle to signal problems. TOPS Technologies – Java Introductory tutorial M1