SlideShare una empresa de Scribd logo
1 de 75
Descargar para leer sin conexión
Hello Everyone!
Welcome to TECHFORT’s
Training
Hello Everyone!
JAVA
Sujit Majety,
Technical Head / Corporate Trainer
Day 1 Agenda
Introduction to Java
• Introduction
• Programming Paradigm
• History
• Features
• Sample Program
• Execution Steps
• JVM
• Data types
• Objects and Classes
• Variables
• Flow Control Statements
Java Introduction
Day 1 : Agenda
Introduction
Lets start our exiting journey from now.
Introduction
•Java is one of the most powerful programming languages.
•Java is cross-platform, object-oriented, network-based,
reliable programming language.
•The slogan of java is “write once and run anywhere”, this
allowed java to gain enormous popularity. Its rapid
ascension and wide acceptance can be traced to its design
and programming features.
•The name “JAVA” came from the name of the coffee seed.
•JAVA released to market in different platforms.
Java Platforms
•A java platform or edition consists of a JRE with a specific set
of libraries for a specific application environment.
PLATFORM KEY CHARACTERISTICS
J2SE Core Java platform designed for applications running on desktop PCs.
J2EE Design, development, assembly, and deployment of business Applications.
J2ME Design of small, embedded applications in consumer devices (such as
mobile phones).
Java Card Design of small Java applications that run on smart cards.
JavaFX Design of Rich Internet Applications (RIAs).
Programming Paradigm
A way of conceptualizing what it means to perform computation
Programming Paradigms
Procedure Oriented
• More emphasis on algorithms.
• Programs divided into functions.
• Most functions share data, less security
to data.
• Data move around the system
between functions, any function can
change the data.
• Adding new code is very difficult.
• Code cannot be re-used.
• E.g. C, VB, Perl, Basic, Fortran
Object Oriented
•More emphasis on data.
•Programs are divided into objects.
•Functions operate on data are tied
together in the data structure.
•Data is secured; it is hidden to external
functions, can be accessed by functions
tied to it.
•Adding new code is very easy.
•Code can be re-used.
•E.g. CPP, Java, VB.Net, C#.Net
History
Where did this start?
History
•Developed by a team led by James Gosling at Sun
Microsystems.
•Sun Microsystems was a company best known for its
workstations.
•Java was originally OAK, designed for use in embedded
consumer electronic application in 1991.
•OAK was redesigned for developing internet applications
and renamed JAVA in 1995.
•Java is inherently object-oriented.
History
Major Release Date Key Characteristics
JDK 1.0 1996 First stable version of Java
JDK 1.1 1997 Inner classes; Java beans; JDBC; RMI; Just in Time (JIT) compiler for Windows
platforms
JDK 1.2 1998 Swing classes; Java IDL; Collections
JDK 1.3 2000 Java platform debugger architecture (JPDA); JavaSound; HotSpot JVM
JDK 1.4 2002 Regular expressions; IPv6 support; image I/O API; non-blocking I/O (nio); XML parser
and XSLT processor
JDK 5.0 2004 Generics; annotations; autoboxing; enumerations; varargs; for each loop
JAVA SE 6 2006 Improved GUI support; improved web service support
JAVA SE 7 2011 New file I/O capabilities; support for new network protocols
JAVA SE 8 2014 Lambda expressions; new date and time API
JAVA SE 9 2016
(expected)
Money and currency API
Features
Features
There are eleven promising features in java
• Simple (no pointers, interfaces, rich set of API, friendly syntaxes)
• Secure (many number of security mechanisms to block stray programs)
• Portable (can run on any operating system)
• Robust (memory management, exceptional handling)
• Distributed (runs on multiple servers and can be accessed by no of clients)
• Interpreted (both compiled and interpreted)
• Multi Threading (multiple flow of controls)
• Dynamic (is always open for updating)
• Architecture Neutral (can run on any processor)
• High Performance (garbage collector, leaves resources wile waiting for inputs)
• Object oriented (everything is written in class)
Our First Java Program
First Java Program
public class Test {
public static void main(String[] args) {
System.out.println("HELLO WORLD");
}
}
javac Test.java
Java Test
HELLO WORLD
Execution Steps
Execution Steps
Text editor
Java
Virtual
Machine
Java
Compiler
Source Code
(.java)
Byte code
(.class)
Output on
Console
Saves Java statements
Produces
Result in
JVM
JVM
•JVM stands for Java Virtual Machine.
•It is abstract machine.
•It is a specification that provides runtime environment in which
java byte code can be executed.
•JVM’s are available for many hardware and software platforms
(i.e. JVM is platform dependant).
•JVM performs four main tasks,
Loads code
Verifies code
Executes code
Provides runtime environment.
JVM
Class
file
Class Loader
Subsystem
Runtime
Data
areas
Method
area
Heap Stack
PC
Registers
Native
Method
area
Execution Engine
JVM JIT
Data Types
Data Types
• Java supports UNICODE character set. Hence, each character is
represented in two bytes.
• In java every variable has a type, every expression has a type and all
assignments should be checked by the compiler for type compatibility.
Hence, java is treated as strongly typed language.
• We are having 8 primitive data types.
• These data types fall under 3 categories.
• Numeric Data types
• Character Data types
• Boolean Data types
Data Types
DATA TYPE SIZE RANGE DEFAULT VALUE
byte 8 bit -128 to 127 0
short 16 bit -32768 to 32767 0
int 32 bit -2,147,483,648 to 2,147,483, 647 0
long 64 bit -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
0L
float 32 bit approximately ±3.40282347E+38F 0.0f
double 64 bit approximately
±1.79769313486231570E+308
0.0d
char 16 bit 0 to 65,536 (unsigned) ‘u0000’
boolean not precisely
defined
true or false false
Object Oriented Programming
OOP
• Object oriented programming models the real world.
• Object oriented programming organizes a program around its data and set of well
defined interfaces to that data.
• An object-oriented program can be characterized as data controlling access to
code.
• By switching the controlling entity to data, you can achieve several organizational
benefits.
• Object oriented programming, the first letter indicates object.
• What is an object?
Object
•An object is the basic unit of object orientation with
behaviour and identity.
•An object is a real time entity. E.g.. Car, bike, book, me
and you.
•It is a runtime entity that has a state and behaviour.
•The state of the object represents the data.
•The behaviour is represented by the methods.
•E.g. An object is created to represent a rabbit.
It would have data: how hungry it is, where it is.
And methods : eat, hide, run and dig.
Class
• A class is a way of binding the data and associated methods into a
single unit.
• A class can also be said as a blue print to create an object.
• If we want to develop a java program, then that should be developed
with respective of class only. i.e. without class there is no java program.
• Syntax:
class <class_name>
{
Variable declaration;
Methods definition;
};
Class Name
Data members/
properties/
Attributes
Behaviours/
Methods
Animal
Name,
Number of legs,
Colour
Eat(),
Walk(),
Sleep()
Example
class Bicycle {
int cadence = 0;
int speed = 0;
int gear = 1;
void changeCadence(int newValue) {
cadence = newValue;
}
void changeGear(int newValue) {
gear = newValue;
}
void speedUp(int increment) {
speed = speed + increment;
}
void applyBrakes(int decrement) {
speed = speed - decrement;
}
void printStates() {
System.out.println("cadence:" +
cadence + " speed:" +
speed + " gear:" +
gear);
}
}
Variables
Variables
•A variable is a name given to a memory location.
•Generally there are three types of variables.
•Variable Types
Local Variables, are the variables that are declared inside a
method
Instance Variables, are the variables that are declared outside the
methods
Static Variables, are the variables that are declared outside the
methods with static keyword.
Flow Control Statements
Flow Control Statements
•A statement is an instruction that executes at runtime.
•Types of Statements
1. Sequential Statements
2. Conditional Statements
3. Iterative / Looping Statements
4. Branching Statements
Sequential Statements
Sequential Statements
•These statements execute
sequentially without
interruption one after the
other.
•All the statements we have
executed so far come under
sequential statements.
Conditional Statements
Conditional Statements
•These statements execute
based on a condition’s
success or failure.
•Types :
1. If
2. If-Else
3. Nested If-Else
4. IF-Else Ladder
If Condition
If Condition
•A simple if condition checks
for the condition and will
decide to process the
statements or not.
•Statement 1 and Statement 2
are conditional statements as
they depend on the
condition for executing.
Statement 1;
Statement 2;
If Syntax
if(condition){
statement 1;
statement 2;
statement 3;
}
If-Else Condition
If-Else Condition
•This construct consists of two
statements. (if and else).
•If the condition is success
some statements will get
executed, if failure other
statements will get executed. Statement 1;
Statement 2;
Statement 1;
Statement 2;
If-Else Syntax
if(condition){
statement 1;
statement 2;
}
else{
statement 3;
statement 4;
}
Nested If-Else
Nested If-Else Condition
•If else construct within either
the body of if statement or
the body of an else
statement or both. This
scenario is said to be Nested
If-else
Nested If-Else Syntax
if(condition){
statement 1;
}
else(condition2){
if(condition){
statement 2;
}
else{
statement 3;
}
}
If-Else Ladder
If-Else Ladder
•If-Else ladder is used to check
multiple conditions.
•Here, every else is associated
with it’s previous if.
•The last else will go to work
only if all the conditions fail.
•Even in else if ladder the last
else is optional.
If-Else Ladder Syntax
if(condition){
statement 1;
}
else if(condition){
statement 3;
}
else{
statement 4;
}
Switch-Case Statement
Switch-Case Statement
•Java has a built-in multiple-
branch selection statement,
called switch, which
successively tests the value of
an expression against a list of
integer or character
constants
•When a match is found the
statements associated with
that constant are executed.
Switch-Case Syntax
switch(expression){
case constant1 : Statement1;
break;
case constant2 : Statement2;
break;
case constant3 : Statement3;
break;
default : Statement4;
}
Iterative Statements
Iterative Statements
•Some times there will be a need to
repeat the execution of certain
statements for certain number of times.
•This can be achieved using Loops.
1. While
2. Do-While
3. For
While Loop
While loop
•A while loop has a loop condition only
that is tested before each iteration to
decide whether to continue or
terminate the loop.
•Hence while loop is said to be entry
controlled loop.
While loop Syntax
while(condition){
Statement1;
Statement2;
Statement3;
---
---
---
}
Do-While Loop
Do-While loop
•A do-while loop has a loop condition
only that is tested after each iteration
to decide whether to continue or
terminate the loop.
•Hence, do-while loop is said to be exit
controlled loop.
•Even the condition fails every time the
contents will be executed at least
once.
Do-While Syntax
do{
Statement1;
Statement2;
---
---
---
}while(condition);
For Loop
For loop
• A For loop contains 3 parts.
• Initializer i.e. executed once at the start of
the loop.
• Loop Condition i.e. tested before iteration to
decide whether to continue or terminate the
loop.
• Increment/Decrement i.e. executed at the
end of each loop iteration.
• Hence, for loop is said to be entry controlled
loop.
For Loop Syntax
for(initializer; condition; increment/decrement){
Statement1;
Statement2;
---
---
---
---
}
Foreach Loop
Foreach Loop
•This is an advanced for loop, used to traverse array or
collection elements.
•The advantage of this for loop over traditional is it eliminates
the possibility of bugs and makes the code more readable.
•Syntax:
for( data_type variable : array|collection){}
•The variable will hold on to single value for each iteration
and stores the next value for the next iteration.
Jumping Control Statements
Jumping Control Statements
• Java provides support to some more control statements.
• These statements are used to move the control from one place of a
program to another place.
• These instructions are implemented by using the following statements.
1. Break
2. Continue
3. Go To
Break
• This keyword is used to stop the
loop and go to the statement
following he statement.
• Break can be written with or
without condition.
• Syntax:
break;
Continue
• Continue is a keyword used to skip
iterations.
• When continue is encountered in a loop
the control stops the current iteration i.e. it
will not execute the statements following
it.
• It can also be used with or without
condition.
• Syntax:
continue;
Go TO
• Goto is a specific control statement.
• It is used to jump the control from one part
of the program to other part of the
program.
• It can be used for either as forward or as
backward.
• When forward goto is used the statements
between the goto statement and label
statement will be skipped.
• When backward goto is used the
statements between the goto and label
statements will be repeatedly executed
infinitely if not stopped with a condition.
Important Interview Questions
• What is the most widely used protocol on internet
• What is the difference between an executable file and .class file?
• Why java is suitable for internet?
• Why pointers are eliminated in java?
• What is the difference between a function and a method?
• Which part of the JVM will allocate the memory for java program?
• Which algorithm is used by garbage collector to remove the unused
variables or objects from memory?
Assignments
• Check the hello world program by removing each and every word.
• Shuffle the order of public static void main
• Try experimenting with print & println.
• Try giving different names for args.
• Try giving int args[] instead of String args[] in main.
• Give Different name for the filename and the class name
• Repeat the above problem with declaring class as public
• Copy the class file into different folder name and execute it.
• Write your own program, compile it and execute it.
• Try giving different data types ( the one you know like int x, double d ) in the println
and see if it prints all of them.
• I have two Integers int x =1; and int x=2; I wish to print 12. find the ways to print.
• Repeat the same if I want to print given int x=1; double d=2.5; and print 12 instead of
12.5
Assignments
• Create new classes for each real-world object that you observed at the beginning of
this trail. Refer to the Bicycle class if you forget the required syntax.
• Create a small program that defines some fields. Try creating some illegal field names
and see what kind of error the compiler produces. Use the naming rules and
conventions as a guide.
• In the program you created in Exercise 1, try leaving the fields uninitialized and print
out their values. Try the same with a local variable and see what kind of compiler
errors you can produce. Becoming familiar with common compiler errors will make it
easier to recognize bugs in your code.
Thank You!
Sujit Majety, Technical Head/Software Trainer
SUJIT MAJETY
Technical Head / Corporate Trainer
Techfort Software Solutions PVT. LTD.
Mail To : sujit.majety@gmail.com
Call To : 040-40062299
View Link : http://tinyurl.com/techfort-java1
Feedback : http://tinyurl.com/mrcewfeedback

Más contenido relacionado

La actualidad más candente

Core Java
Core JavaCore Java
Core JavaNA
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of javavinay arora
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsMahika Tutorials
 
Training on Core java | PPT Presentation | Shravan Sanidhya
Training on Core java | PPT Presentation | Shravan SanidhyaTraining on Core java | PPT Presentation | Shravan Sanidhya
Training on Core java | PPT Presentation | Shravan SanidhyaShravan Sanidhya
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java Ravi_Kant_Sahu
 
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...Edureka!
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVAKUNAL GADHIA
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programmingElizabeth Thomas
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core javamahir jain
 

La actualidad más candente (20)

Core Java
Core JavaCore Java
Core Java
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
Introduction of java
Introduction  of javaIntroduction  of java
Introduction of java
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of java
 
Core java slides
Core java slidesCore java slides
Core java slides
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Core Java
Core JavaCore Java
Core Java
 
Training on Core java | PPT Presentation | Shravan Sanidhya
Training on Core java | PPT Presentation | Shravan SanidhyaTraining on Core java | PPT Presentation | Shravan Sanidhya
Training on Core java | PPT Presentation | Shravan Sanidhya
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
 
Core java
Core java Core java
Core java
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
 
Java basic
Java basicJava basic
Java basic
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVA
 
JDK,JRE,JVM
JDK,JRE,JVMJDK,JRE,JVM
JDK,JRE,JVM
 
Jdk,jre,jvm
Jdk,jre,jvmJdk,jre,jvm
Jdk,jre,jvm
 
Core java
Core java Core java
Core java
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 

Similar a Introduction to java (revised)

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 3rdprat0ham
 
1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptxBhargaviDalal3
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept Prakash Poudel
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxMurugesh33
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxMurugesh33
 
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf10322210023
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to JavaSoumya Suman
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Java Lover
 
JAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptxJAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptx20EUEE018DEEPAKM
 
Lecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 FastLecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 FastUzairSaeed18
 

Similar a Introduction to java (revised) (20)

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
 
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
 
1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
Java programming and security
Java programming and securityJava programming and security
Java programming and security
 
Java basic
Java basicJava basic
Java basic
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept
 
Letest
LetestLetest
Letest
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
 
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
 
Java
JavaJava
Java
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
unit1.pptx
unit1.pptxunit1.pptx
unit1.pptx
 
JAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptxJAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptx
 
Lecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 FastLecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 Fast
 

Último

Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxAneriPatwari
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptxAneriPatwari
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptxmary850239
 

Último (20)

Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptx
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx
 

Introduction to java (revised)

  • 1. Hello Everyone! Welcome to TECHFORT’s Training
  • 4. • Introduction • Programming Paradigm • History • Features • Sample Program • Execution Steps • JVM • Data types • Objects and Classes • Variables • Flow Control Statements Java Introduction Day 1 : Agenda
  • 5. Introduction Lets start our exiting journey from now.
  • 6. Introduction •Java is one of the most powerful programming languages. •Java is cross-platform, object-oriented, network-based, reliable programming language. •The slogan of java is “write once and run anywhere”, this allowed java to gain enormous popularity. Its rapid ascension and wide acceptance can be traced to its design and programming features. •The name “JAVA” came from the name of the coffee seed. •JAVA released to market in different platforms.
  • 7. Java Platforms •A java platform or edition consists of a JRE with a specific set of libraries for a specific application environment. PLATFORM KEY CHARACTERISTICS J2SE Core Java platform designed for applications running on desktop PCs. J2EE Design, development, assembly, and deployment of business Applications. J2ME Design of small, embedded applications in consumer devices (such as mobile phones). Java Card Design of small Java applications that run on smart cards. JavaFX Design of Rich Internet Applications (RIAs).
  • 8. Programming Paradigm A way of conceptualizing what it means to perform computation
  • 9. Programming Paradigms Procedure Oriented • More emphasis on algorithms. • Programs divided into functions. • Most functions share data, less security to data. • Data move around the system between functions, any function can change the data. • Adding new code is very difficult. • Code cannot be re-used. • E.g. C, VB, Perl, Basic, Fortran Object Oriented •More emphasis on data. •Programs are divided into objects. •Functions operate on data are tied together in the data structure. •Data is secured; it is hidden to external functions, can be accessed by functions tied to it. •Adding new code is very easy. •Code can be re-used. •E.g. CPP, Java, VB.Net, C#.Net
  • 11. History •Developed by a team led by James Gosling at Sun Microsystems. •Sun Microsystems was a company best known for its workstations. •Java was originally OAK, designed for use in embedded consumer electronic application in 1991. •OAK was redesigned for developing internet applications and renamed JAVA in 1995. •Java is inherently object-oriented.
  • 12. History Major Release Date Key Characteristics JDK 1.0 1996 First stable version of Java JDK 1.1 1997 Inner classes; Java beans; JDBC; RMI; Just in Time (JIT) compiler for Windows platforms JDK 1.2 1998 Swing classes; Java IDL; Collections JDK 1.3 2000 Java platform debugger architecture (JPDA); JavaSound; HotSpot JVM JDK 1.4 2002 Regular expressions; IPv6 support; image I/O API; non-blocking I/O (nio); XML parser and XSLT processor JDK 5.0 2004 Generics; annotations; autoboxing; enumerations; varargs; for each loop JAVA SE 6 2006 Improved GUI support; improved web service support JAVA SE 7 2011 New file I/O capabilities; support for new network protocols JAVA SE 8 2014 Lambda expressions; new date and time API JAVA SE 9 2016 (expected) Money and currency API
  • 14. Features There are eleven promising features in java • Simple (no pointers, interfaces, rich set of API, friendly syntaxes) • Secure (many number of security mechanisms to block stray programs) • Portable (can run on any operating system) • Robust (memory management, exceptional handling) • Distributed (runs on multiple servers and can be accessed by no of clients) • Interpreted (both compiled and interpreted) • Multi Threading (multiple flow of controls) • Dynamic (is always open for updating) • Architecture Neutral (can run on any processor) • High Performance (garbage collector, leaves resources wile waiting for inputs) • Object oriented (everything is written in class)
  • 15. Our First Java Program
  • 16. First Java Program public class Test { public static void main(String[] args) { System.out.println("HELLO WORLD"); } } javac Test.java Java Test HELLO WORLD
  • 18. Execution Steps Text editor Java Virtual Machine Java Compiler Source Code (.java) Byte code (.class) Output on Console Saves Java statements Produces Result in
  • 19. JVM
  • 20. JVM •JVM stands for Java Virtual Machine. •It is abstract machine. •It is a specification that provides runtime environment in which java byte code can be executed. •JVM’s are available for many hardware and software platforms (i.e. JVM is platform dependant). •JVM performs four main tasks, Loads code Verifies code Executes code Provides runtime environment.
  • 23. Data Types • Java supports UNICODE character set. Hence, each character is represented in two bytes. • In java every variable has a type, every expression has a type and all assignments should be checked by the compiler for type compatibility. Hence, java is treated as strongly typed language. • We are having 8 primitive data types. • These data types fall under 3 categories. • Numeric Data types • Character Data types • Boolean Data types
  • 24. Data Types DATA TYPE SIZE RANGE DEFAULT VALUE byte 8 bit -128 to 127 0 short 16 bit -32768 to 32767 0 int 32 bit -2,147,483,648 to 2,147,483, 647 0 long 64 bit -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 0L float 32 bit approximately ±3.40282347E+38F 0.0f double 64 bit approximately ±1.79769313486231570E+308 0.0d char 16 bit 0 to 65,536 (unsigned) ‘u0000’ boolean not precisely defined true or false false
  • 26. OOP • Object oriented programming models the real world. • Object oriented programming organizes a program around its data and set of well defined interfaces to that data. • An object-oriented program can be characterized as data controlling access to code. • By switching the controlling entity to data, you can achieve several organizational benefits. • Object oriented programming, the first letter indicates object. • What is an object?
  • 27. Object •An object is the basic unit of object orientation with behaviour and identity. •An object is a real time entity. E.g.. Car, bike, book, me and you. •It is a runtime entity that has a state and behaviour. •The state of the object represents the data. •The behaviour is represented by the methods. •E.g. An object is created to represent a rabbit. It would have data: how hungry it is, where it is. And methods : eat, hide, run and dig.
  • 28. Class • A class is a way of binding the data and associated methods into a single unit. • A class can also be said as a blue print to create an object. • If we want to develop a java program, then that should be developed with respective of class only. i.e. without class there is no java program. • Syntax: class <class_name> { Variable declaration; Methods definition; }; Class Name Data members/ properties/ Attributes Behaviours/ Methods Animal Name, Number of legs, Colour Eat(), Walk(), Sleep()
  • 29. Example class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) { speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println("cadence:" + cadence + " speed:" + speed + " gear:" + gear); } }
  • 31. Variables •A variable is a name given to a memory location. •Generally there are three types of variables. •Variable Types Local Variables, are the variables that are declared inside a method Instance Variables, are the variables that are declared outside the methods Static Variables, are the variables that are declared outside the methods with static keyword.
  • 33. Flow Control Statements •A statement is an instruction that executes at runtime. •Types of Statements 1. Sequential Statements 2. Conditional Statements 3. Iterative / Looping Statements 4. Branching Statements
  • 35. Sequential Statements •These statements execute sequentially without interruption one after the other. •All the statements we have executed so far come under sequential statements.
  • 37. Conditional Statements •These statements execute based on a condition’s success or failure. •Types : 1. If 2. If-Else 3. Nested If-Else 4. IF-Else Ladder
  • 39. If Condition •A simple if condition checks for the condition and will decide to process the statements or not. •Statement 1 and Statement 2 are conditional statements as they depend on the condition for executing. Statement 1; Statement 2;
  • 42. If-Else Condition •This construct consists of two statements. (if and else). •If the condition is success some statements will get executed, if failure other statements will get executed. Statement 1; Statement 2; Statement 1; Statement 2;
  • 43. If-Else Syntax if(condition){ statement 1; statement 2; } else{ statement 3; statement 4; }
  • 45. Nested If-Else Condition •If else construct within either the body of if statement or the body of an else statement or both. This scenario is said to be Nested If-else
  • 46. Nested If-Else Syntax if(condition){ statement 1; } else(condition2){ if(condition){ statement 2; } else{ statement 3; } }
  • 48. If-Else Ladder •If-Else ladder is used to check multiple conditions. •Here, every else is associated with it’s previous if. •The last else will go to work only if all the conditions fail. •Even in else if ladder the last else is optional.
  • 49. If-Else Ladder Syntax if(condition){ statement 1; } else if(condition){ statement 3; } else{ statement 4; }
  • 51. Switch-Case Statement •Java has a built-in multiple- branch selection statement, called switch, which successively tests the value of an expression against a list of integer or character constants •When a match is found the statements associated with that constant are executed.
  • 52. Switch-Case Syntax switch(expression){ case constant1 : Statement1; break; case constant2 : Statement2; break; case constant3 : Statement3; break; default : Statement4; }
  • 54. Iterative Statements •Some times there will be a need to repeat the execution of certain statements for certain number of times. •This can be achieved using Loops. 1. While 2. Do-While 3. For
  • 56. While loop •A while loop has a loop condition only that is tested before each iteration to decide whether to continue or terminate the loop. •Hence while loop is said to be entry controlled loop.
  • 59. Do-While loop •A do-while loop has a loop condition only that is tested after each iteration to decide whether to continue or terminate the loop. •Hence, do-while loop is said to be exit controlled loop. •Even the condition fails every time the contents will be executed at least once.
  • 62. For loop • A For loop contains 3 parts. • Initializer i.e. executed once at the start of the loop. • Loop Condition i.e. tested before iteration to decide whether to continue or terminate the loop. • Increment/Decrement i.e. executed at the end of each loop iteration. • Hence, for loop is said to be entry controlled loop.
  • 63. For Loop Syntax for(initializer; condition; increment/decrement){ Statement1; Statement2; --- --- --- --- }
  • 65. Foreach Loop •This is an advanced for loop, used to traverse array or collection elements. •The advantage of this for loop over traditional is it eliminates the possibility of bugs and makes the code more readable. •Syntax: for( data_type variable : array|collection){} •The variable will hold on to single value for each iteration and stores the next value for the next iteration.
  • 67. Jumping Control Statements • Java provides support to some more control statements. • These statements are used to move the control from one place of a program to another place. • These instructions are implemented by using the following statements. 1. Break 2. Continue 3. Go To
  • 68. Break • This keyword is used to stop the loop and go to the statement following he statement. • Break can be written with or without condition. • Syntax: break;
  • 69. Continue • Continue is a keyword used to skip iterations. • When continue is encountered in a loop the control stops the current iteration i.e. it will not execute the statements following it. • It can also be used with or without condition. • Syntax: continue;
  • 70. Go TO • Goto is a specific control statement. • It is used to jump the control from one part of the program to other part of the program. • It can be used for either as forward or as backward. • When forward goto is used the statements between the goto statement and label statement will be skipped. • When backward goto is used the statements between the goto and label statements will be repeatedly executed infinitely if not stopped with a condition.
  • 71. Important Interview Questions • What is the most widely used protocol on internet • What is the difference between an executable file and .class file? • Why java is suitable for internet? • Why pointers are eliminated in java? • What is the difference between a function and a method? • Which part of the JVM will allocate the memory for java program? • Which algorithm is used by garbage collector to remove the unused variables or objects from memory?
  • 72. Assignments • Check the hello world program by removing each and every word. • Shuffle the order of public static void main • Try experimenting with print & println. • Try giving different names for args. • Try giving int args[] instead of String args[] in main. • Give Different name for the filename and the class name • Repeat the above problem with declaring class as public • Copy the class file into different folder name and execute it. • Write your own program, compile it and execute it. • Try giving different data types ( the one you know like int x, double d ) in the println and see if it prints all of them. • I have two Integers int x =1; and int x=2; I wish to print 12. find the ways to print. • Repeat the same if I want to print given int x=1; double d=2.5; and print 12 instead of 12.5
  • 73. Assignments • Create new classes for each real-world object that you observed at the beginning of this trail. Refer to the Bicycle class if you forget the required syntax. • Create a small program that defines some fields. Try creating some illegal field names and see what kind of error the compiler produces. Use the naming rules and conventions as a guide. • In the program you created in Exercise 1, try leaving the fields uninitialized and print out their values. Try the same with a local variable and see what kind of compiler errors you can produce. Becoming familiar with common compiler errors will make it easier to recognize bugs in your code.
  • 74. Thank You! Sujit Majety, Technical Head/Software Trainer
  • 75. SUJIT MAJETY Technical Head / Corporate Trainer Techfort Software Solutions PVT. LTD. Mail To : sujit.majety@gmail.com Call To : 040-40062299 View Link : http://tinyurl.com/techfort-java1 Feedback : http://tinyurl.com/mrcewfeedback