You are on page 1of 37

JAVA

PROGRAMMING

by
S.PARAMASIVAM
JAVA PROGRAMMING
Day 1:
•Getting Started with Java,
• Syntax,
•Comments,
•variables and Data types
JAVA PROGRAMMING
INTRODUCTION TO JAVA PROGRAMMING

Java is a Programming Language

The word “Java” meaning is “Hot Coffee”

Developed by a team lead by James Gosling


JAVA PROGRAMMING
• The Java developers,
• Who drank a lot of coffee while working on the language.
• Java coffee beans
• They named their developed language as JAVA
• It was originally named as OAK later named as JAVA
JAVA PROGRAMMING
• Programming Conventions

Two types

• 1-Procedural Programming 2-Object Oriented Programming


JAVA PROGRAMMING
• 1. Procedural Programming

• Well Structured steps and procedures


• Systematic order of statements
• Functions
• and commands
JAVA PROGRAMMING
• 2. Object Oriented Programming
Object Oriented Programming System (OOPS)
JAVA PROGRAMMING
• 2. Object Oriented Programming

• Systematic approach for problem solving


• There is no step by step procedures
• All statements and methods (functions) defined
inside the class
• From the classes Objects are created
JAVA PROGRAMMING
JAVA PROGRAMMING
JAVA PROGRAMMING
DIFFERENCES
PROCEDURAL ORIENTED OBJECT ORIENTED
PROGRAMMING (POP) PROGRAMMING (OOP)
Top down approach Bottom up approach

Concentrated on Functions Concentrated on data rather than functions

Data uses globally Data used by associated function within the


class
Due to global data less secure language It is more secure language because external
functions can’t access another data
Example: FORTRAN, BASIC, COBAL, Pascal, C, C++, Java, Python, Lisp, Perl
JAVA PROGRAMMING
• Getting Started with Java

Java is highly case sensitive language


Java is Object Oriented Language
Java is Compiled--Interpreted Language
javac is a java compiler
java is Java Virtual Machine(JVM) a Interpreter
JAVA PROGRAMMING
• Getting Started with Java

Your First Program – FirstProgram.java


class FirstProgram
{  
    public static void main( String[] args )
{  
     System.out.println(“WELCOME TO JAVA PROGRAMMING");  
}  
}  
JAVA PROGRAMMING
• Getting Started with Java
Your First Program – FirstProgram.java

1.System: It is a final class defined in the java.lang package.


2.out: This is an instance of PrintStream type, which is a public and static
member field of the System class.
3.println(): As all instances of PrintStream class have a public method
println(), hence we can invoke the same on out as well. This is an
upgraded version of print(). It prints any argument passed to it and
adds a new line to the output. We can assume that System.out
represents the Standard Output Stream.
JAVA PROGRAMMING
• Getting Started with Java

Your First Program – FirstProgram.java


Save the file as FirstProgram.java
Compile the java program using javac compiler
C:\>javac FirstProgram.java
Run the program using the Java Virtual Machine
C:\>java Firstprogram
JAVA PROGRAMMING
Your First Program – FirstProgram.java
class FirstProgram
{  
    public static void main( String[] args )
{  
     System.out.println(“WELCOME TO JAVA PROGRAMMING");  
}  
}  

C:\>javac FirstProgram.java
C:\>java Firstprogram
WELCOME TO JAVA PROGRAMMING
JAVA PROGRAMMING
Syntax
•Java Four Basic Syntax

•Class: The class is a blueprint (plan)


•Object: The object is an instance of a class. ...
•Method: The behaviour of an object is the method. ...
•Instance variables: Every object has its own unique
set of instance variables.
JAVA PROGRAMMING
Syntax
•Java Basic Syntax
•Class: The class is a blueprint (plan)
class classname
{
Class Variables;
Class Methods;
}
}  
JAVA PROGRAMMING
Syntax
•Java Basic Syntax

•Object: The object is an instance of a class. ...

classname objectname=new classname();


Or

classname objectname;

objectname=new classname();
JAVA PROGRAMMING
Syntax
•Java Basic Syntax
•Method: The behaviour of an object is the method. ...

methodreturntype methodname(type1 var1, type2 var2…)


{
// Method Contents
}
JAVA PROGRAMMING
Syntax
JAVA PROGRAMMING
Syntax
• Instance variables: Every object has its own unique set of instance
variables.
public class Vehicle
{ private int doors; Instance
private int speed; Variables
private String color;

public void run()


{ }
}
JAVA PROGRAMMING
Java Comments
/* This is my First Java Program
* This will Print WELCOME TO JAVA PROGRAMMING
*/
class FirstProgram
{  
     public static void main( String[] args )
{  
    System.out.println(“WELCOME TO JAVA PROGRAMMING");  
}  
}  
JAVA PROGRAMMING
Java Comments
// This is my First Java Program
// This will Print WELCOME TO JAVA PROGRAMMING
class FirstProgram
{  
     public static void main( String[] args )
{  
    System.out.println(“WELCOME TO JAVA PROGRAMMING");  
}  
}  
// Program Ends
JAVA PROGRAMMING
Java Comments
// This is my First Java Program
class FirstProgram
{   // Comments inside the Class
     public static void main( String[] args )
{   // Comments inside the main method
    System.out.println(“WELCOME TO JAVA PROGRAMMING");  
}  
}  
// Program Ends
JAVA PROGRAMMING
• Java Data Types

1. Primitive Data Types


2. Non Primitive Data Types
JAVA PROGRAMMING
Java Data Types
Integer TypesFractional Data types Character Data types
byte float char
short double
int
long

Boolean Type
boolean
JAVA PROGRAMMING
JAVA PROGRAMMING
Java Data Types
Non Primitive Data Types

Strings
Arrays
User Defined Classes / Interfaces
JAVA PROGRAMMING
Java Data Types
Data Type Size Description
byte 1 byte Stores whole numbers from -128 to 127

short 2 bytes Stores whole numbers from -32,768 to 32,767

int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647

long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to


9,223,372,036,854,775,807

float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits

double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits

boolean 1 bit Stores true or false values

char 2 bytes Stores a single character/letter or ASCII values


JAVA PROGRAMMING
Variables
datatype variablename;
JAVA PROGRAMMING
Variables
Syntax
datatype variablename;
datatype variablename = value;
Example
int number = 107 ;
float interest = 6.75 ;
String name = “Alice”
JAVA PROGRAMMING
Variables
final Variables / Constants
final datatype variablename = value ;
Example
final int no = 105;
no = 201; // Creates Error final variables Unchangeable
JAVA PROGRAMMING
Variables
• Rules of Declaring variables in Java
• A variable name can consist of Capital letters A-Z, lowercase
letters a-z, digits 0-9, and two special characters such as
underscore and dollar Sign.
• The first character must be a letter/underscore.
• Blank spaces cannot be used in variable names.
• Java keywords cannot be used as variable names.
JAVA PROGRAMMING
Variables
• Rules of Declaring variables in Java
Valid Variables Invalid Variables
number 7value
no2 #no
myNameYour Name
CARTYPEpublic
vehicle bus*
JAVA PROGRAMMING

Questions ?

You might also like