WELCOME TO JAVA
FUNDAMENTAL OF OOP THROUGH JAVA
WHAT IS PROGRAMMING ?
• The answer is that programming is a medium to give task to computer to do something.
• As computer just know Machine language which is just 1 and 0 .
• So computers doesn’t know other than Machine Language .
• So now the question is how to instruct computer , in other words how to told to computer
that do it computer for me ?
WHAT IS PROGRAMMING ?
• The answer is we use a programming language which can human understand but
computers not because computers understand only as I told you guys Machine language .
• So what happens then ha ?
• The thing is that the programming language which we are using is being translated or
converted by compiler or interpreter to Machine language .
• In this way computers understand our language .
WHAT IS JAVA ?
• The answer is java is powerful and fast programming language.
• java can be used to develop specially Android Application .
• Someone who develops means constructs or made application for Android operating
system is called Android app developer .
HELLO WORLD JAVA PROGRAM
public class Main {
public static void main (String [] args)
{
System.out.println ("Hello WOrld");
}
}
LINE #1
• Line 1 starts with a Class.
• A Class is piece of instruction which perform a specific task.
• In a Software Company developers create from 100 to 1000 Classes for developing a
specific Application.
• Class is made up of data members and member functions or methods.
• The left curly bracket i.e { indicates that from here our class starts.
LINE #2
• Line 2 starts with a main method.
• Our main method is also a piece of instruction which perform a specific task.
• The term Public means its accessible everywhere.
• Void means its returns nothing.
• Main is the name of method.
• The left brace means our main method starts from here.
LINE #3
• The line 3 starts with System.out.println which prints out our desired data on the screen .
• The right curly bracket means our main method ends here.
• And the other curly bracket means our Class ends here.
VARIABLE
public class Main {
public static void main (String [] args)
{
int a ;
// variable declaration
a = 10 ;
// variable initialization
System.out.println (a) ;
// call to method to print a
}
}
VARIABLE
• Variable is like a container like container which stores the data.
• Variable is like a box that stores the data.
• The word data is plural and the singular of data is datum.
• Data is a collection of unprocessed items such as audio , video, image, text etc.
• When this data is processed its called as information.
VARIABLE DECLARATION
• When we write the name of variable with data type, this is called Variable declaration.
int a ;
// variable declaration
• Here the int means integer data type just like 1,2,3,4,5,6,7,8,9 and 10 etc.
• The semi colon “ ; “ is a statement terminator which means here our statement ends.
• The double forward slash is a single line comment.
VARIABLE INITIALIZATION
a = 10 ;
// variable initialization
VARIABLE INITIALIZATION
• When we store a specific value in a variable , then this is called variable initialization.
• We can declare variable and initialize variable just in one statement rather than writing
two statements just like that :
int a = 10 ;
DATA TYPES
Integer data type :
The integer data type is data type which include on whole numbers like 1,2,3,4 and 10
and so on.
For instance
int a = 10 ;
DATA TYPES
Float data type :
The float data type is a data type which includes on decimal numbers just like 7.3 , 4.5
and 55.5 etc .
For instance
float a = 10.5F;
System.out.println(a);
DATA TYPES
Character data type :
• The character data type is a data type which includes on a single character and the
single character may be a special symbol like $ dollar sign or number like 1 or may
me upper case alphabet like N or may be lower case alphabet like n .
• We always enclosed a character in single quotes ‘ ’ .
• For instance
DATA TYPES
char a = 'n' ;
char b = 'N' ;
char c = '1' ;
char d = '$' ;
DATA TYPES
String data type :
The string data type is a data which includes on word ,sentence or on a paragraph or
even on a whole book.
We always enclosed a string in double quotes “ ” .
For instance
SIMPLE ADDITION APP
STRUCTURE OF PROGRAM IN JAVA
• By structure of program means , that in how many way we can write a program.
• There are three basic structure of program according to Jaccopini means that each
computer program, we can write In three ways.
• These structure are given as :
1) Sequence structure
2) Control structure
3) Iteration structure
SEQUENCE STRUCTURE
import java.util.Scanner;
public class Main {
public static void main (String[] args)
{
int a = 6 ;
int b = 4 ;
int c = a + b ;
System.out.printf("Your sum is %d",c);
}
}
SEQUENCE STRUCTURE
• This type of structure is actually what called is Sequence structure.
• In Sequence structure the program executes line by line one after another.
• For instance , line 1 will execute i1st and then 2 nd line and 3rd line will execute in this way
and so on.