SlideShare a Scribd company logo
JAVA
TajendarArora
OBJECTIVES
 What is Java?
 Why Java?
 Java System overview and Types of programs in java
 JVM
 JDK
 Primitive Data types in java
 Expressions in java
 Control Statements
 Naming conventions
 Arrays
 For-each loop
 Type casting
 Build first basic java program
 Command Line Arguments
TajendarArora
JAVA
 Java is high level programming language
introduced by Sun Microsystems in June 1995.
 Java is an object oriented language built upon C
& C++, It derived its object oriented features
from C++.
 The Java language has undergone several
changes since JDK 1.0 (1996) and now JSE 7 is
latest.
*jdk- Java Development Kit
*JSE- Java Standard Ediiton
TajendarArora
WHY JAVA
 Object-oriented
 Platform independent
 Built-in support for multi-threading, socket
communication and memory management
 Supports Web based applications (Applet,
Servlets and JSP)
 Vast library of predefined objects and operations
 Secure
TajendarArora
Tajendar Arora
JAVA FEATURES
 Simple and object oriented
 Look and feel of C
 Simplified object modeling
 Portability
 Java compiler generates byte codes
 Runtime systems for various platforms
 Size and behavior of basic data types defined
 Write once, run/debug anywhere
Tajendar Arora
JAVA FEATURES CONT.
 Availability
 Windows, Linux, Solaris,…
 Embedded systems
 Compiler and runtime are free
 Free IDEs: Eclipse, Netbeans
 Library
 Rich class library
 Part of the definition
 Standard GUI toolkit
Tajendar Arora
JAVA FEATURES CONT.
 Built-in model for concurrency
 Threads at the language level
 Synchronization
 Safety
 No Pointer!
 Automatic memory management – GC
 Networking
 Web Enabled
Tajendar Arora
JAVA SYSTEM OVERVIEW
APPLETS , SERVLETS AND APPLICATION
 An applet is designed to be embedded in a Web
page, and run by a browser.
 A servlet is designed to be run by a web server
which act as controller for we application.
 An application is a conventional standalone
program.
TajendarArora
Tajendar Arora
WHAT IS A VIRTUAL MACHINE?
 A virtual machine (VM) is an abstract computer
architecture
 Software on top of a real hardware
 Can run the same application on different
machines where the VM is available
Tajendar Arora
JVM CONT.
 Runtime environment for Java
 Implementation NOT defined
 Runs Java .class files
 Has to conform to Sun‘s specification
JDK DIRECTORY STRUCTURE
(JAVA INSTALLATIONS)
Assuming the JDK software is installed at /jdk1.7.0, here are
some of the most important directories:
/jdk1.7.0Root directory of the JDK software installation.
Contains copyright, license, and README files.
./jdk1.7.0/binExecutables for all the development tools
contained in the JDK. The PATH environment variable
should contain an entry for this directory.
/jdk1.7.0/lib Files used by the development tools.
Includes tools.jar, which contains non-core classes for support
of the tools and utilities in the JDK.
/jdk1.7.0/jre Root directory of the Java runtime environment
used by the JDK development tools. The runtime environment
is an implementation of the Java platform.
TajendarArora
PRIMITIVE DATA TYPES
 Main data types are int, double, boolean,
char
 Also have byte, short, long, float
 boolean has values true and false
 Variable Declarations look like,
 double x, y;
 int count = 0;
TajendarArora
EXPRESSIONS
 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
TajendarArora
CONTROL STATEMENTS
•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
TajendarArora
NAMING 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.
TajendarArora
ARRAYS IN JAVA
 Java provides a data structure, the array, which
stores a fixed-size sequential collection of elements of
the same type. An array is used to store a collection of
data.
 Declare array
 dataType[] arrayRefVar; // preferred way.
 Creating Arrays:
 You can create an array by using the new operator
with the following syntax:
 arrayRefVar = new dataType[arraySize]; The above
statement does two things:
 It creates an array using new dataType[arraySize];
 It assigns the reference of the newly created array to
the variable arrayRefVar.
TajendarArora
FOR EACH LOOP FOR ARRAYS IN JAVA
 Since JDK 1.5 introduced a new for loop known
as foreach loop or enhanced for loop, which
enables you to traverse the complete array
sequentially without using an index variable.
 Example:
 The following code displays all the elements in
the array myList:
 public class TestArray {
 public static void main(String[] args) {
 double[] myList = {1.9, 2.9, 3.4, 3.5};
 // Print all the array elements
 for (double element: myList)
 { System.out.println(element);
 } } }
TajendarArora
TYPE CASTING IN JAVA
 Assigning a value of one type to a variable of
another type is known as Type Casting.
 In Java, type casting is classified into two types,
 Widening Casting(Implicit)
 Narrowing Casting(Explicitly done)

TajendarArora
TYPE CASTING IN JAVA
 Widening or Automatic type converion
 Automatic Type casting take place when,the two
types are compatible
 the target type is larger than the source type
 Example :
 int i = 100;
 long l = i;
 Narrowing or Explicit type conversion
 When you are assigning a larger type value to a
variable of smaller type, then you need to perform
explicit type casting.
 double d = 100.04;
 long l = (long)d;
 //explicit type casting required int i = (int)l;
TajendarArora
BUILDING STANDALONE JAVA PROGRAMS
 We can use different IDEs as well
 IDEs are more complex and have visual Java
development tools, tight integration with the
compiler or application server, and may include
tools for debugging, refactoring, version control,
and so forth. Some examples below
 Eclipse
 NetBeans
 BjueJ
 Jbuilder
TajendarArora
BUILDING STANDALONE JAVA PROGRAMS
 Prepare the file First.java using an editor
 /*
 This is a simple Java program.*/
 class First
 {
 public static void main(String args[])
 {
 System.out.println("This is a simple Java program.");
 }
 }
 Invoke the compiler: javac First.java
 This creates First.class
 Run the java interpreter: java First
 println is a member function for the System.out class
 String is built in class
* File name should be First.java
TajendarArora
COMMAND LINE ARGUMENTS
 A command-line argument is the information
that directly follows the program’s name on the
command line when it is executed. To access the
command-line arguments inside a Java program
is quite easy—they are stored as strings in the
String array passed to main( ).
 class CommandLine {
 public static void main(String args[]) {
 for(int i=0; i<args.length; i++)
 System.out.println("args[" + i + "]: " +args[i]);
 }
 }
 * length returns the length of array
TajendarArora
Thank you
TajendarArora

More Related Content

PPTX
Java 101 Intro to Java Programming
PPTX
Let's start with Java- Basic Concepts
PPTX
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
PPTX
Core Java introduction | Basics | free course
PPTX
Core java
PDF
Introduction to Java Programming
PPTX
PPT
Java basic introduction
Java 101 Intro to Java Programming
Let's start with Java- Basic Concepts
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Core Java introduction | Basics | free course
Core java
Introduction to Java Programming
Java basic introduction

What's hot (20)

PPTX
Java 101 intro to programming with java
PPT
Fundamentals of oop lecture 2
PPT
Presentation on java
PPT
Hibernate introduction
PPT
Java basic
PPTX
1_JavIntro
PPS
Advance Java
PDF
Core Java
PPT
Fundamentals of JAVA
PPTX
Java training in delhi
PPSX
Core java lessons
PPSX
Java &amp; advanced java
PPSX
Elements of Java Language
PPT
Basics of java programming language
PDF
Basic java tutorial
PPTX
Java basic-tutorial for beginners
PDF
Java Programming - 01 intro to java
PPTX
Java 102 intro to object-oriented programming in java
PPTX
Core java1
PPTX
PROGRAMMING IN JAVA
Java 101 intro to programming with java
Fundamentals of oop lecture 2
Presentation on java
Hibernate introduction
Java basic
1_JavIntro
Advance Java
Core Java
Fundamentals of JAVA
Java training in delhi
Core java lessons
Java &amp; advanced java
Elements of Java Language
Basics of java programming language
Basic java tutorial
Java basic-tutorial for beginners
Java Programming - 01 intro to java
Java 102 intro to object-oriented programming in java
Core java1
PROGRAMMING IN JAVA
Ad

Viewers also liked (14)

PDF
Introduction to Jquery
PPT
Challenges confronting the police institution in ghana by evans kojo acheampong
DOCX
Bus 402 week 5 discussion questions 1
PDF
Formação Continuada
PPTX
11.measurement
PPTX
Tal Solutions Talent Science Presentation_FINAL3
PDF
The Power of Legacy
PDF
hospitality
DOCX
Bus 402 week 3 discussion questions 2
PPTX
Einführung in die @4sqapi
DOC
CV CALUBAYAN LEAMOR L.
PPTX
Unit 27 – task 2 coachs log
PPT
Global277 279
PPTX
Digital marketing-training-institute
Introduction to Jquery
Challenges confronting the police institution in ghana by evans kojo acheampong
Bus 402 week 5 discussion questions 1
Formação Continuada
11.measurement
Tal Solutions Talent Science Presentation_FINAL3
The Power of Legacy
hospitality
Bus 402 week 3 discussion questions 2
Einführung in die @4sqapi
CV CALUBAYAN LEAMOR L.
Unit 27 – task 2 coachs log
Global277 279
Digital marketing-training-institute
Ad

Similar to Introduction to java (20)

PPTX
JAVA INETRNSHIP1 made with simple topics.ppt.pptx
PPTX
Object Oriented Programming unit 1 content for students
PPTX
Introduction to Core Java Programming
PDF
Introduction java programming
PDF
Java programming basics
PPTX
Core java introduction
PDF
Java programming material for beginners by Nithin, VVCE, Mysuru
PPT
Introduction
PPT
Java platform
PPTX
2. Introduction to Java for engineering stud
PPTX
JAVA_Day1_BasicIntroduction.pptx
PPTX
JAVAPart1_BasicIntroduction.pptx
PDF
Java Developer Roadmap PDF By ScholarHat
PDF
Java Programming Fundamentals: Complete Guide for Beginners
PPTX
UNIT 1.pptx
PPTX
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
PPTX
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
DOCX
OOP-Chap2.docx
JAVA INETRNSHIP1 made with simple topics.ppt.pptx
Object Oriented Programming unit 1 content for students
Introduction to Core Java Programming
Introduction java programming
Java programming basics
Core java introduction
Java programming material for beginners by Nithin, VVCE, Mysuru
Introduction
Java platform
2. Introduction to Java for engineering stud
JAVA_Day1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
Java Developer Roadmap PDF By ScholarHat
Java Programming Fundamentals: Complete Guide for Beginners
UNIT 1.pptx
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
OOP-Chap2.docx

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
GDM (1) (1).pptx small presentation for students
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Pharma ospi slides which help in ospi learning
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Classroom Observation Tools for Teachers
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Lesson notes of climatology university.
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
VCE English Exam - Section C Student Revision Booklet
Microbial disease of the cardiovascular and lymphatic systems
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
O5-L3 Freight Transport Ops (International) V1.pdf
Anesthesia in Laparoscopic Surgery in India
GDM (1) (1).pptx small presentation for students
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Computing-Curriculum for Schools in Ghana
Pharma ospi slides which help in ospi learning
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Microbial diseases, their pathogenesis and prophylaxis
Classroom Observation Tools for Teachers
Final Presentation General Medicine 03-08-2024.pptx
Renaissance Architecture: A Journey from Faith to Humanism
TR - Agricultural Crops Production NC III.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Lesson notes of climatology university.

Introduction to java

  • 2. OBJECTIVES  What is Java?  Why Java?  Java System overview and Types of programs in java  JVM  JDK  Primitive Data types in java  Expressions in java  Control Statements  Naming conventions  Arrays  For-each loop  Type casting  Build first basic java program  Command Line Arguments TajendarArora
  • 3. JAVA  Java is high level programming language introduced by Sun Microsystems in June 1995.  Java is an object oriented language built upon C & C++, It derived its object oriented features from C++.  The Java language has undergone several changes since JDK 1.0 (1996) and now JSE 7 is latest. *jdk- Java Development Kit *JSE- Java Standard Ediiton TajendarArora
  • 4. WHY JAVA  Object-oriented  Platform independent  Built-in support for multi-threading, socket communication and memory management  Supports Web based applications (Applet, Servlets and JSP)  Vast library of predefined objects and operations  Secure TajendarArora
  • 5. Tajendar Arora JAVA FEATURES  Simple and object oriented  Look and feel of C  Simplified object modeling  Portability  Java compiler generates byte codes  Runtime systems for various platforms  Size and behavior of basic data types defined  Write once, run/debug anywhere
  • 6. Tajendar Arora JAVA FEATURES CONT.  Availability  Windows, Linux, Solaris,…  Embedded systems  Compiler and runtime are free  Free IDEs: Eclipse, Netbeans  Library  Rich class library  Part of the definition  Standard GUI toolkit
  • 7. Tajendar Arora JAVA FEATURES CONT.  Built-in model for concurrency  Threads at the language level  Synchronization  Safety  No Pointer!  Automatic memory management – GC  Networking  Web Enabled
  • 9. APPLETS , SERVLETS AND APPLICATION  An applet is designed to be embedded in a Web page, and run by a browser.  A servlet is designed to be run by a web server which act as controller for we application.  An application is a conventional standalone program. TajendarArora
  • 10. Tajendar Arora WHAT IS A VIRTUAL MACHINE?  A virtual machine (VM) is an abstract computer architecture  Software on top of a real hardware  Can run the same application on different machines where the VM is available
  • 11. Tajendar Arora JVM CONT.  Runtime environment for Java  Implementation NOT defined  Runs Java .class files  Has to conform to Sun‘s specification
  • 12. JDK DIRECTORY STRUCTURE (JAVA INSTALLATIONS) Assuming the JDK software is installed at /jdk1.7.0, here are some of the most important directories: /jdk1.7.0Root directory of the JDK software installation. Contains copyright, license, and README files. ./jdk1.7.0/binExecutables for all the development tools contained in the JDK. The PATH environment variable should contain an entry for this directory. /jdk1.7.0/lib Files used by the development tools. Includes tools.jar, which contains non-core classes for support of the tools and utilities in the JDK. /jdk1.7.0/jre Root directory of the Java runtime environment used by the JDK development tools. The runtime environment is an implementation of the Java platform. TajendarArora
  • 13. PRIMITIVE DATA TYPES  Main data types are int, double, boolean, char  Also have byte, short, long, float  boolean has values true and false  Variable Declarations look like,  double x, y;  int count = 0; TajendarArora
  • 14. EXPRESSIONS  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 TajendarArora
  • 15. CONTROL STATEMENTS •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 TajendarArora
  • 16. NAMING 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. TajendarArora
  • 17. ARRAYS IN JAVA  Java provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data.  Declare array  dataType[] arrayRefVar; // preferred way.  Creating Arrays:  You can create an array by using the new operator with the following syntax:  arrayRefVar = new dataType[arraySize]; The above statement does two things:  It creates an array using new dataType[arraySize];  It assigns the reference of the newly created array to the variable arrayRefVar. TajendarArora
  • 18. FOR EACH LOOP FOR ARRAYS IN JAVA  Since JDK 1.5 introduced a new for loop known as foreach loop or enhanced for loop, which enables you to traverse the complete array sequentially without using an index variable.  Example:  The following code displays all the elements in the array myList:  public class TestArray {  public static void main(String[] args) {  double[] myList = {1.9, 2.9, 3.4, 3.5};  // Print all the array elements  for (double element: myList)  { System.out.println(element);  } } } TajendarArora
  • 19. TYPE CASTING IN JAVA  Assigning a value of one type to a variable of another type is known as Type Casting.  In Java, type casting is classified into two types,  Widening Casting(Implicit)  Narrowing Casting(Explicitly done)  TajendarArora
  • 20. TYPE CASTING IN JAVA  Widening or Automatic type converion  Automatic Type casting take place when,the two types are compatible  the target type is larger than the source type  Example :  int i = 100;  long l = i;  Narrowing or Explicit type conversion  When you are assigning a larger type value to a variable of smaller type, then you need to perform explicit type casting.  double d = 100.04;  long l = (long)d;  //explicit type casting required int i = (int)l; TajendarArora
  • 21. BUILDING STANDALONE JAVA PROGRAMS  We can use different IDEs as well  IDEs are more complex and have visual Java development tools, tight integration with the compiler or application server, and may include tools for debugging, refactoring, version control, and so forth. Some examples below  Eclipse  NetBeans  BjueJ  Jbuilder TajendarArora
  • 22. BUILDING STANDALONE JAVA PROGRAMS  Prepare the file First.java using an editor  /*  This is a simple Java program.*/  class First  {  public static void main(String args[])  {  System.out.println("This is a simple Java program.");  }  }  Invoke the compiler: javac First.java  This creates First.class  Run the java interpreter: java First  println is a member function for the System.out class  String is built in class * File name should be First.java TajendarArora
  • 23. COMMAND LINE ARGUMENTS  A command-line argument is the information that directly follows the program’s name on the command line when it is executed. To access the command-line arguments inside a Java program is quite easy—they are stored as strings in the String array passed to main( ).  class CommandLine {  public static void main(String args[]) {  for(int i=0; i<args.length; i++)  System.out.println("args[" + i + "]: " +args[i]);  }  }  * length returns the length of array TajendarArora