0% found this document useful (0 votes)
60 views

Introduction To Java Programming

This document provides an introduction to Java programming including: - An overview of Java applications, primitive data types, control flow, methods, and object-oriented programming. - Descriptions of Java's history and key characteristics like being simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, multithreaded, and dynamic. - Explanations of primitive data types like byte, short, int, long, float, double, char, and boolean as well as operators, expressions, and errors. - Details on control structures like if/else statements, switch statements, loops, breaks and continues. - A discussion of methods including structure, declaration,

Uploaded by

Lakshmi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Introduction To Java Programming

This document provides an introduction to Java programming including: - An overview of Java applications, primitive data types, control flow, methods, and object-oriented programming. - Descriptions of Java's history and key characteristics like being simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, multithreaded, and dynamic. - Explanations of primitive data types like byte, short, int, long, float, double, char, and boolean as well as operators, expressions, and errors. - Details on control structures like if/else statements, switch statements, loops, breaks and continues. - A discussion of methods including structure, declaration,

Uploaded by

Lakshmi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

Introduction to

Java Programming
Introduction
– Java applications and applets
– Primitive data types
– Java control flow
– Methods
– Object-oriented programming
Fundamentals of Programming

– Introduction to Java
– Primitive Data Types and Operations
– Control Statements
– Methods
Introduction to Java
 What Is Java?
 Getting Started With Java Programming
– Compiling and Running a Java Application
What Is Java?
 History
 Characteristics of Java
History
 James Gosling
 Oak
 Java, May 20, 1995, Sun World
 HotJava
– The first Java-enabled Web browser
Characteristics of Java
 Java is simple
 Java is object-oriented
 Java is distributed
 Java is interpreted
 Java is robust
 Java is secure
 Java is architecture-neutral
 Java is portable
 Java’s performance
 Java is multithreaded
 Java is dynamic
Getting Started with Java
Programming
 A Simple Java Application
 Compiling Programs
 Executing Applications
A Simple Application
Example 1.1
//This application program prints Welcome
//to Java!
public class Welcome
{
public static void main(String[] args)
{
System.out.println("Welcome to Java!");
}
}
Compiling Programs
 On command line
– javac file.java
Executing Applications
 On command line
– java classname

Bytecode

Java Java Java


Interpreter Interpreter Interpreter
...
on Windows on Linux on Sun Solaris
Example
javac Welcome.java

java Welcome

output:...
Primitive Data Types and Operations
 Identifiers, Variables, and Constants
 Primitive Data Types
– Byte, short, int, long, float, double, char, boolean
 Operators
– +, -, *, /, %, +=, -=, *=, /=, %=, ++, --
 Expressions
 Style and Documentation
 Syntax Errors, Runtime Errors, and Logic Errors
Numerical Data Types

byte 8 bits
short 16 bits
int 32 bits
long 64 bits
float 32 bits
double 64 bits
Control Statements
Selection
Statements
–Using if and if...else
–Nested if Statements
–Using switch Statements
–Conditional Operator
Repetition Statements
–Looping: while, do, and for
–Nested loops
–Using break and continue
Selection Statements
 if Statements
 switch Statements
 Conditional Operators
if Statements
if (booleanExpression)
{
statement(s);
}

Example:
if ((i >= 0) && (i <= 10))
{
System.out.println("i is an “ +
“integer between 0 and 10");
}
The if...else Statement
if (booleanExpression)
{
statement(s)-for-the-true-case;
}
else
{
statement(s)-for-the-false-case;
}
Repetitions
 while Loops
 do Loops
 for Loops
 break and continue
Introducing Methods
Method Structure
A method is a modifier methodName

collection of returnValueType parameters

statements that are method


heading
public static int max(int num1, int num2)
{
grouped together method
int result = 0;

to perform an
body
if (num1 > num2)
result = num1;
operation. else
result = num2;

return result;
}
return value
Declaring Methods

public static int max(int num1,


int num2)
{
if (num1 > num2)
return num1;
else
return num2;
}
Passing Parameters
void nPrintln(String message, int n)
{
for (int i=0; i<n; i++)
System.out.println(message);
}
Object-Oriented Programming

– Objects and Classes


– Class Inheritance
Exception Handling
 Exceptions and Exception Types
 Claiming Exceptions
 Throwing Exceptions
 Catching Exceptions
 The finally Clause

You might also like