SlideShare une entreprise Scribd logo
1  sur  13
Grade VIII 
Computer Applications 
Introduction to Java 
Program: A program is a set of instructions written to perform a specific task. 
Programming Languages: Programming Languages can be broadly classified as: 
i) Low Level Language: 
Machine Language (1GL) 
Assembly Language (2GL) 
ii) High Level Language: 
Procedural (3GL) 
Non-Procedural (4GL) 
i) Machine Language : (1st Generation Language) Machine language is literally 
binary sequences (lots of 0s and 1s) interpreted by the computer as instructions. It 
is the only language that the computer directly understands. 
Advantage: Its efficiency and speed of processing. 
Disadvantages 
a. Coding in the machine language is an extremely cumbersome and complicated 
task that is prone to errors. 
b. The language itself is not very human readable. (i.e. user friendly). 
c. The language is also machine dependent and requires knowledge of complete 
computer circuitry. 
ii) Assembly Language: (2nd Generation Language) The first language similar to 
English was developed in 1950 which was known as Assembly Language or 
Symbolic Programming Language. Assembly language is a low level language 
that uses small symbolic words called mnemonics instead of zeroes and ones. 
These mnemonics like ADD to add, MUL to multiply, LOC to locate an address 
and such others express the operations to be performed. A translator called the 
assembler converts these mnemonics to the machine language and performs the 
necessary action. 
Advantages: Assembly language is very powerful and efficient. It is fast, small in 
program size and flexible. This language is popularly used at microprocessor level 
and system coding. 
Disadvantages: It is not very user friendly and easily understandable. 
The assembler must be loaded to the computer memory for translation and it 
occupies a sizeable memory of the computer, hence Assembly Language cannot 
be used with small capacity computers.
iii) High Level Language: (3rd Generation Language) Procedural languages are used 
to solve problems and are often described as problem oriented languages. They 
focus on the method or HOW to solve the problem. In high level languages, the 
programs are written in a language which is closer to the user i.e. English, just 
following some rules specific for the language (syntax). Every instruction that 
the programmer writes in this language is translated into the machine language 
using a language processor /translator called the compiler or the interpreter. 
Advantages: HLL is independent of the internal machine code of any particular 
computer. High Level language is the most understandable and easy to code 
language besides having the following advantages, easier documentation, easy to 
learn and use and modifications can be done more easily. 
Disadvantages: The syntax and the semantics of the language need to be learnt 
and only then can it be used. 
BASIC, COBOL, Pascal, FORTRAN, C, C++, Java are some examples of HLL. 
Programming in HLL can be done in one of the following two approaches: 
a) Procedural Programming Approach 
b) Object Oriented Programming Approach. 
iv) Non-Procedural Language: 4GLs are non procedural, that is only “WHAT is 
required” is to be specified and the rest gets done on its own. The main aim of the 
4GL is to cut down on development and maintenance time and make it easier for 
users. The user interacts with the utility software which is an integral part of a 
4GL and that in turn interacts with the system to get the work done. Word 
processors, spreadsheets, DBMS, graphic software are some of the examples of 
4GLs. 
TRANSLATORS OR LANGUAGE PROCESSORS: 
(COMPILERS AND INTERPRETERS) 
Translators are system software that perform the process of converting a high level 
language instruction to the machine language. 
A) Compiler: A compiler converts the HLL program into the machine language at one go. It 
converts the entire HLL program at a time and reports all the errors of the program along 
with the line numbers. After the program is debugged, it is recompiled and after that the 
compiler is not needed in the memory as the object program is available. 
B) Interpreter: This language processor converts s a HLL program into machine language by 
converting and executing it line by line. It there is any error in any line, it reports it at the 
same time and program execution cannot be resumed till the error is rectified. The interpreter 
must always be present in the memory every time the program is executed. For error 
debugging, interpreter is very much useful as it reports the errors immediately on occurrence 
but after the program is debugged, unnecessary usage of memory takes place as it has to be 
present in the memory always. 
Therefore, combination of interpreter and compiler is an ideal option of HLL 
translation to the machine code. For the initial error removal, the interpreter can be used and 
then the program can be compiled enabling the removal of the language translator from the 
memory.
Programming Approach 
Programming in HLL can be done in one of the following two approaches: 
a) Procedural Programming Approach 
b) Object Oriented Programming Approach. 
a) Procedural or Structured Programming: Developing a language with a process 
centric approach is called procedural programming. It concentrates on HOW to solve 
the problem. It focuses on the methods/processes for which the software is being 
built. This approach refers to breaking up the complex problem into smaller problems 
and then solving each by using modules (functions or procedures) which act on the 
data. These functions are tightly interdependent on each other. Example: BASIC, 
COBOL, C, Pascal. 
Drawbacks: 
i) The modules or parts of the whole program strongly depend on each other. 
So a module cannot be reused by other programs. 
ii) The procedural program code is not flexible to change. The program 
written in a procedural language completely needs to be changed as all the 
parts of a program are linked and dependent on each other. 
iii) Solutions to real world problems cannot be directly depicted using this 
language. 
b) Object Oriented Programming: OOP simulates the real world in software. Real 
world consists of identifiable entities or objects. These objects have their peculiar 
characteristics and behavior. Examples of real world objects are books, pens, students, 
chair, and car and so on. This approach concentrates on “WHAT”- “What is the object 
that will get affected by this problem?” and then the approach works on the 
attributes/state and behavior/methods of that object. Examples: Smalltalk, C++, Java. 
Advantages: 
i) This approach models the real world quite accurately as the programs 
written in the language are focused on the objects rather than the 
procedure. 
ii) It is extremely reusable as these objects can be invoked in different 
programs. 
iii) Programs written in OOP are simple to change when the requirements for 
the application changes. 
iv) The principles of OOP prevent the objects from being mishandled and are 
kept safe from unauthorized access.
JAVA 
(An Object Oriented Programming Language) 
History of Java 
Sun Micro systems began for software to run on TV and VCR sets i.e. Interactive TV 
and VCR sets. A team of software engineers led by James Gosling, Patric Naughton, Chris 
Warth, Ed Frank and Mike Sheridan laid specifications for these projects in 1991. By 
September 1992, the basic system was drafted. These interactive sets were called set-top 
boxes. The hardware was called 7(Seven), OS was called Green and the programming 
language was called OAK. 
Between the initial implementation of OAK in the fall of 1992 and the public 
announcement of Java in 1995, many more people contributed to the design and the evolution 
of the language. Bill Joy, Arther van Hoff, Jonathan Payne, Frank Yellin and Tim Lindholm 
were key contributors to the maturing of the older prototype. 
Hot Java was the first commercial product to be developed completely in Java. On 
May 23, 1995, Java was commercially released. The advent of Internet gave a tremendous 
boost to this language. Java Programs can be embedded in HTML pages and downloaded by 
Web browser to bring live animations and interaction to web clients. The power of Java is not 
limited to web applications. Java is a general purpose programming language. It has full 
programming features and can be used to develop standalone applications. 
Characteristics of Java 
1) It is simple : No programming language is simple, but java is bit simple as compared to 
other OOP language such as C++. 
2) It is object oriented : Java is called OOP language because Java is centered on creating 
objects, manipulating objects and making objects working together. 
3) It is distributed : Distributed computing involves several computers on a network 
working together. Java is designed to make distributed computing easy. Networking 
capability is inherently integrated into Java.
4) Java is compiled as well as interpreted: One needs an interpreter and a compiler to run 
Java programs. The programs are compiled into Java Virtual Machine Code called 
bytecode. The bytecode is machine independent and can run on any machine that has java 
interpreter. 
5) Java is highly case sensitive: Java is highly case aware. Instructions written in java are 
different when written in the lower case and the upper case. 
6) It is robust: Robust means reliable. No programming language can assure reliability. 
Java puts a lot of emphasis on early checking of possible errors as java compilers can 
detect many problems that would throw show up at execution time in other languages. It 
has a runtime exception handling feature to provide programming support for robustness. 
Java can catch and respond to an exceptional situation so that the program can continue 
its normal execution and terminate gracefully when a runtime error occurs. 
7) It is secure : Java being an Internet programming language is used in a networked and 
distributed environment. You can download a java applet, run it on your computer and it 
will cause no damage to your system. 
8) It is architecturally neutral- The most remarkable feature of java is that it is 
architectural neutral (Platform Independent). You can write one program that runs on 
any platform with JVM (Java Virtual Machine). You can run Java Applets from a Web 
Browser, but java is more than just a web applet. You can also run stand-alone java 
applications directly from operating system by using a java interpreter. 
9) It is portable: Java programs can run on any platform without having to be recompiled. 
This is one positive aspect of portability. 
10) It is multithreaded : Multithreading is capability for a program to perform several tasks 
simultaneously within a program. E.g. downloading a video file while playing a video file 
would be considered multithreading. It is smoothly integrated in Java. 
11) It is a dynamic and one of the most high performance languages today. 
JAVA APPLICATIONS 
Java programs can be one of the two types: stand alone applications and applets. 
Applications are stand-alone programs like any program written using high-level language. 
Applications can be executed from any computer with a Java interpreter and are ideal for 
developing software. Applets are special kind of Java programs that can run directly from 
Java compatible Web browser. Applets are suitable for deploying (installing) Web projects.
Java Program Structure (For stand alone programs only) 
Probably, the best way to start learning a programming language is to write a simple 
program. [* Please consider the program structure as a mandatory syntax requirement, the 
details of what is it will be learnt by you in due course of time] 
/* program to -- Welcome to Java*/ 
class Welcome 
{ 
public static void main(String args[]) 
{ 
System.out.println(“Welcome to Java”); 
} 
} 
Let us now examine the parts of this sample program: 
i) /* program… welcome to java*/ 
The text enclosed with /* …*/ is called comment. Comments or remarks are non 
executable statements purely for enhancing the program readability. 
ii) class Welcome 
Every java program should begin with the “class” keyword. Java being OOP, classes 
contain attributes/data members and behavior/methods of the objects. Methods may 
contain other executable statements. Here a class/program with the name Welcome is 
defined. It is also called the initial class since it defines the program name. The file 
name of this program should be Welcome.java- i.e. same name as that of the class. 
Although there can be many classes in a Java program, there can by only one initial 
class in a Java program. An initial class contains the main function inside it. 
iii) public static void main(String args[]) 
This is the syntax of the “main” method, it cannot be changed. It is the most important 
method because it is from this method that the application begins executing the program. 
(Cannot have any other name) If there are several methods in a program, the program 
will only begin executing from the main method. If there are many classes within a Java
program, the execution will only begin from the initial class (the class that contains the 
main method) If there is no main method in the class, no execution will take place. Thus 
the main method is also called the driver method. On reaching the end of main, the 
program terminates and the control passes back to the operating system. 
Let us now understand each keyword of this method declaration: 
public- “main” is the first method called by the Java environment when a program is 
executed so it has to be accessible from the Java environment (JDK software). This 
method has to be publicly available otherwise how can it be accessed outside the 
program. Hence the access specifier has to be public. 
static- static methods are class methods that do not need the creation of any object to 
work with the method. 
void – Functions or methods can return a value. void means nothing. The main 
method does not return any value, hence it is declared void. 
String args[ ]- Functions or methods can also take in arguments or parameters to 
work on them. The main method can take arguments in this form. 
iii) { } The pair of curly braces called the block of code marks the scope of the main 
method and the scope of the class. They indicate the boundaries. 
iv) System.out.println(“Welcome to Java”); 
This statement prints “Welcome to Java” on the standard output device which is 
generally the monitor. This is the statement to print the desired output that is present in the 
brackets (“ … ”). Here, System – computer, out – output device(monitor) , println – print the 
output and the control goes to the next line. 
Exercise I : Write programs in Java to: 
i) Print your name
ii) Print your name and address 
iii) Print your name , school name and class name 
iv) Print a pattern like “****” 
“***” 
“*” 
v) Print the message “hello world!”. 
The Java Language 
Java Keywords: Keywords are the words that convey a special meaning to the language 
compiler. These are reserved for special purpose and cannot be used as normal identifier 
names. 
abstract boolean break Byte case catch 
char class const Continue default do 
double else extends Final finally float 
for goto if implements import instanceof 
int interface long native new package 
private protected public Return short static 
strictfp super switch synchronized this throw 
throws transient try Void volatile while 
*true and false and null are reserved words but not keywords, they are literals. 
Identifiers: 
Identifiers are fundamental building blocks of a program. They are programmer designed 
tokens. They are used for naming all the components of a program like the classes, methods, 
variables, objects, labels, packages, and interfaces in a program. The identifier follows the 
following rules: 
1. They can have alphabets, digits, underscore, and dollar sign characters. 
2. They must not begin with a digit. 
3. Uppercase and lowercase letters are distinct. Java is case sensitive. 
4. They can be of any length. 
5. They must not be a keyword or a boolean or null literal.
Java developers follow some naming conventions for the identifiers. Conventions are good 
programming practice to improve the readability of the program. 
· Names of all public methods and instance variables start with a leading lowercase letter. 
If the name has more than one word, the second and subsequent words are marked with a 
leading uppercase letters. 
E.g. average 
totalMarks 
· All private and local variables use only lowercase letters combined with underscores. 
E.g. length 
batch_strength 
· All classes & interfaces start with a leading uppercase letter (and subsequent words are 
marked with a leading uppercase letter). 
E.g. Student 
MotorCycle 
· Variables that represent literal values use all uppercase letters & underscores. 
Eg TOTAL 
MAX_MARKS 
Literals 
They refer to fixed values that do not change during the execution of a program. 
Integer literals 
It refers to sequence of digits. There are 3 types of integer literals, namely, decimal integer, 
octal integer and hexadecimal integer. 
Decimal integer consists of a set of digits, 0 through 9, preceded by an optional minus sign. 
An octal integer literal consists of digits 0 through 7 with a leading zero. A sequence of digits 
preceded by 0x or 0X is considered as hexadecimal integer. They may also include alphabets 
A through F.
Real literals 
Integers containing fractional parts are called real (or floating point) literals. Eg. –0.75. It can 
also be expressed in exponential notation. Eg. 2.345e2 
Character literals 
It contains a single character enclosed in single quotes. Eg. ‘5’, ‘s’ as well as certain escape 
sequence characters. 
String literals 
It is a sequence of characters enclosed between double quotes. Eg. “ Good Day! “ 
Comments: 
Comments or remarks are non executable statements in the program that improve the 
readability of the program. They help in internal program documentation to understand the 
code better. It is a convention to use comments regularly in the source code. 
There are three types of comments in Java: 
i. Single line comment //this is a comment 
ii. Multi line comment /* all the enclosed 
lines are comments */ 
iii. Documentation Comment 
/** Program Name : Test 
* Author : ABC 
* Code Date: Feb 11, 2011 
*/ 
Data Type: 
Java like any other language provides ways to facilitate the handling of different types 
of data. Data types are means to identify the type of data and the associated operations of 
handling it. 
Java data types are of two types: 
i) Primitive or Intrinsic data type. 
ii) Reference or derived data type.
Primitive data types come as a part of the language. Java has 8 primitive data types- byte, 
short, int, long, float, double, char, boolean. 
Integer types 
Holds whole numbers. Java supports four types of integers - byte, short, int and long. Java 
values are signed meaning either positive or negative. 
Data Types Size in Bytes 
byte 1 
short 2 
int 4 
long 8 
Floating Point Types 
They are used to hold numbers containing fractional parts. There are 2 types of floating point 
storage- float and double. Float type values are single-precision while double represent 
double-precision numbers. 
Data Types Size in Bytes 
float 4 
double 8 
Character Type 
These are used to store character literals in memory. They are always enclosed in single 
quotes e.g. ‘ a‘. The data type is called char. It occupies 2 bytes in memory. 
Boolean Type 
It is used to test a condition. A boolean datatype can only have one of these two values: true 
or false. It occupies 1 byte in memory.
Variables 
It is a named memory location storing varying values. It is an identifier that denotes a storage 
location used to store a data value. It may take different values during program execution. 
Operators and Operands 
An operator is a symbol that tells computer to perform certain mathematical or logical 
manipulations. They are used in programs to manipulate data and variables. Java operators 
are classified into following categories: 
Operands are identifiers on whom operators perform the operations. 
int a = b + c; // Here = and + are operators 
a, b and c are operands 
Unary Operators (Operators that perform operations on one operand) 
Increment & decrement operator 
These operators are ++ and --. ++ add 1 to the operand while -- subtracts 1. 
Binary Operators (Operators that perform operations on two operands) 
Arithmetic operators 
The operator +, -, *, /, % can operate on any built-in numeric data type. The unary minus 
multiplies its single operand by –1. 
Relational operators 
The comparison of 2 data items is done with the help of relational operator. The result of a 
relational expression is either true or false. The relational operators are <, <=, >, >=, ==, !=. 
Logical operators 
It also yields true or false. The operators are &&(and), | |(or), !(not). 
Assignment operators and Shorthand Assignment Operators. 
They are used to assign the value to a variable. (= is the assignment operator)
The shorthand assignment operators are +=, *=, /=, %=, -=. 
Ternary Operators (Operators that perform operations on three operands) 
Conditional operators 
The pair ?: is a ternary operator in Java. It is used to construct conditional expression in Java. 
exp1 ? exp2 : exp3 
if exp1 is evaluated first, & if it is true then the value of exp2 is return else exp3 is return.

Contenu connexe

Tendances

Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageDr.YNM
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxShreyasLawand
 
Microsoft word ppt presentation
 Microsoft word  ppt presentation Microsoft word  ppt presentation
Microsoft word ppt presentationvethics
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programmingprogramming9
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners Sujith Kumar
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statementnarmadhakin
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ LanguageWay2itech
 
Flowchart and algorithem
Flowchart and algorithemFlowchart and algorithem
Flowchart and algorithemehsanullah786
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to htmlvikasgaur31
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,pptAllNewTeach
 

Tendances (20)

Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Programming
ProgrammingProgramming
Programming
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptx
 
C tokens
C tokensC tokens
C tokens
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Microsoft word ppt presentation
 Microsoft word  ppt presentation Microsoft word  ppt presentation
Microsoft word ppt presentation
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Python programming
Python  programmingPython  programming
Python programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Data types
Data typesData types
Data types
 
Loops c++
Loops c++Loops c++
Loops c++
 
HTML practicals
HTML practicals HTML practicals
HTML practicals
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Data types in C
Data types in CData types in C
Data types in C
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Flowchart and algorithem
Flowchart and algorithemFlowchart and algorithem
Flowchart and algorithem
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
 

Similaire à Grade 8: Introduction To Java

Algorithm and flowchart(1)
Algorithm and flowchart(1)Algorithm and flowchart(1)
Algorithm and flowchart(1)Suneel Dogra
 
Programming language
Programming languageProgramming language
Programming languageShuja Qais
 
Top Programming Languages of 2020
Top Programming Languages of 2020Top Programming Languages of 2020
Top Programming Languages of 2020Ikbal Ahmed
 
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
 
Programming languages of computer
Programming languages of computerProgramming languages of computer
Programming languages of computerKeval Goyani
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingGwyneth Calica
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compilerA. S. M. Shafi
 
Abstraction level taxonomy of programming language frameworks
Abstraction level taxonomy of programming language frameworksAbstraction level taxonomy of programming language frameworks
Abstraction level taxonomy of programming language frameworksijpla
 
Generation of Computer language by arya dutta (1).pptx
Generation of Computer language by arya dutta (1).pptxGeneration of Computer language by arya dutta (1).pptx
Generation of Computer language by arya dutta (1).pptxAryaDutta4
 
Trend of Visual Programming Language
Trend of Visual Programming LanguageTrend of Visual Programming Language
Trend of Visual Programming LanguageTeddy Marcus
 
computer languages
computer languagescomputer languages
computer languagesYasirali328
 
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming LanguagesMuhammad Hammad Waseem
 

Similaire à Grade 8: Introduction To Java (20)

Algorithm and flowchart(1)
Algorithm and flowchart(1)Algorithm and flowchart(1)
Algorithm and flowchart(1)
 
Programming language
Programming languageProgramming language
Programming language
 
Top Programming Languages of 2020
Top Programming Languages of 2020Top Programming Languages of 2020
Top Programming Languages of 2020
 
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
 
Programming languages of computer
Programming languages of computerProgramming languages of computer
Programming languages of computer
 
Unit 1
Unit 1Unit 1
Unit 1
 
JAVA
JAVAJAVA
JAVA
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Abstraction level taxonomy of programming language frameworks
Abstraction level taxonomy of programming language frameworksAbstraction level taxonomy of programming language frameworks
Abstraction level taxonomy of programming language frameworks
 
Generation of Computer language by arya dutta (1).pptx
Generation of Computer language by arya dutta (1).pptxGeneration of Computer language by arya dutta (1).pptx
Generation of Computer language by arya dutta (1).pptx
 
SYSTEM DEVELOPMENT
SYSTEM DEVELOPMENTSYSTEM DEVELOPMENT
SYSTEM DEVELOPMENT
 
Trend of Visual Programming Language
Trend of Visual Programming LanguageTrend of Visual Programming Language
Trend of Visual Programming Language
 
computer languages
computer languagescomputer languages
computer languages
 
Programming
ProgrammingProgramming
Programming
 
Languages in computer
Languages in computerLanguages in computer
Languages in computer
 
Java Programming Basics
Java Programming BasicsJava Programming Basics
Java Programming Basics
 
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
 
Ict topic 5
Ict topic 5Ict topic 5
Ict topic 5
 
Notacd071
Notacd071Notacd071
Notacd071
 

Plus de nandanrocker

Plasma ball and fluorescent lamp experiment
Plasma ball and fluorescent lamp experimentPlasma ball and fluorescent lamp experiment
Plasma ball and fluorescent lamp experimentnandanrocker
 
Halcyon Attractions Of Nature
Halcyon Attractions Of NatureHalcyon Attractions Of Nature
Halcyon Attractions Of Naturenandanrocker
 
Atmospheric Pollution
Atmospheric PollutionAtmospheric Pollution
Atmospheric Pollutionnandanrocker
 
Indus Valley Civilization
Indus Valley CivilizationIndus Valley Civilization
Indus Valley Civilizationnandanrocker
 
Some applications on Trigonometry
Some applications on TrigonometrySome applications on Trigonometry
Some applications on Trigonometrynandanrocker
 
Extinct and endangered animals
Extinct and endangered animalsExtinct and endangered animals
Extinct and endangered animalsnandanrocker
 
The london olympic games
The london olympic gamesThe london olympic games
The london olympic gamesnandanrocker
 
Global warming faq
Global warming faqGlobal warming faq
Global warming faqnandanrocker
 
Archimedes' principle
Archimedes' principleArchimedes' principle
Archimedes' principlenandanrocker
 
Energy conservation
Energy conservationEnergy conservation
Energy conservationnandanrocker
 
The khilafat movement
The khilafat movementThe khilafat movement
The khilafat movementnandanrocker
 
Energy saving tips
Energy saving tipsEnergy saving tips
Energy saving tipsnandanrocker
 
Natural disasters and their impact towards the environment
Natural disasters and their impact towards the environmentNatural disasters and their impact towards the environment
Natural disasters and their impact towards the environmentnandanrocker
 

Plus de nandanrocker (17)

Plasma ball and fluorescent lamp experiment
Plasma ball and fluorescent lamp experimentPlasma ball and fluorescent lamp experiment
Plasma ball and fluorescent lamp experiment
 
Halcyon Attractions Of Nature
Halcyon Attractions Of NatureHalcyon Attractions Of Nature
Halcyon Attractions Of Nature
 
Atmospheric Pollution
Atmospheric PollutionAtmospheric Pollution
Atmospheric Pollution
 
Indus Valley Civilization
Indus Valley CivilizationIndus Valley Civilization
Indus Valley Civilization
 
Some applications on Trigonometry
Some applications on TrigonometrySome applications on Trigonometry
Some applications on Trigonometry
 
Extinct and endangered animals
Extinct and endangered animalsExtinct and endangered animals
Extinct and endangered animals
 
Crystallography
Crystallography Crystallography
Crystallography
 
The london olympic games
The london olympic gamesThe london olympic games
The london olympic games
 
Road accidents
Road accidentsRoad accidents
Road accidents
 
Global warming faq
Global warming faqGlobal warming faq
Global warming faq
 
Archimedes' principle
Archimedes' principleArchimedes' principle
Archimedes' principle
 
Measles
MeaslesMeasles
Measles
 
Measles
MeaslesMeasles
Measles
 
Energy conservation
Energy conservationEnergy conservation
Energy conservation
 
The khilafat movement
The khilafat movementThe khilafat movement
The khilafat movement
 
Energy saving tips
Energy saving tipsEnergy saving tips
Energy saving tips
 
Natural disasters and their impact towards the environment
Natural disasters and their impact towards the environmentNatural disasters and their impact towards the environment
Natural disasters and their impact towards the environment
 

Dernier

SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 

Dernier (20)

SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 

Grade 8: Introduction To Java

  • 1. Grade VIII Computer Applications Introduction to Java Program: A program is a set of instructions written to perform a specific task. Programming Languages: Programming Languages can be broadly classified as: i) Low Level Language: Machine Language (1GL) Assembly Language (2GL) ii) High Level Language: Procedural (3GL) Non-Procedural (4GL) i) Machine Language : (1st Generation Language) Machine language is literally binary sequences (lots of 0s and 1s) interpreted by the computer as instructions. It is the only language that the computer directly understands. Advantage: Its efficiency and speed of processing. Disadvantages a. Coding in the machine language is an extremely cumbersome and complicated task that is prone to errors. b. The language itself is not very human readable. (i.e. user friendly). c. The language is also machine dependent and requires knowledge of complete computer circuitry. ii) Assembly Language: (2nd Generation Language) The first language similar to English was developed in 1950 which was known as Assembly Language or Symbolic Programming Language. Assembly language is a low level language that uses small symbolic words called mnemonics instead of zeroes and ones. These mnemonics like ADD to add, MUL to multiply, LOC to locate an address and such others express the operations to be performed. A translator called the assembler converts these mnemonics to the machine language and performs the necessary action. Advantages: Assembly language is very powerful and efficient. It is fast, small in program size and flexible. This language is popularly used at microprocessor level and system coding. Disadvantages: It is not very user friendly and easily understandable. The assembler must be loaded to the computer memory for translation and it occupies a sizeable memory of the computer, hence Assembly Language cannot be used with small capacity computers.
  • 2. iii) High Level Language: (3rd Generation Language) Procedural languages are used to solve problems and are often described as problem oriented languages. They focus on the method or HOW to solve the problem. In high level languages, the programs are written in a language which is closer to the user i.e. English, just following some rules specific for the language (syntax). Every instruction that the programmer writes in this language is translated into the machine language using a language processor /translator called the compiler or the interpreter. Advantages: HLL is independent of the internal machine code of any particular computer. High Level language is the most understandable and easy to code language besides having the following advantages, easier documentation, easy to learn and use and modifications can be done more easily. Disadvantages: The syntax and the semantics of the language need to be learnt and only then can it be used. BASIC, COBOL, Pascal, FORTRAN, C, C++, Java are some examples of HLL. Programming in HLL can be done in one of the following two approaches: a) Procedural Programming Approach b) Object Oriented Programming Approach. iv) Non-Procedural Language: 4GLs are non procedural, that is only “WHAT is required” is to be specified and the rest gets done on its own. The main aim of the 4GL is to cut down on development and maintenance time and make it easier for users. The user interacts with the utility software which is an integral part of a 4GL and that in turn interacts with the system to get the work done. Word processors, spreadsheets, DBMS, graphic software are some of the examples of 4GLs. TRANSLATORS OR LANGUAGE PROCESSORS: (COMPILERS AND INTERPRETERS) Translators are system software that perform the process of converting a high level language instruction to the machine language. A) Compiler: A compiler converts the HLL program into the machine language at one go. It converts the entire HLL program at a time and reports all the errors of the program along with the line numbers. After the program is debugged, it is recompiled and after that the compiler is not needed in the memory as the object program is available. B) Interpreter: This language processor converts s a HLL program into machine language by converting and executing it line by line. It there is any error in any line, it reports it at the same time and program execution cannot be resumed till the error is rectified. The interpreter must always be present in the memory every time the program is executed. For error debugging, interpreter is very much useful as it reports the errors immediately on occurrence but after the program is debugged, unnecessary usage of memory takes place as it has to be present in the memory always. Therefore, combination of interpreter and compiler is an ideal option of HLL translation to the machine code. For the initial error removal, the interpreter can be used and then the program can be compiled enabling the removal of the language translator from the memory.
  • 3. Programming Approach Programming in HLL can be done in one of the following two approaches: a) Procedural Programming Approach b) Object Oriented Programming Approach. a) Procedural or Structured Programming: Developing a language with a process centric approach is called procedural programming. It concentrates on HOW to solve the problem. It focuses on the methods/processes for which the software is being built. This approach refers to breaking up the complex problem into smaller problems and then solving each by using modules (functions or procedures) which act on the data. These functions are tightly interdependent on each other. Example: BASIC, COBOL, C, Pascal. Drawbacks: i) The modules or parts of the whole program strongly depend on each other. So a module cannot be reused by other programs. ii) The procedural program code is not flexible to change. The program written in a procedural language completely needs to be changed as all the parts of a program are linked and dependent on each other. iii) Solutions to real world problems cannot be directly depicted using this language. b) Object Oriented Programming: OOP simulates the real world in software. Real world consists of identifiable entities or objects. These objects have their peculiar characteristics and behavior. Examples of real world objects are books, pens, students, chair, and car and so on. This approach concentrates on “WHAT”- “What is the object that will get affected by this problem?” and then the approach works on the attributes/state and behavior/methods of that object. Examples: Smalltalk, C++, Java. Advantages: i) This approach models the real world quite accurately as the programs written in the language are focused on the objects rather than the procedure. ii) It is extremely reusable as these objects can be invoked in different programs. iii) Programs written in OOP are simple to change when the requirements for the application changes. iv) The principles of OOP prevent the objects from being mishandled and are kept safe from unauthorized access.
  • 4. JAVA (An Object Oriented Programming Language) History of Java Sun Micro systems began for software to run on TV and VCR sets i.e. Interactive TV and VCR sets. A team of software engineers led by James Gosling, Patric Naughton, Chris Warth, Ed Frank and Mike Sheridan laid specifications for these projects in 1991. By September 1992, the basic system was drafted. These interactive sets were called set-top boxes. The hardware was called 7(Seven), OS was called Green and the programming language was called OAK. Between the initial implementation of OAK in the fall of 1992 and the public announcement of Java in 1995, many more people contributed to the design and the evolution of the language. Bill Joy, Arther van Hoff, Jonathan Payne, Frank Yellin and Tim Lindholm were key contributors to the maturing of the older prototype. Hot Java was the first commercial product to be developed completely in Java. On May 23, 1995, Java was commercially released. The advent of Internet gave a tremendous boost to this language. Java Programs can be embedded in HTML pages and downloaded by Web browser to bring live animations and interaction to web clients. The power of Java is not limited to web applications. Java is a general purpose programming language. It has full programming features and can be used to develop standalone applications. Characteristics of Java 1) It is simple : No programming language is simple, but java is bit simple as compared to other OOP language such as C++. 2) It is object oriented : Java is called OOP language because Java is centered on creating objects, manipulating objects and making objects working together. 3) It is distributed : Distributed computing involves several computers on a network working together. Java is designed to make distributed computing easy. Networking capability is inherently integrated into Java.
  • 5. 4) Java is compiled as well as interpreted: One needs an interpreter and a compiler to run Java programs. The programs are compiled into Java Virtual Machine Code called bytecode. The bytecode is machine independent and can run on any machine that has java interpreter. 5) Java is highly case sensitive: Java is highly case aware. Instructions written in java are different when written in the lower case and the upper case. 6) It is robust: Robust means reliable. No programming language can assure reliability. Java puts a lot of emphasis on early checking of possible errors as java compilers can detect many problems that would throw show up at execution time in other languages. It has a runtime exception handling feature to provide programming support for robustness. Java can catch and respond to an exceptional situation so that the program can continue its normal execution and terminate gracefully when a runtime error occurs. 7) It is secure : Java being an Internet programming language is used in a networked and distributed environment. You can download a java applet, run it on your computer and it will cause no damage to your system. 8) It is architecturally neutral- The most remarkable feature of java is that it is architectural neutral (Platform Independent). You can write one program that runs on any platform with JVM (Java Virtual Machine). You can run Java Applets from a Web Browser, but java is more than just a web applet. You can also run stand-alone java applications directly from operating system by using a java interpreter. 9) It is portable: Java programs can run on any platform without having to be recompiled. This is one positive aspect of portability. 10) It is multithreaded : Multithreading is capability for a program to perform several tasks simultaneously within a program. E.g. downloading a video file while playing a video file would be considered multithreading. It is smoothly integrated in Java. 11) It is a dynamic and one of the most high performance languages today. JAVA APPLICATIONS Java programs can be one of the two types: stand alone applications and applets. Applications are stand-alone programs like any program written using high-level language. Applications can be executed from any computer with a Java interpreter and are ideal for developing software. Applets are special kind of Java programs that can run directly from Java compatible Web browser. Applets are suitable for deploying (installing) Web projects.
  • 6. Java Program Structure (For stand alone programs only) Probably, the best way to start learning a programming language is to write a simple program. [* Please consider the program structure as a mandatory syntax requirement, the details of what is it will be learnt by you in due course of time] /* program to -- Welcome to Java*/ class Welcome { public static void main(String args[]) { System.out.println(“Welcome to Java”); } } Let us now examine the parts of this sample program: i) /* program… welcome to java*/ The text enclosed with /* …*/ is called comment. Comments or remarks are non executable statements purely for enhancing the program readability. ii) class Welcome Every java program should begin with the “class” keyword. Java being OOP, classes contain attributes/data members and behavior/methods of the objects. Methods may contain other executable statements. Here a class/program with the name Welcome is defined. It is also called the initial class since it defines the program name. The file name of this program should be Welcome.java- i.e. same name as that of the class. Although there can be many classes in a Java program, there can by only one initial class in a Java program. An initial class contains the main function inside it. iii) public static void main(String args[]) This is the syntax of the “main” method, it cannot be changed. It is the most important method because it is from this method that the application begins executing the program. (Cannot have any other name) If there are several methods in a program, the program will only begin executing from the main method. If there are many classes within a Java
  • 7. program, the execution will only begin from the initial class (the class that contains the main method) If there is no main method in the class, no execution will take place. Thus the main method is also called the driver method. On reaching the end of main, the program terminates and the control passes back to the operating system. Let us now understand each keyword of this method declaration: public- “main” is the first method called by the Java environment when a program is executed so it has to be accessible from the Java environment (JDK software). This method has to be publicly available otherwise how can it be accessed outside the program. Hence the access specifier has to be public. static- static methods are class methods that do not need the creation of any object to work with the method. void – Functions or methods can return a value. void means nothing. The main method does not return any value, hence it is declared void. String args[ ]- Functions or methods can also take in arguments or parameters to work on them. The main method can take arguments in this form. iii) { } The pair of curly braces called the block of code marks the scope of the main method and the scope of the class. They indicate the boundaries. iv) System.out.println(“Welcome to Java”); This statement prints “Welcome to Java” on the standard output device which is generally the monitor. This is the statement to print the desired output that is present in the brackets (“ … ”). Here, System – computer, out – output device(monitor) , println – print the output and the control goes to the next line. Exercise I : Write programs in Java to: i) Print your name
  • 8. ii) Print your name and address iii) Print your name , school name and class name iv) Print a pattern like “****” “***” “*” v) Print the message “hello world!”. The Java Language Java Keywords: Keywords are the words that convey a special meaning to the language compiler. These are reserved for special purpose and cannot be used as normal identifier names. abstract boolean break Byte case catch char class const Continue default do double else extends Final finally float for goto if implements import instanceof int interface long native new package private protected public Return short static strictfp super switch synchronized this throw throws transient try Void volatile while *true and false and null are reserved words but not keywords, they are literals. Identifiers: Identifiers are fundamental building blocks of a program. They are programmer designed tokens. They are used for naming all the components of a program like the classes, methods, variables, objects, labels, packages, and interfaces in a program. The identifier follows the following rules: 1. They can have alphabets, digits, underscore, and dollar sign characters. 2. They must not begin with a digit. 3. Uppercase and lowercase letters are distinct. Java is case sensitive. 4. They can be of any length. 5. They must not be a keyword or a boolean or null literal.
  • 9. Java developers follow some naming conventions for the identifiers. Conventions are good programming practice to improve the readability of the program. · Names of all public methods and instance variables start with a leading lowercase letter. If the name has more than one word, the second and subsequent words are marked with a leading uppercase letters. E.g. average totalMarks · All private and local variables use only lowercase letters combined with underscores. E.g. length batch_strength · All classes & interfaces start with a leading uppercase letter (and subsequent words are marked with a leading uppercase letter). E.g. Student MotorCycle · Variables that represent literal values use all uppercase letters & underscores. Eg TOTAL MAX_MARKS Literals They refer to fixed values that do not change during the execution of a program. Integer literals It refers to sequence of digits. There are 3 types of integer literals, namely, decimal integer, octal integer and hexadecimal integer. Decimal integer consists of a set of digits, 0 through 9, preceded by an optional minus sign. An octal integer literal consists of digits 0 through 7 with a leading zero. A sequence of digits preceded by 0x or 0X is considered as hexadecimal integer. They may also include alphabets A through F.
  • 10. Real literals Integers containing fractional parts are called real (or floating point) literals. Eg. –0.75. It can also be expressed in exponential notation. Eg. 2.345e2 Character literals It contains a single character enclosed in single quotes. Eg. ‘5’, ‘s’ as well as certain escape sequence characters. String literals It is a sequence of characters enclosed between double quotes. Eg. “ Good Day! “ Comments: Comments or remarks are non executable statements in the program that improve the readability of the program. They help in internal program documentation to understand the code better. It is a convention to use comments regularly in the source code. There are three types of comments in Java: i. Single line comment //this is a comment ii. Multi line comment /* all the enclosed lines are comments */ iii. Documentation Comment /** Program Name : Test * Author : ABC * Code Date: Feb 11, 2011 */ Data Type: Java like any other language provides ways to facilitate the handling of different types of data. Data types are means to identify the type of data and the associated operations of handling it. Java data types are of two types: i) Primitive or Intrinsic data type. ii) Reference or derived data type.
  • 11. Primitive data types come as a part of the language. Java has 8 primitive data types- byte, short, int, long, float, double, char, boolean. Integer types Holds whole numbers. Java supports four types of integers - byte, short, int and long. Java values are signed meaning either positive or negative. Data Types Size in Bytes byte 1 short 2 int 4 long 8 Floating Point Types They are used to hold numbers containing fractional parts. There are 2 types of floating point storage- float and double. Float type values are single-precision while double represent double-precision numbers. Data Types Size in Bytes float 4 double 8 Character Type These are used to store character literals in memory. They are always enclosed in single quotes e.g. ‘ a‘. The data type is called char. It occupies 2 bytes in memory. Boolean Type It is used to test a condition. A boolean datatype can only have one of these two values: true or false. It occupies 1 byte in memory.
  • 12. Variables It is a named memory location storing varying values. It is an identifier that denotes a storage location used to store a data value. It may take different values during program execution. Operators and Operands An operator is a symbol that tells computer to perform certain mathematical or logical manipulations. They are used in programs to manipulate data and variables. Java operators are classified into following categories: Operands are identifiers on whom operators perform the operations. int a = b + c; // Here = and + are operators a, b and c are operands Unary Operators (Operators that perform operations on one operand) Increment & decrement operator These operators are ++ and --. ++ add 1 to the operand while -- subtracts 1. Binary Operators (Operators that perform operations on two operands) Arithmetic operators The operator +, -, *, /, % can operate on any built-in numeric data type. The unary minus multiplies its single operand by –1. Relational operators The comparison of 2 data items is done with the help of relational operator. The result of a relational expression is either true or false. The relational operators are <, <=, >, >=, ==, !=. Logical operators It also yields true or false. The operators are &&(and), | |(or), !(not). Assignment operators and Shorthand Assignment Operators. They are used to assign the value to a variable. (= is the assignment operator)
  • 13. The shorthand assignment operators are +=, *=, /=, %=, -=. Ternary Operators (Operators that perform operations on three operands) Conditional operators The pair ?: is a ternary operator in Java. It is used to construct conditional expression in Java. exp1 ? exp2 : exp3 if exp1 is evaluated first, & if it is true then the value of exp2 is return else exp3 is return.