0% found this document useful (0 votes)
2 views

Untitled document (7)

The document outlines key concepts in Java programming, including differences between classes and objects, source code and object code, and principles of Object-Oriented Programming (OOP) such as abstraction, encapsulation, inheritance, and polymorphism. It also explains the compilation process of Java programs, the definition of tokens, keywords, constants, variables, and data types, along with their sizes. Additionally, it provides examples of operator types based on the number of operands.
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)
2 views

Untitled document (7)

The document outlines key concepts in Java programming, including differences between classes and objects, source code and object code, and principles of Object-Oriented Programming (OOP) such as abstraction, encapsulation, inheritance, and polymorphism. It also explains the compilation process of Java programs, the definition of tokens, keywords, constants, variables, and data types, along with their sizes. Additionally, it provides examples of operator types based on the number of operands.
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

Important Questions from Java Programming :-

1.​ Difference between class and object .

Answer:

Key Class Object


Definition A class is a blueprint or An object is an
template for creating objects instance of a class.

Structure A class defines properties An object contains


and methods (but doesn't actual data and
store actual data). uses the class's
structure.

Existence A class is a logical concept An object is a


and doesn't exist in memory physical entity that
until an object is created. exists in memory.


2.​Difference between Source code and Object
code.

Answer:

Key Source Code Object code


Definition The human-readable The machine
code written by a -readable code
programmer in a (binary or low-level
high-level language (e.g., instructions)
Python, C++). generated by a
compiler from the
source code.
Readability Easy to read and Not human-readable;
understand by humans. understood by the
and methods (but computer.
doesn't store actual
data).

Modification Can be directly modified Cannot be modified


by programmers. easily; it is typically
executed as-is.

3.​Write down the principles of OOPs (Object
oriented Programming Language).

Answer:

A. Abstraction: A key feature of OOP that


simplifies complexity by showing only essential
features to the user while hiding the internal
details is known as Abstraction.

B. Encapsulation: Bundling of data (attributes)


and methods (functions) that operate on the data
into a single unit (class) is called Encapsulation. It
ensures that the user cannot access the data
without proper authorisation ensuring that the
user can have access only to those functions for
which he/she is authorised , keeping the other
functions unaffected.

C. Inheritance: A mechanism where one class


(child) derives properties and behaviors from
another class (parent).

D. Polymorphism: The ability to take many


forms, allowing methods with the same name to
behave differently based on the object.
4.​Write down how a java program compiles
and interprets.Explain with a suitable
diagram.
Answer:

The java program is saved as Welcome.java.


Compilation produces another file
Welcome.class. The file is executed by the
computer.By default, these files are stored in the
Documents folder.

Hence, We can say that clearly Java is a language


that can both be compiled and interpreted.

5.​What is a Token?

Answer:
The smallest meaningful element of a Java program is
called a Token.

6.​What are the rules for naming an identifier?


(variable,class name and function name)

Answer:

The rules for naming an identifier are-

a.​ An identifier we use in a program may be


composed of any combination(A-Z) or
(a-z),underscore(_) or dollar sign($).

b.​ An identifier should noy be a Java keyword.

c.​ Java identifier can be of any length.

7. What is a keyword?

Answer: Keywords are the reserved words of a Java


program with some special meaning,and can be used
for that purpose only. The keywords cannot be used
as identifiers.

8. What is a constant?

Answer: Constants mean the fixed value that does


not change during the execution of a program. These
values can be digits or character constants.
Constants are also referred to as Literals.
​ 9. What is a variable?

Answer: A variable is a named storage location in


memory that holds data. It acts as a container for
storing values that can be changed during program
execution.

​ 10. What are data types? Write down all the


primitive data types and their size.

Answer: Data types specify the type of data that a


variable can hold, such as integers, decimals, or
characters. They help define the operations that can
be performed on the data and how it is stored in
memory.

Type Data type Size


Integer int 2 to 4 bytes(16 to 32 bits)
Fractional float 4 to 8 bytes(32 bits to 64 bits)
double
Character char 2 bytes(16 bits)
Boolean boolean 1 bit
Classwork of 17/01/2025 Computer:-

Based on the number of operands types of


operators are->

+a —> Unary operator (1)


a+b —> Binary operator (2)

(if exp 1 true then goes to exp 2) (if exp1 false then goes to exp3)

<expression 1>?<expression 2>:<expression 3>;

—> Ternary operator

Example :

int a=5,b=6,c;

c=(a>b)?a:b;

[Then ,c=6.]

Whereas same thing using if else —>


int a=5;b=6,c;

if(a>b)
c=a;
else
c=b;

You might also like