User talk:Maithili Bhardwaj

Program Coding
Program coding (Programming) involves the use of a computer programming language to write a series of instructions (algorithms) called a computer program that the computer can interpret and carry out. All the operations performed by a computer are controlled by computer programs. Introduction of program coding (programming) can be explained by using a computer language. This topic will develop your ability to write, compile and execute any program to solve the problem in a computer. You will also appreciate the need and importance of programming. Maithili Bhardwaj (talk) 15:28, 7 October 2021 (UTC)

Data Types in Java
Language is a medium of communication. If you want to convey your thoughts to your friends, then a language. This language must be commonly known you need by both of you. It is very difficult to share your views or ideas with a person who does not know the language that you know. Hence, languages are essentially required to establish communication among people.

Computer is a machine that understands a specific language. A set of rules that provides a way of telling a computer what operations to perform is called a programming language. If you need to communicate with a computer, then you must learn the language that it understands. This is the reason why you need to learn a computer language.

𝗡𝗲𝗲𝗱 𝗳𝗼𝗿 𝗖𝗼𝗺𝗽𝘂𝘁𝗲𝗿 𝗣𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴 Suppose, you want to instruct a computer to perform a task. For this, you need to give instructions in the coded form which the computer understands. Thus, a sequential set ofinstructions coded in a computer language that are given to perform a specific task is known as a 'Program Computer programming is needed because:

It regulates the functioning of computer hardware/software components. It promotes communication between users and machines.

It helps in developing problem solving skills.

It encourages logic building among users.

. It empowers the capability towards error detection and correction. It increases the confidence level of the users to solve problems.

• It helps in understanding computers and also gaining knowledge. There are many programming languages through which you can develop programming codes to perform various tasks. Some of the latest computer languages available for coding a program are C, C++, Java, Python and Visual Basic. In this chapter, you will learn about Java (a programming language) that allows you to code computer programs in an easy manner.

𝗜𝗻𝘁𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻 𝘁𝗼 𝗷𝗮𝘃𝗮 ( 𝗔 𝗣𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴 𝗟𝗮𝘂𝗻𝗴𝗮𝗴𝗲) Java is an object-oriented programming language developed primarily by James Gosling and his colleagues at the Sun Micro Systems in USA. The language was initially called Oak (named after the oak tree outside Gosling's office). In 1991, the Sun Micro Systems (Broomfield, Colorado, USA) developed a complete language as a part of its research work to develop a software for consumer electronics. It was developed as a full-fledged programming languagein which one could accomplish the same kinds of tasks and solve similar problems that one could do in other programming languages such as BASIC, C++, etc. Platform Independence is the most significant advantage that JAVA has over other languages. It has the capability of moving easily from one computer system to another.

Java, being an object oriented programming language, encapsulates many features of C++. Originally, Java was designed to execute applets that are downloaded while web browsing. Gradually, Java has been gaining wide acceptance as a programming language, very often replacing C or C++.

𝗕𝗮𝘀𝗶𝗰 𝗙𝗲𝗮𝘁𝘂𝗿𝗲𝘀 𝗼𝗳 𝗷𝗮𝘃𝗮 Java has the following features:

Java is an object-oriented programming language.

Java programs are both compiled and interpreted.

It can access data from a local system as well as from the Internet.

Java programming is written within a class. The variables and functions are declared and defined with the class. Java programs can create applets (the programs which run on web browsers) and applications (general programs) like any other programming language.

• Java doesn't require any preprocessor (#) or inclusion of header files for creating a Java application program.

Java is case sensitive. As a programming language, the upper case and lower case letters are distinguished by the language.

𝗖𝗼𝗺𝗽𝗶𝗹𝗲𝗿 𝗮𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝗽𝗿𝗲𝘁𝗲𝗿 All high-level languages, i.e., HLL need to be converted to a machine code (binary code) so that the computer can understand the program after taking the required inputs. Knowledg The computer processes the program to show the desiredame results if the program is error-free, otherwise the errors are to be corrected to execute the program successfully. The conversion of high-level language (source code) to a machine level language, i.e., MLL (binary code) can be done in two possible ways, either by using a compiler or an interpreter.

The software by which the conversion of high-level instructions is performed line-by-line to a machine level language is known as an Interpreter. If an error is found in any line, the execution is stopped till it is corrected. This process of correcting errors is easier but the program takes a longer time to be executed successfully. However, if all the instructions can be converted to machine level language at once and all the errors are listed together, then the software is known as a Compiler. This process is much faster but sometimes, it becomes difficult to debug (correct) all the errors together in a program.

Therefore, a compiler is a system program that translates the instructions of a high-level language to a machine language. A program which is input to a compiler is called a source program. This program is now converted to a machine level language by a compiler and is known as the object program or the object code.

A compiler can translate only those source programs which have been written in the language for which the computer is meant. It means that each high-level programming language requires a separate compiler for the conversion.

For example, FORTRAN compiler is capable of translating a FORTRAN program into machine code. A computer system may have more than one compiler to work for more than one high-level language.

An interpreter is generally used in microcomputers. It helps the programmer to find out the errors and correct them before the control moves to the next statement. Assemblers, compilers and interpreters are basically system softwares which are also known as language processors.

𝙎𝙤𝙡𝙫𝙚𝙙 𝙌𝙪𝙚𝙨𝙩𝙞𝙤𝙣𝙨

1. What is meant by type conversion? How is implicit conversion different from explicit conversion?

Ans. In a mixed expression, the result is obtained in a specific data type. Thus, the data type needs to be converted into the required type. This is known as type conversion. In an implicit type conversion, the result of a mixed mode expression is obtained into

the higher most data type without any intervention of the user.. eg. int a; float b; float c;

c = a + b:

In case of an explicit type conversion, the data gets converted to another type as per

user's choice and requirements. egint a; float b; double c;

b = (float)(a + c);

2. Write the output of the given snippet:

char x= 'A'; int m; m=(x== 'a')? 'A': 'a'; System.out.println("m="+m);

Ans. m = 97

3. What will the following function returns when executed? (i) Math.max(-17,-19)

Ans. 17

(ii) Math.ceil(7.8)

4. What will be the output of the following codes?

Ans. 8.0

double b = -15.6; double a = Math.rint (Math.abs(b));

System.out.println("a="+a);

Ans. a = 15

5. Give one example each of a primitive data type and a composite (non-primitive) data type. Ans. Examples of primitive data type int, float, double, long, char, o

Examples of composite data type: array, class, interface, etc.

6. Give the output of the following program seginenti double x 2.9,y-2.51 System.out.println(Math.floor(x);

System.out.println(Math.ceil(y));

Ans. 2.0 3.0

7. State the values of n and ch.

char c='A';

int_n=c+1; char ch=(char)n;

Ans. 66 and B

8. Answer in one/two words:

(i) Name two types of Java programs. (ii) Name a package that is invoked by default.

Ans. (i) Stand Alone and Java Applets; (ii) java.lang

9. Define byte code.

Ans. Java compiler converts the source code into an intermediate This code helps to generate a machine code and is independent of the machine on which the program runs. It makes a Java program highly portable. Thus, this intermediate code is known as 'byte code 10. Java uses both a compiler as well as an interpreter. Justify this statement.

Ans. The Java compiler converts the Java source code into an intermediate binary coded form

called the byte code. This byte code is further converted into a machine code and made

suitable for the specific platform with the help of an interpreter. In this way, Java uses

a compiler as well as an interpreter.

11. What is a literal?

Ans. Literal is a constant that remains fixed throughout the discussion of a program. Thus, it is a value that can be assigned to a specific variable.

eg. Integer literals: 12, 4, 342 etc Character literals: 'A 'p'? etc

String literals: "Computers", "Pay2014", "3421" etc

12. What are the types of casting shown by the following examples?

(i) double x = 15.2; int y = (int) x; Ans. Explicit type casting

(ii) int x = 12; long y = x; Ans. Implicit type casting

𝘾𝙝𝙖𝙥𝙩𝙚𝙧 𝙖𝙩 𝙖 𝙂𝙡𝙖𝙣𝙘𝙚 You need learning a computer language because computer understands a specific language. • Computer programming improves problem solving skills.

.

• Latest computer languages used as programming languages are C, C++, Java, Python, and

Visual Basic etc. • Java (A programming language) was developed by James Gosling at Sun Microsystem, USA

• Java is a platform independent, robust and case sensitive language.

• Byte code is an intermediate binary code that is independent of any machine.

Compiler converts Java source code into byte code that in turn gets converted into machine code with the help of an interpreter.

• Package is a collection of classes. It can be included in a program by using the keyword 'import:

• Reserve word is a keyword that carries special meaning for the system compiler. It cannot be

used for naming a variable. • There are two ways of writing programs in Java. (i) Java Application (ii) Java Applet

• Literals are the constants whereas variables are named memory location that contain constants.

• The data types which are fundamental or independent in nature are said to be primitive data type. e.g. int, float, double, char etc.

Non primitive data types are reference type data. They are derived from primitive data types. e.g.; arrays, class and interface.

• There are two ways of performing data type conversion i.e. implicit and explicit.

• Mathematical functions are used for easy development of program logic.

Objective

I. Multiple Choice Quest

1. A constant which gi

(a) variable

2. The default value of

(a) "false"

3. Character literal is

(a) char variable

4. A character literal

5. A set of character

(a) String variabl

6. The ASCII codes

a65-90

7. Which of the fo

(a) Math.pow(a

8. What type of va

(a) int

9. Maithili Bhardwaj (talk) 15:49, 7 October 2021 (UTC)