SlideShare una empresa de Scribd logo
1 de 49
PROGRAMMING IN JAVA
Dr.K.Kalaiselvi
Dept of Computer Science
Kristu Jayanti college
Bangalore
Course Objective
To inculcate knowledge about the fundamentals of OOPs(Object
oriented programming)
To provide knowledge about developing java applications and
applets
Creating GUI based Java apps and applets that run in a consistent
manner across all platforms. (swings).
1. Balagurusamy.E. Programming with JAVA a Primer.
NewDelhi : Tata McGraw- Hill Publishing Company
Limited.
2.Herbert Schildt. The Complete Reference- Java (7th ed.).
New Delhi : Tata McGraw-Hill Publishing Company
Limited.
Refer : http://javabeginnerstutorial.com/core-java/
Books & References
Introduction to java
Unit-1
4
• Object oriented programming concepts
• Structure of Java programs
• Compiling and running the program
• Printing messages to the screen
Learning outcome of this unit
6
UNIT1:IntroductiontoJavaandFeaturesofJava10hrs
History; Evolution of Java; How Java changed internet; Fundamentals of object-Oriented
programming; Basic concepts of object-oriented programming; Benefits of object-oriented
programming; Features of Java; How Java differs from C And C++; Overview of Java; Simple
Java program; Structure; Java development kit (JDK); Java interpreter; Java virtual machine.
Data types; Variable; Type conversion and casting; Operators and expressions; Programming
structure; Operators and expressions; Decision-making and branching: If; If.. Else; Nested If;
Switch; ?: Operator; Looping: While; Do; For – Jumps In Loops - Labeled loops; Array – Types
ofarrays;Stringhandling.
Some Basics
Q. What is a program?
Ans. A sequence of instructions that a computer can interpret
and execute.
Q. Why Java and not Hindi / Marathi / English?
Ans. Since, so far, computer is not intelligent enough to
understand natural languages.
Contents
 History
 First Java Application
 Data types
 Variables
 Strings
 Assignments
 Math, Boolean expressions
 Relational operations
 If statements
 System.exit
8
What is java?
 A general-purpose object-oriented language.
 Write Once Run Anywhere (WORA).
 Designed for easy Web/Internet applications.
 Widespread acceptance.
Very Brief History
 Started in 1991 by SUN Microsystems
 Targeted at consumer electronics. Wanted reliable programming language.
 Integrated into browsers
 Evolved into write once run anywhere, integrates into Netscape
 General purpose libraries released
10
11 A programming language specifies the words and
symbols that we can use to write a program
A programming language employs a set of rules that
dictate how the words and symbols can be put together to
form valid program statements
The Java programming language was created by Sun
Microsystems, Inc.
It was introduced in 1995 and it's popularity has grown
quickly since
History
James Gosling - Sun Microsystems
Co founder – Vinod Khosla
Oak - Java, May 20, 1995, Sun World
JDK Evolutions
 JDK 1.0 (January 23, 1996)
 JDK 1.1 (February 19, 1997)
 J2SE 1.2 (December 8, 1998)
 J2SE 1.3 (May 8, 2000)
 J2SE 1.4 (February 6, 2002)
 J2SE 5.0 (September 30, 2004)
 Java SE 6 (December 11, 2006)
 Java SE 7 (July 28, 2011)
Cont..
Java Editions.
 J2SE(Java 2 Standard Edition) - to develop client-side standalone applications or
applets.
 J2ME(Java 2 Micro Edition ) - to develop applications for mobile devices such as cell
phones.
 J2EE(Java 2 Enterprise Edition ) - to develop server-side applications such as Java
servlets and Java ServerPages.
Development Environments
 There are many programs that support the development of Java software, including:
 Sun Java Development Kit (JDK)
 Sun NetBeans
 IBM Eclipse
 Borland JBuilder
 MetroWerks CodeWarrior
 BlueJ
 Jgrasp
 Though the details of these environments differ, the basic compilation and execution
process is essentially the same
1-14
Java Attributes/Features
 Familiar, Simple, Small
 Compiled and Interpreted
 Platform-Independent and Portable
 Object-Oriented
 Robust and Secure
 Distributed
 Multithreaded and Interactive
 High Performance
 Dynamic and Extensible
16
Object-Oriented Software Development
problem solving
program design, implementation, and testing
object-oriented concepts
classes
objects
Data Abstraction & encapsulation
Dynamic Binding
inheritance
Polymorphism
Message communication
graphical user interfaces
17
BENEFITS OF OOPS
1. Data hiding helps the programmer to build secure programs.
2. Possible to have multiple objects to coexist without any interference.
3. Easy to partition the work in a project based on objects .
4. Message passing between objects makes the interface description with external
systems much simple.
5. Software complexity can be easily managed.
APPLICATIONS OF OOP``
1. Real time systems
2. Simulation and modeling
3. Object oriented DB
4. Hypertext, hypermedia
5. AI & expert systems
6. Neural networks and parallel programming
7. Office automation system
18
In the Java programming language:
A program is made up of one or more
classes
A class contains one or more methods
A method contains program statements
These terms will be explored in detail
throughout the course
A Java application always contains a method
called main
Programming Languages
 Each type of CPU executes only a particular machine language
 A program must be translated into machine language before it can be executed
 A compiler is a software tool which translates source code into a specific target
language
 Often, that target language is the machine language for a particular CPU type
 The Java approach is somewhat different
1-19
Java Translation
 The Java compiler translates Java source code into a special representation called
bytecode
 Java bytecode is not the machine language for any traditional CPU
 Another software tool, called an interpreter, translates bytecode into machine
language and executes it.
 Therefore the Java compiler is not tied to any particular machine
 Java is considered to be architecture-neutral
1-20
Java Translation (JVM)
Java source
code
Machine
code
Java
bytecode
Bytecode
interpreter
Bytecode
compiler
Java
compiler
• JAVA VIRTUAL MACHINE
• JUST IN TIME (JIT) EXECUTION.
• PLATFORM INDEPENDENT.
• INTERNET LANGUAGE ??
Java is Compiled and Interpreted
Text Editor Compiler Interpreter
Programmer
Source Code
.java file
Byte Code
.class file
Hardware and
Operating System
Notepad,
emacs,vi
javac java
appletviewer
netscape
Compiled Languages
Text Editor Compiler linker
Programmer
Source Code
.c file
Object Code
.o file
Notepad,
emacs,vi
gcc
Executable
Code
a.out file
Total Platform Independence
JAVA COMPILER
JAVA BYTE CODE
JAVA INTERPRETER
Windows 95 Macintosh Solaris Windows NT
(translator)
(same for all platforms)
(one for each different system)
Architecture Neutral & Portable
 Java Compiler - Java source code (file with extension .java) to
bytecode (file with extension .class)
 Bytecode - an intermediate form, closer to machine representation
 A interpreter (virtual machine) on any target platform interprets the
bytecode.
Architecture Neutral & Portable
 Porting the java system to any new platform involves writing an interpreter.
 The interpreter will figure out what the equivalent machine dependent code to run
Java better than C++ ?
 No Typedefs, Defines, or Preprocessor
 No Global Variables
 No Goto statements
 No Pointers
 No Unsafe Structures
 No Multiple Inheritance
 No Operator Overloading
 No Automatic Coercions
 No Fragile Data Types
Java Applications
 We can develop two types of Java programs:
 Stand-alone applications
 Web applications (applets)
Applications v/s Applets
 Different ways to run a Java executable are:
Application- A stand-alone program that can be invoked from command line . A
program that has a “main” method
Applet- A program embedded in a web page , to be run when the page is browsed . A
program that contains no “main” method
Applets v/s Applications
 Different ways to run a Java executable are
Application- A stand-alone program that can be invoked from command line . A
program that has a “main” method
Applet- A program embedded in a web page , to be run when the page is browsed . A
program that contains no “main” method
 Application –Executed by the Java interpreter.
 Applet- Java enabled web browser.
Syntax and Semantics
 The syntax rules of a language define how we can put together symbols, reserved
words, and identifiers to make a valid program
 The semantics of a program statement define what that statement means (its
purpose or role in a program)
 A program that is syntactically correct is not necessarily logically (semantically)
correct
 A program will always do what we tell it to do, not what we meant to tell it to do
1-31
Errors
 A program can have three types of errors
 The compiler will find syntax errors and other basic problems (compile-time errors)
 If compile-time errors exist, an executable version of the program is not created
 A problem can occur during program execution, such as trying to divide by zero,
which causes a program to terminate abnormally (run-time errors)
 A program may run, but produce incorrect results, perhaps using an incorrect formula
(logical errors)
1-32
Basic Program Development
1-33
errors
errors
Edit and
save program
Compile program
Execute program and
evaluate results
How is Java different from C…
 C Language:
 Major difference is that C is a structure oriented language and Java is
an object oriented language and has mechanism to define classes and
objects.
 Java does not support an explicit pointer type
 Java does not have preprocessor, so we cant use #define, #include and
#ifdef statements.
 Java does not include structures, unions and enum data types.
 Java does not include keywords like goto, sizeof and typedef.
 Java adds labeled break and continue statements.
 Java adds many features required for object oriented programming.
How is Java different from C++…
 C++ language
Features removed in java:
 Java doesn’t support pointers to avoid unauthorized access of memory locations.
 Java does not include structures, unions and enum data types.
 Java does not support operator over loading.
 Preprocessor plays less important role in C++ and so eliminated entirely in java.
 Java does not perform automatic type conversions that result in loss of precision.
Cont…
 Java does not support global variables. Every method and variable is
declared within a class and forms part of that class.
 Java does not allow default arguments.
 Java does not support inheritance of multiple super classes by a sub class
(i.e., multiple inheritance). This is accomplished by using ‘interface’ concept.
 It is not possible to declare unsigned integers in java.
 In java objects are passed by reference only. In C++ objects may be passed
by value or reference.
Cont …
New features added in Java:
 Multithreading, that allows two or more pieces of the same program to execute
concurrently.
 C++ has a set of library functions that use a common header file. But java replaces it
with its own set of API classes.
 It adds packages and interfaces.
 Java supports automatic garbage collection.
 break and continue statements have been enhanced in java to accept labels as targets.
 The use of unicode characters ensures portability.
Cont …
Features that differ:
 Though C++ and java supports Boolean data type, C++ takes any
nonzero value as true and zero as false. True and false in java are
predefined literals that are values for a boolean expression.
 Java has replaced the destructor function with a finalize() function.
 C++ supports exception handling that is similar to java's. However,
in C++ there is no requirement that a thrown exception be caught.
Characteristics of Java
 Java is simple-C & C++ features are
adapted.
 Java is object-oriented-classes as
packages and objects.
 Java is distributed-it can share both
data and programs.
 Java is compiled & interpreted
 Java is robust
 Java is architecture-neutral
 Java is portable
 Java’s high performance-
Multithreading
 Java is multithreaded-multiple
 Java is dynamic-supports functions of
c & c++
Java is secure
Java Environment
 Java includes many development tools, classes and methods
 Development tools are part of Java Development Kit (JDK) and
 The classes and methods are part of Java Standard Library (JSL), also
known as Application Programming Interface (API).
 JDK constitutes of tools like java compiler, java interpreter and
many.
 API includes hundreds of classes and methods grouped into
several packages according to their functionality.
First Application
/**
*Hello World, first application, only output.
*/
public class hello{
public static void main (String [] args) {
System.out.println(“Hello Worldn”);
} //end main
}//end class
41
public is the visibility. This can be public, private, protected or (if you omit a value)
default.
static is a special [optional] keyword that indicates that this method can be called
without creating an instance of this class. Without it, you have to instantiate this class
and call this method from the resulting object.
void is the return type of this method, indicating that this method doesn't return
anything. Methods must have a return type.
42
 main( ... ) is the name of this method. Methods have to be named. The
parentheses indicate that this is a method.
 String[] args is a single parameter for the method. String[] is the type of the
parameter, indicating an array of Strings. args is the name of the parameter.
Parameters must be named.
43
How to get it running
 Text in hello.java file
 Why?
 To compile:
 javac hello.java
 To run:
 java hello
44
 Case Sensitivity - Java is case sensitive, which means identifier Hello and hello
would have different meaning in Java.
 Class Names - For all class names the first letter should be in Upper Case.
 If several words are used to form a name of the class, each inner word's first letter
should be in Upper Case.
Example class MyFirstJavaClass
 Method Names - All method names should start with a Lower
Case letter.
If several words are used to form the name of the method,
each inner word's first letter should be in Upper Case.
Example public void myMethodName()
Notice:
 Java is CASE SENSITIVE!!
 Whitespace is ignored by compiler
 Whitespace makes things easier to read…hence it affects your grade 
 File name has to be the same as class name in file.
 Need to import necessary class definitions
46
 Program File Name - Name of the program file should exactly match the class
name.
When saving the file, you should save it using the class name (Remember Java is
case sensitive) and append '.java' to the end of the name (if the file name and
class name do not match your program will not compile).
Example : Assume 'MyFirstJavaProgram' is the class name. Then the file should
saved as 'MyFirstJavaProgram.java'
Java program structure
 Thank you..Lets meet in the implementation of OOPs concept in JAVA

Más contenido relacionado

La actualidad más candente (20)

History of java'
History of java'History of java'
History of java'
 
Java I/O
Java I/OJava I/O
Java I/O
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Java IO
Java IOJava IO
Java IO
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
 
Introduction to Basic Java Versions and their features
Introduction to Basic Java Versions and their featuresIntroduction to Basic Java Versions and their features
Introduction to Basic Java Versions and their features
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing in Python
 
Java Multithreading and Concurrency
Java Multithreading and ConcurrencyJava Multithreading and Concurrency
Java Multithreading and Concurrency
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
 
QSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and JitQSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and Jit
 
Java threads
Java threadsJava threads
Java threads
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New Features
 
Java Notes
Java Notes Java Notes
Java Notes
 

Similar a Introduction to java

ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.docICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.docAmanGunner
 
C,c++,java,php,.net training institute in delhi, best training institute for ...
C,c++,java,php,.net training institute in delhi, best training institute for ...C,c++,java,php,.net training institute in delhi, best training institute for ...
C,c++,java,php,.net training institute in delhi, best training institute for ...MCM COmpetitive Classes
 
Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to JavaDevaKumari Vijay
 
Java Lecture 1
Java Lecture 1Java Lecture 1
Java Lecture 1Qualys
 
JAVA PROGRAMMING-Unit I - Final PPT.pptx
JAVA PROGRAMMING-Unit I - Final PPT.pptxJAVA PROGRAMMING-Unit I - Final PPT.pptx
JAVA PROGRAMMING-Unit I - Final PPT.pptxSuganthiDPSGRKCW
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year projectsuneel singh
 
0f0cef_1dac552af56c4338ab0672859199e693.pdf
0f0cef_1dac552af56c4338ab0672859199e693.pdf0f0cef_1dac552af56c4338ab0672859199e693.pdf
0f0cef_1dac552af56c4338ab0672859199e693.pdfDeepakChaudhriAmbali
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
1.INTRODUCTION TO JAVA_2022 MB.ppt .
1.INTRODUCTION TO JAVA_2022 MB.ppt      .1.INTRODUCTION TO JAVA_2022 MB.ppt      .
1.INTRODUCTION TO JAVA_2022 MB.ppt .happycocoman
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java SlidesVinit Vyas
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayLiz Sims
 
Vb.net basics 1(vb,net--3 year)
Vb.net basics 1(vb,net--3 year)Vb.net basics 1(vb,net--3 year)
Vb.net basics 1(vb,net--3 year)Ankit Gupta
 

Similar a Introduction to java (20)

ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.docICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
 
Java Programming Basics
Java Programming BasicsJava Programming Basics
Java Programming Basics
 
C,c++,java,php,.net training institute in delhi, best training institute for ...
C,c++,java,php,.net training institute in delhi, best training institute for ...C,c++,java,php,.net training institute in delhi, best training institute for ...
C,c++,java,php,.net training institute in delhi, best training institute for ...
 
Java1
Java1Java1
Java1
 
Java
Java Java
Java
 
Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to Java
 
Java Lecture 1
Java Lecture 1Java Lecture 1
Java Lecture 1
 
JAVA PROGRAMMING-Unit I - Final PPT.pptx
JAVA PROGRAMMING-Unit I - Final PPT.pptxJAVA PROGRAMMING-Unit I - Final PPT.pptx
JAVA PROGRAMMING-Unit I - Final PPT.pptx
 
Java Intro
Java IntroJava Intro
Java Intro
 
report
reportreport
report
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year project
 
0f0cef_1dac552af56c4338ab0672859199e693.pdf
0f0cef_1dac552af56c4338ab0672859199e693.pdf0f0cef_1dac552af56c4338ab0672859199e693.pdf
0f0cef_1dac552af56c4338ab0672859199e693.pdf
 
Java ms harsha
Java ms harshaJava ms harsha
Java ms harsha
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
1.INTRODUCTION TO JAVA_2022 MB.ppt .
1.INTRODUCTION TO JAVA_2022 MB.ppt      .1.INTRODUCTION TO JAVA_2022 MB.ppt      .
1.INTRODUCTION TO JAVA_2022 MB.ppt .
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage Essay
 
Java presentation
Java presentationJava presentation
Java presentation
 
Java programming language basics
Java programming language basicsJava programming language basics
Java programming language basics
 
Vb.net basics 1(vb,net--3 year)
Vb.net basics 1(vb,net--3 year)Vb.net basics 1(vb,net--3 year)
Vb.net basics 1(vb,net--3 year)
 

Más de Kalai Selvi

cloud services and providers
cloud services and providerscloud services and providers
cloud services and providersKalai Selvi
 
cloud concepts and technologies
cloud concepts and technologiescloud concepts and technologies
cloud concepts and technologiesKalai Selvi
 
I Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxI Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxKalai Selvi
 
I semester-SOP-POS expressions.pptx
I semester-SOP-POS expressions.pptxI semester-SOP-POS expressions.pptx
I semester-SOP-POS expressions.pptxKalai Selvi
 
I Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxI Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxKalai Selvi
 
Multimedia Authoring Tools.ppt
Multimedia Authoring Tools.pptMultimedia Authoring Tools.ppt
Multimedia Authoring Tools.pptKalai Selvi
 
Process of Making Multimedia.ppt
Process of Making Multimedia.pptProcess of Making Multimedia.ppt
Process of Making Multimedia.pptKalai Selvi
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritanceKalai Selvi
 
Unit3 packages & interfaces
Unit3 packages & interfacesUnit3 packages & interfaces
Unit3 packages & interfacesKalai Selvi
 
Introduction to Artificial Intelligence
Introduction to Artificial IntelligenceIntroduction to Artificial Intelligence
Introduction to Artificial IntelligenceKalai Selvi
 
Searching techniques in AI
Searching techniques in AISearching techniques in AI
Searching techniques in AIKalai Selvi
 
Introduction to Artificial Intelligence
Introduction to Artificial IntelligenceIntroduction to Artificial Intelligence
Introduction to Artificial IntelligenceKalai Selvi
 
AWT controls, Listeners
AWT controls, ListenersAWT controls, Listeners
AWT controls, ListenersKalai Selvi
 
AWT controls, Listeners
AWT controls, ListenersAWT controls, Listeners
AWT controls, ListenersKalai Selvi
 
Unit 4 combinational circuit
Unit 4 combinational circuitUnit 4 combinational circuit
Unit 4 combinational circuitKalai Selvi
 
Unit 3 file management
Unit 3 file managementUnit 3 file management
Unit 3 file managementKalai Selvi
 
Unit 3 chapter 1-file management
Unit 3 chapter 1-file managementUnit 3 chapter 1-file management
Unit 3 chapter 1-file managementKalai Selvi
 

Más de Kalai Selvi (20)

cloud services and providers
cloud services and providerscloud services and providers
cloud services and providers
 
cloud concepts and technologies
cloud concepts and technologiescloud concepts and technologies
cloud concepts and technologies
 
cloud computing
cloud computingcloud computing
cloud computing
 
I Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxI Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptx
 
I semester-SOP-POS expressions.pptx
I semester-SOP-POS expressions.pptxI semester-SOP-POS expressions.pptx
I semester-SOP-POS expressions.pptx
 
I Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptxI Semester-Unit 3 Boolean Algebra.pptx
I Semester-Unit 3 Boolean Algebra.pptx
 
Multimedia Authoring Tools.ppt
Multimedia Authoring Tools.pptMultimedia Authoring Tools.ppt
Multimedia Authoring Tools.ppt
 
Process of Making Multimedia.ppt
Process of Making Multimedia.pptProcess of Making Multimedia.ppt
Process of Making Multimedia.ppt
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
 
Unit3 packages & interfaces
Unit3 packages & interfacesUnit3 packages & interfaces
Unit3 packages & interfaces
 
Introduction to Artificial Intelligence
Introduction to Artificial IntelligenceIntroduction to Artificial Intelligence
Introduction to Artificial Intelligence
 
Searching techniques in AI
Searching techniques in AISearching techniques in AI
Searching techniques in AI
 
Introduction to Artificial Intelligence
Introduction to Artificial IntelligenceIntroduction to Artificial Intelligence
Introduction to Artificial Intelligence
 
AWT controls, Listeners
AWT controls, ListenersAWT controls, Listeners
AWT controls, Listeners
 
AWT controls, Listeners
AWT controls, ListenersAWT controls, Listeners
AWT controls, Listeners
 
Unit 1 part 2
Unit 1  part 2Unit 1  part 2
Unit 1 part 2
 
Unit 1 part 1
Unit 1   part 1Unit 1   part 1
Unit 1 part 1
 
Unit 4 combinational circuit
Unit 4 combinational circuitUnit 4 combinational circuit
Unit 4 combinational circuit
 
Unit 3 file management
Unit 3 file managementUnit 3 file management
Unit 3 file management
 
Unit 3 chapter 1-file management
Unit 3 chapter 1-file managementUnit 3 chapter 1-file management
Unit 3 chapter 1-file management
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Último (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Introduction to java

  • 1. PROGRAMMING IN JAVA Dr.K.Kalaiselvi Dept of Computer Science Kristu Jayanti college Bangalore
  • 2. Course Objective To inculcate knowledge about the fundamentals of OOPs(Object oriented programming) To provide knowledge about developing java applications and applets Creating GUI based Java apps and applets that run in a consistent manner across all platforms. (swings).
  • 3. 1. Balagurusamy.E. Programming with JAVA a Primer. NewDelhi : Tata McGraw- Hill Publishing Company Limited. 2.Herbert Schildt. The Complete Reference- Java (7th ed.). New Delhi : Tata McGraw-Hill Publishing Company Limited. Refer : http://javabeginnerstutorial.com/core-java/ Books & References
  • 5. • Object oriented programming concepts • Structure of Java programs • Compiling and running the program • Printing messages to the screen Learning outcome of this unit
  • 6. 6 UNIT1:IntroductiontoJavaandFeaturesofJava10hrs History; Evolution of Java; How Java changed internet; Fundamentals of object-Oriented programming; Basic concepts of object-oriented programming; Benefits of object-oriented programming; Features of Java; How Java differs from C And C++; Overview of Java; Simple Java program; Structure; Java development kit (JDK); Java interpreter; Java virtual machine. Data types; Variable; Type conversion and casting; Operators and expressions; Programming structure; Operators and expressions; Decision-making and branching: If; If.. Else; Nested If; Switch; ?: Operator; Looping: While; Do; For – Jumps In Loops - Labeled loops; Array – Types ofarrays;Stringhandling.
  • 7. Some Basics Q. What is a program? Ans. A sequence of instructions that a computer can interpret and execute. Q. Why Java and not Hindi / Marathi / English? Ans. Since, so far, computer is not intelligent enough to understand natural languages.
  • 8. Contents  History  First Java Application  Data types  Variables  Strings  Assignments  Math, Boolean expressions  Relational operations  If statements  System.exit 8
  • 9. What is java?  A general-purpose object-oriented language.  Write Once Run Anywhere (WORA).  Designed for easy Web/Internet applications.  Widespread acceptance.
  • 10. Very Brief History  Started in 1991 by SUN Microsystems  Targeted at consumer electronics. Wanted reliable programming language.  Integrated into browsers  Evolved into write once run anywhere, integrates into Netscape  General purpose libraries released 10
  • 11. 11 A programming language specifies the words and symbols that we can use to write a program A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since
  • 12. History James Gosling - Sun Microsystems Co founder – Vinod Khosla Oak - Java, May 20, 1995, Sun World JDK Evolutions  JDK 1.0 (January 23, 1996)  JDK 1.1 (February 19, 1997)  J2SE 1.2 (December 8, 1998)  J2SE 1.3 (May 8, 2000)  J2SE 1.4 (February 6, 2002)  J2SE 5.0 (September 30, 2004)  Java SE 6 (December 11, 2006)  Java SE 7 (July 28, 2011)
  • 13. Cont.. Java Editions.  J2SE(Java 2 Standard Edition) - to develop client-side standalone applications or applets.  J2ME(Java 2 Micro Edition ) - to develop applications for mobile devices such as cell phones.  J2EE(Java 2 Enterprise Edition ) - to develop server-side applications such as Java servlets and Java ServerPages.
  • 14. Development Environments  There are many programs that support the development of Java software, including:  Sun Java Development Kit (JDK)  Sun NetBeans  IBM Eclipse  Borland JBuilder  MetroWerks CodeWarrior  BlueJ  Jgrasp  Though the details of these environments differ, the basic compilation and execution process is essentially the same 1-14
  • 15. Java Attributes/Features  Familiar, Simple, Small  Compiled and Interpreted  Platform-Independent and Portable  Object-Oriented  Robust and Secure  Distributed  Multithreaded and Interactive  High Performance  Dynamic and Extensible
  • 16. 16 Object-Oriented Software Development problem solving program design, implementation, and testing object-oriented concepts classes objects Data Abstraction & encapsulation Dynamic Binding inheritance Polymorphism Message communication graphical user interfaces
  • 17. 17 BENEFITS OF OOPS 1. Data hiding helps the programmer to build secure programs. 2. Possible to have multiple objects to coexist without any interference. 3. Easy to partition the work in a project based on objects . 4. Message passing between objects makes the interface description with external systems much simple. 5. Software complexity can be easily managed. APPLICATIONS OF OOP`` 1. Real time systems 2. Simulation and modeling 3. Object oriented DB 4. Hypertext, hypermedia 5. AI & expert systems 6. Neural networks and parallel programming 7. Office automation system
  • 18. 18 In the Java programming language: A program is made up of one or more classes A class contains one or more methods A method contains program statements These terms will be explored in detail throughout the course A Java application always contains a method called main
  • 19. Programming Languages  Each type of CPU executes only a particular machine language  A program must be translated into machine language before it can be executed  A compiler is a software tool which translates source code into a specific target language  Often, that target language is the machine language for a particular CPU type  The Java approach is somewhat different 1-19
  • 20. Java Translation  The Java compiler translates Java source code into a special representation called bytecode  Java bytecode is not the machine language for any traditional CPU  Another software tool, called an interpreter, translates bytecode into machine language and executes it.  Therefore the Java compiler is not tied to any particular machine  Java is considered to be architecture-neutral 1-20
  • 21. Java Translation (JVM) Java source code Machine code Java bytecode Bytecode interpreter Bytecode compiler Java compiler • JAVA VIRTUAL MACHINE • JUST IN TIME (JIT) EXECUTION. • PLATFORM INDEPENDENT. • INTERNET LANGUAGE ??
  • 22. Java is Compiled and Interpreted Text Editor Compiler Interpreter Programmer Source Code .java file Byte Code .class file Hardware and Operating System Notepad, emacs,vi javac java appletviewer netscape
  • 23. Compiled Languages Text Editor Compiler linker Programmer Source Code .c file Object Code .o file Notepad, emacs,vi gcc Executable Code a.out file
  • 24. Total Platform Independence JAVA COMPILER JAVA BYTE CODE JAVA INTERPRETER Windows 95 Macintosh Solaris Windows NT (translator) (same for all platforms) (one for each different system)
  • 25. Architecture Neutral & Portable  Java Compiler - Java source code (file with extension .java) to bytecode (file with extension .class)  Bytecode - an intermediate form, closer to machine representation  A interpreter (virtual machine) on any target platform interprets the bytecode.
  • 26. Architecture Neutral & Portable  Porting the java system to any new platform involves writing an interpreter.  The interpreter will figure out what the equivalent machine dependent code to run
  • 27. Java better than C++ ?  No Typedefs, Defines, or Preprocessor  No Global Variables  No Goto statements  No Pointers  No Unsafe Structures  No Multiple Inheritance  No Operator Overloading  No Automatic Coercions  No Fragile Data Types
  • 28. Java Applications  We can develop two types of Java programs:  Stand-alone applications  Web applications (applets)
  • 29. Applications v/s Applets  Different ways to run a Java executable are: Application- A stand-alone program that can be invoked from command line . A program that has a “main” method Applet- A program embedded in a web page , to be run when the page is browsed . A program that contains no “main” method
  • 30. Applets v/s Applications  Different ways to run a Java executable are Application- A stand-alone program that can be invoked from command line . A program that has a “main” method Applet- A program embedded in a web page , to be run when the page is browsed . A program that contains no “main” method  Application –Executed by the Java interpreter.  Applet- Java enabled web browser.
  • 31. Syntax and Semantics  The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program  The semantics of a program statement define what that statement means (its purpose or role in a program)  A program that is syntactically correct is not necessarily logically (semantically) correct  A program will always do what we tell it to do, not what we meant to tell it to do 1-31
  • 32. Errors  A program can have three types of errors  The compiler will find syntax errors and other basic problems (compile-time errors)  If compile-time errors exist, an executable version of the program is not created  A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors)  A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors) 1-32
  • 33. Basic Program Development 1-33 errors errors Edit and save program Compile program Execute program and evaluate results
  • 34. How is Java different from C…  C Language:  Major difference is that C is a structure oriented language and Java is an object oriented language and has mechanism to define classes and objects.  Java does not support an explicit pointer type  Java does not have preprocessor, so we cant use #define, #include and #ifdef statements.  Java does not include structures, unions and enum data types.  Java does not include keywords like goto, sizeof and typedef.  Java adds labeled break and continue statements.  Java adds many features required for object oriented programming.
  • 35. How is Java different from C++…  C++ language Features removed in java:  Java doesn’t support pointers to avoid unauthorized access of memory locations.  Java does not include structures, unions and enum data types.  Java does not support operator over loading.  Preprocessor plays less important role in C++ and so eliminated entirely in java.  Java does not perform automatic type conversions that result in loss of precision.
  • 36. Cont…  Java does not support global variables. Every method and variable is declared within a class and forms part of that class.  Java does not allow default arguments.  Java does not support inheritance of multiple super classes by a sub class (i.e., multiple inheritance). This is accomplished by using ‘interface’ concept.  It is not possible to declare unsigned integers in java.  In java objects are passed by reference only. In C++ objects may be passed by value or reference.
  • 37. Cont … New features added in Java:  Multithreading, that allows two or more pieces of the same program to execute concurrently.  C++ has a set of library functions that use a common header file. But java replaces it with its own set of API classes.  It adds packages and interfaces.  Java supports automatic garbage collection.  break and continue statements have been enhanced in java to accept labels as targets.  The use of unicode characters ensures portability.
  • 38. Cont … Features that differ:  Though C++ and java supports Boolean data type, C++ takes any nonzero value as true and zero as false. True and false in java are predefined literals that are values for a boolean expression.  Java has replaced the destructor function with a finalize() function.  C++ supports exception handling that is similar to java's. However, in C++ there is no requirement that a thrown exception be caught.
  • 39. Characteristics of Java  Java is simple-C & C++ features are adapted.  Java is object-oriented-classes as packages and objects.  Java is distributed-it can share both data and programs.  Java is compiled & interpreted  Java is robust  Java is architecture-neutral  Java is portable  Java’s high performance- Multithreading  Java is multithreaded-multiple  Java is dynamic-supports functions of c & c++ Java is secure
  • 40. Java Environment  Java includes many development tools, classes and methods  Development tools are part of Java Development Kit (JDK) and  The classes and methods are part of Java Standard Library (JSL), also known as Application Programming Interface (API).  JDK constitutes of tools like java compiler, java interpreter and many.  API includes hundreds of classes and methods grouped into several packages according to their functionality.
  • 41. First Application /** *Hello World, first application, only output. */ public class hello{ public static void main (String [] args) { System.out.println(“Hello Worldn”); } //end main }//end class 41
  • 42. public is the visibility. This can be public, private, protected or (if you omit a value) default. static is a special [optional] keyword that indicates that this method can be called without creating an instance of this class. Without it, you have to instantiate this class and call this method from the resulting object. void is the return type of this method, indicating that this method doesn't return anything. Methods must have a return type. 42
  • 43.  main( ... ) is the name of this method. Methods have to be named. The parentheses indicate that this is a method.  String[] args is a single parameter for the method. String[] is the type of the parameter, indicating an array of Strings. args is the name of the parameter. Parameters must be named. 43
  • 44. How to get it running  Text in hello.java file  Why?  To compile:  javac hello.java  To run:  java hello 44
  • 45.  Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.  Class Names - For all class names the first letter should be in Upper Case.  If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example class MyFirstJavaClass  Method Names - All method names should start with a Lower Case letter. If several words are used to form the name of the method, each inner word's first letter should be in Upper Case. Example public void myMethodName()
  • 46. Notice:  Java is CASE SENSITIVE!!  Whitespace is ignored by compiler  Whitespace makes things easier to read…hence it affects your grade   File name has to be the same as class name in file.  Need to import necessary class definitions 46
  • 47.  Program File Name - Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and class name do not match your program will not compile). Example : Assume 'MyFirstJavaProgram' is the class name. Then the file should saved as 'MyFirstJavaProgram.java'
  • 49.  Thank you..Lets meet in the implementation of OOPs concept in JAVA