SlideShare a Scribd company logo
1 of 19
Introduction To
      Java
Java
    • Programming Language
    • Developed by: James Gosling at Sun
      Microsystems in 1991 , referred as OAK
    • Released in 1995 as core component of Sun
      Microsystems Java Platform
    • Derives much of its syntax from C and C++
    • Applications are compiled to bytecode that can
      run on any JVM( Java Virtual Machine) regardless
      of computer architecture

Based on material from: http://en.wikipedia.org/wiki/Java_%28programming_language%29
Java Virtual Machine
       • A virtual machine (VM) is a software implementation of a
         machine that executes programs like a physical machine1
       • JVM enables a set of computer software programs and
         data structures to use a virtual machine model for the
         execution of other computer programs and scripts.2
       • The model used by a JVM accepts a form of computer
         intermediate language commonly referred to as Java
         bytecode.2
       • Java bytecode instructions are analogous to machine
         code, but are intended to be interpreted by a virtual
         machine


Based on material from:
1. http://en.wikipedia.org/wiki/Virtual_machine
2.http://en.wikipedia.org/wiki/Java_Virtual_Machine
Java is:
      • General-purpose
      • Concurrent
      • class-based and
      • Object-oriented,
      • Is specifically designed to have as few implementation
        dependencies as possible.
      • It is intended to let application developers "write once,
        run anywhere".
      • Java is considered by many as one of the most influential
        programming languages of the 20th century, and widely
        used from application software to web application



Based on material from: http://en.wikipedia.org/wiki/Java_%28programming_language%29
Principles
       • There were five primary goals in the creation
         of the Java language:
             – It should be "simple, object oriented, and
               familiar".
             – It should be "robust and secure".
             – It should be "architecture neutral and portable".
             – It should execute with "high performance".
             – It should be "interpreted, threaded, and
               dynamic".

Design Goals of the JavaTM Programming Language
Object Oriented
• A technique or way to model real world
  problems
• Many interacting objects exist
• Objects interact via messages
• Class Vs Object
  – A class is a user defined data type
  – Object is any instance of class
Object
• The fundamental idea behind object-oriented
  language is to combine into a single unit both
  – data and
  – the functions that operate on that data.
  – Such a unit is called an object
• Five basic properties
  –   Identity
  –   Attributes
  –   Behavior
  –   Interface
  –   Life Span
Java Program
• A java program is defined by a public class that takes
  the form:
public class program-name
{
  optional variable declarations and methods
  public static void main(String[] args)
  {
       statements
  }
  optional variable declarations and methods
}
To compile Java Code
• javac program-name.java
• For this to work, the javac must be in your shell's path
  or you must explicitly specify the path to the program
  (such as c:j2sebinjavac program-name.java).
• If the compilation is successful, javac will quietly end
  and return you to a command prompt.
• If you look in the directory, there will now be a
  program-name.class file.
• This file is the compiled version of your program.
  Once your program is in this form, its ready to run.
• If not, or you receive an error message, check for
  typographical errors in your source code.
To RUN(Execute) Java Program
• java Program-name
Java Comments
• The Java programming language supports three kinds of
  comments:
• /* text */
  The compiler ignores everything from /* to */.
• /** documentation */
  This indicates a documentation comment (doc comment,
  for short). The compiler ignores this kind of comment, just
  like it ignores comments that use /* and */. The JDK
  javadoc tool uses doc comments when preparing
  automatically generated documentation.
• // text
  The compiler ignores everything from // to the end of the
  line.
Java Data and Variables
• 8 primitive types
  – byte
  – short
  – int
  – long
  – float
  – double
  – char
  – boolean
Integer Primitive Data Types
Type           Size       Range
byte           8 bits     -128 to +127
                          -32,768 to
short          16 bits
                          +32,767
                          (about)-2 billion
int            32 bits
                          to +2 billion
                          (about)-10E18 to
long           64 bits
                          +10E18
Floating Point Primitive DataTypes
Method to Declare variable
• Syntax
  – DataType VariableName;
  – Datatype VariableName = InitialValue;
• Examples
  – int yr = 2010;
  – double value = 89.12 ;
Wrapper Class
Variable
• Variables only exist within the structure in which
  they are defined.
• For example, if a variable is created within a
  method, it cannot be accessed outside the method.
• In addition, a different method can create a variable
  of the same name which will not conflict with the
  other variable.
• A java variable can be thought of as a little box
  made up of one or more bytes that can hold a value
  of a particular data type
Example
class example
{
  public static void main ( String[] args )
  {
    long x = 123; //a declaration of a variable named x with a datatype of long
    System.out.println("The variable x has: " + x );
  }
}
Java Command Line Arguments
• Arguments are passed as a String array to the
  main method of a class.
• The first element (element 0) is the first
  argument passed not the name of the class

More Related Content

What's hot (20)

Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platforms
 
Packages and Interfaces
Packages and InterfacesPackages and Interfaces
Packages and Interfaces
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java & advanced java
Java & advanced javaJava & advanced java
Java & advanced java
 
Short notes of oop with java
Short notes of oop with javaShort notes of oop with java
Short notes of oop with java
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Java introduction
Java introductionJava introduction
Java introduction
 
Memory models in c#
Memory models in c#Memory models in c#
Memory models in c#
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
 
Core Java
Core JavaCore Java
Core Java
 
Java
JavaJava
Java
 
Java
JavaJava
Java
 
Core Java
Core JavaCore Java
Core Java
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 
Introduction of java
Introduction  of javaIntroduction  of java
Introduction of java
 
Introduction to Object-Oriented Concepts and Java
Introduction to Object-Oriented Concepts and Java Introduction to Object-Oriented Concepts and Java
Introduction to Object-Oriented Concepts and Java
 
Java features
Java  features Java  features
Java features
 
Java features
Java featuresJava features
Java features
 

Viewers also liked

Case studys of RockSound and Kerrang!
Case studys of RockSound and Kerrang!Case studys of RockSound and Kerrang!
Case studys of RockSound and Kerrang!Chloe Main
 

Viewers also liked (8)

Comp102 lec 5.0
Comp102   lec 5.0Comp102   lec 5.0
Comp102 lec 5.0
 
Comp102 lec 5.1
Comp102   lec 5.1Comp102   lec 5.1
Comp102 lec 5.1
 
Comp102 lec 7
Comp102   lec 7Comp102   lec 7
Comp102 lec 7
 
Case studys of RockSound and Kerrang!
Case studys of RockSound and Kerrang!Case studys of RockSound and Kerrang!
Case studys of RockSound and Kerrang!
 
Comp102 lec 8
Comp102   lec 8Comp102   lec 8
Comp102 lec 8
 
Comp102 lec 9
Comp102   lec 9Comp102   lec 9
Comp102 lec 9
 
Comp102 lec 10
Comp102   lec 10Comp102   lec 10
Comp102 lec 10
 
Comp102 lec 4
Comp102   lec 4Comp102   lec 4
Comp102 lec 4
 

Similar to Comp102 lec 3

Similar to Comp102 lec 3 (20)

1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
JAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptJAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).ppt
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java Programming
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentation
 
unit1.pptx
unit1.pptxunit1.pptx
unit1.pptx
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
 
j-chap1-Basics.ppt
j-chap1-Basics.pptj-chap1-Basics.ppt
j-chap1-Basics.ppt
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdf
 
1 java introduction
1 java introduction1 java introduction
1 java introduction
 
1 java intro
1 java intro1 java intro
1 java intro
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).pptJava SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).ppt
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 
JAVA INTRODUCTION - 1
JAVA INTRODUCTION - 1JAVA INTRODUCTION - 1
JAVA INTRODUCTION - 1
 

Comp102 lec 3

  • 2. Java • Programming Language • Developed by: James Gosling at Sun Microsystems in 1991 , referred as OAK • Released in 1995 as core component of Sun Microsystems Java Platform • Derives much of its syntax from C and C++ • Applications are compiled to bytecode that can run on any JVM( Java Virtual Machine) regardless of computer architecture Based on material from: http://en.wikipedia.org/wiki/Java_%28programming_language%29
  • 3. Java Virtual Machine • A virtual machine (VM) is a software implementation of a machine that executes programs like a physical machine1 • JVM enables a set of computer software programs and data structures to use a virtual machine model for the execution of other computer programs and scripts.2 • The model used by a JVM accepts a form of computer intermediate language commonly referred to as Java bytecode.2 • Java bytecode instructions are analogous to machine code, but are intended to be interpreted by a virtual machine Based on material from: 1. http://en.wikipedia.org/wiki/Virtual_machine 2.http://en.wikipedia.org/wiki/Java_Virtual_Machine
  • 4. Java is: • General-purpose • Concurrent • class-based and • Object-oriented, • Is specifically designed to have as few implementation dependencies as possible. • It is intended to let application developers "write once, run anywhere". • Java is considered by many as one of the most influential programming languages of the 20th century, and widely used from application software to web application Based on material from: http://en.wikipedia.org/wiki/Java_%28programming_language%29
  • 5. Principles • There were five primary goals in the creation of the Java language: – It should be "simple, object oriented, and familiar". – It should be "robust and secure". – It should be "architecture neutral and portable". – It should execute with "high performance". – It should be "interpreted, threaded, and dynamic". Design Goals of the JavaTM Programming Language
  • 6. Object Oriented • A technique or way to model real world problems • Many interacting objects exist • Objects interact via messages • Class Vs Object – A class is a user defined data type – Object is any instance of class
  • 7. Object • The fundamental idea behind object-oriented language is to combine into a single unit both – data and – the functions that operate on that data. – Such a unit is called an object • Five basic properties – Identity – Attributes – Behavior – Interface – Life Span
  • 8. Java Program • A java program is defined by a public class that takes the form: public class program-name { optional variable declarations and methods public static void main(String[] args) { statements } optional variable declarations and methods }
  • 9. To compile Java Code • javac program-name.java • For this to work, the javac must be in your shell's path or you must explicitly specify the path to the program (such as c:j2sebinjavac program-name.java). • If the compilation is successful, javac will quietly end and return you to a command prompt. • If you look in the directory, there will now be a program-name.class file. • This file is the compiled version of your program. Once your program is in this form, its ready to run. • If not, or you receive an error message, check for typographical errors in your source code.
  • 10. To RUN(Execute) Java Program • java Program-name
  • 11. Java Comments • The Java programming language supports three kinds of comments: • /* text */ The compiler ignores everything from /* to */. • /** documentation */ This indicates a documentation comment (doc comment, for short). The compiler ignores this kind of comment, just like it ignores comments that use /* and */. The JDK javadoc tool uses doc comments when preparing automatically generated documentation. • // text The compiler ignores everything from // to the end of the line.
  • 12. Java Data and Variables • 8 primitive types – byte – short – int – long – float – double – char – boolean
  • 13. Integer Primitive Data Types Type Size Range byte 8 bits -128 to +127 -32,768 to short 16 bits +32,767 (about)-2 billion int 32 bits to +2 billion (about)-10E18 to long 64 bits +10E18
  • 15. Method to Declare variable • Syntax – DataType VariableName; – Datatype VariableName = InitialValue; • Examples – int yr = 2010; – double value = 89.12 ;
  • 17. Variable • Variables only exist within the structure in which they are defined. • For example, if a variable is created within a method, it cannot be accessed outside the method. • In addition, a different method can create a variable of the same name which will not conflict with the other variable. • A java variable can be thought of as a little box made up of one or more bytes that can hold a value of a particular data type
  • 18. Example class example { public static void main ( String[] args ) { long x = 123; //a declaration of a variable named x with a datatype of long System.out.println("The variable x has: " + x ); } }
  • 19. Java Command Line Arguments • Arguments are passed as a String array to the main method of a class. • The first element (element 0) is the first argument passed not the name of the class