0% found this document useful (0 votes)
64 views7 pages

CSN-103: Fundamentals of Object Oriented Programming: Indian Institute of Technology Roorkee

The document discusses fundamentals of object oriented programming in Java, including comparing programming languages to English, the steps to learning a programming language, data types such as constants and variables, and lexical issues related to vocabulary in Java such as keywords, variable naming conventions, and data types. It provides examples of declaring and initializing variables in Java and differences between strongly and weakly typed languages.

Uploaded by

Parth Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views7 pages

CSN-103: Fundamentals of Object Oriented Programming: Indian Institute of Technology Roorkee

The document discusses fundamentals of object oriented programming in Java, including comparing programming languages to English, the steps to learning a programming language, data types such as constants and variables, and lexical issues related to vocabulary in Java such as keywords, variable naming conventions, and data types. It provides examples of declaring and initializing variables in Java and differences between strongly and weakly typed languages.

Uploaded by

Parth Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

CSN-103: Fundamentals of Object Oriented Programming

Instructor: Dr. Rahul Thakur


Assistant Professor, Computer Science and Engineering, IIT Roorkee
Compare English and Programming Language

Steps in learning a Programming Language

2
Constants and Variables

• Constant: A constant is an entity that doesn’t change


– Example: 23, 5555, A, Rahul, 34.56
– Also called Literals in Java

• Variable: A variable is an entity that may change with time


– Just as in Mathematics
– Example: x=5, y=2.44

• Why we need variables?


– For calculations, values stored in the memory (RAM)
– Memory contains millions of ‘cells’ or ‘locations’
– Variable names  Points to memory locations  Easy referencing

3
Java: Data Types and Variables

• Variable declaration and initialization


• Example: Integers
– Correct way
int x; // Declaration
int x=10; // Declaration & Initialization

int x; // Declaration
x=10; // Initialization

– Incorrect
x=10; // Initialization without declaration
• Declaration for a variable can be done only once

4
Java: Data Types and Variables

• Java is a strongly typed language


– Every variable and expression has a type
– All assignments are checked for type compatibility
• Automatic conversion for compatible types
• No automatic conversion of conflicting types

• Strongly vs. Weakly Typed Languages


– C language is a weakly-typed language
• int i = 3.0; No Error in C/C++

5
Java: Data Types and Variables

• Variable names can be a combination of alphabets,


numbers, and special characters
• Restrictions
– Special characters ( _ and $ )
– Can’t start with a number
• 6data : WRONG
– Can’t have space
• Roll no: WRONG

• Reserved words (keywords) can’t be used as variable names

6
Lexical Issues (Vocabulary in Java)
• Keywords: Reserved. Cannot be used as names for variables,
methods, and class

You might also like