0% found this document useful (0 votes)
5 views1 page

1a Imp Questions

The document provides an overview of Java programming, including data types, differences between C++ and Java, object-oriented concepts, type casting, decision-making constructs, access modifiers, keywords, and features of Java. It also includes examples of Java programs and the structure of a Java program. Key features highlighted are Java's simplicity, object-oriented nature, platform independence, security, and robustness.
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)
5 views1 page

1a Imp Questions

The document provides an overview of Java programming, including data types, differences between C++ and Java, object-oriented concepts, type casting, decision-making constructs, access modifiers, keywords, and features of Java. It also includes examples of Java programs and the structure of a Java program. Key features highlighted are Java's simplicity, object-oriented nature, platform independence, security, and robustness.
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/ 1

1. List the data types in java.

1. Give the difference between C++ and JAVA.


Ans - Here is the table for Primitive and Non-Primitive Data Types in Java:

Ans - Type Casting in Java


Ans -
Type Data Category
Feature C++ Java
Types

2.

1.

4.
Speed Faster Slower Primitive byte, Integer Types
short,
Memory Manual (new/delete) Automatic (Garbage

(dataType), which may result in data loss.


of a larger data type into a smaller data type using
Explicit Type Casting (Narrowing) – Manual conversion
type without data loss.
conversion of a smaller data type into a larger data
Implicit Type Casting (Widening) – Automatic

Define the implicit & explicit type casting java.


int, long
Collector)
float, Floating-Point Types
Platform Runs on one system Runs anywhere (JVM)
double
Pointers Yes No char Character Type
Multiple Yes No (Uses interfaces) boolean Boolean Type (true/false)
Inheritance Non- String Text Data
Security Less secure More secure Primitive
Array Collection of Elements
Usage System programming, Mobile apps, Web apps
Class Object-Oriented Type
Games
Interface Object-Oriented Type
2. What is object? Give one example of object with its properties & 2. Explain Relational & Logical operator in java.
methods in java. Ans -Here is the merged table for Relational and Logical Operators
Ans - An object is an instance of a class that has state (properties/attributes) in Java:
and behavior (methods/actions). It is a fundamental building block of Object- Operator Type Meaning
Oriented Programming (OOP). == Relational Equal to
Objects are created from classes using the new keyword. Each object has: != Relational Not equal to
• Properties (fields/attributes) → Represent the state of the object. > Relational Greater than
• Methods (functions/actions) → Define the behavior of the object. < Relational Less than

execute. It consists of four main parts:


Ans - The for loop is used when we know how many times a block of code should
Example - Output - 60 km/h >= Relational Greater than or equal to
<= Relational Less than or equal to

5.
4.

3.

2.

1.

5.
&& Logical Logical AND (Both true)
! Logical Logical NOT (Reverses value)

Example: Print Numbers from 1 to 5


Body – The block of code to be executed repeatedly.
each iteration.
Update (Increment/Decrement) – Updates the loop variable after
each iteration).
Condition – Checks if the loop should continue (evaluated before
once).
Initialization – Defines and initializes the loop variable (executes

Explain structure of for loop with a suitable example.


3. What are the various decision-making constructions in java?
Ans -Decision-Making Constructs in Java. Java provides several decision-
making constructs to control the flow of execution based on conditions.
Construct Description
if statement Executes a block of code if the condition
is true.
3. List the various access modifiers in java if-else statement Executes one block if the condition is
Ans - Access modifiers define the scope and visibility of classes, true, otherwise executes another block.
variables, and methods in Java. if-else-if ladder Checks multiple conditions sequentially.
There are four types:Example: switch statement Selects one case from multiple options
based on a variable’s value.
Modifier Scope (Accessible From) Ternary Operator (?:) A shorthand for if-else, used for simple
public Anywhere in the program (inside and conditions.
outside the package) 6. List the various keywords in java
private Only within the same class Ans - Main Keywords in Java
Category Main Keywords
protected Within the same package and subclasses
Data Types int, float, double, char, boolean
(even in different packages)
Control Statements if, else, switch, for, while, do, break, continue,
default (no Only within the same package return
modifier)
Access Modifiers public, private, protected
Example:
class Example { Class & Object Handling class, new, this, super, final, static, extends,
public int a = 10; // Public - Accessible everywhere implements
private int b = 20; // Private - Only inside this class
protected int c = 30; // Protected - Same package & subclasses Exception Handling try, catch, finally, throw, throws
int d = 40; // Default - Only in the same package
Other Important void, package, import, null, abstract,
}
Keywords synchronized, volatile
1. What is data abstraction Java.
Ans - Data abstraction is hiding implementation details and showing 7. Explain the various features of java programming language.
only essential features. It is achieved using: Ans - Features of Java Programming Language
1. Abstract Classes (abstract keyword) Java is a widely used, secure, and platform-independent programming language. Its key features include:
1. Simple – Easy to learn, with a syntax similar to C/C++, and without complex features like
2. Interfaces (interface keyword)
pointers.
Example: abstract class Vehicle { 2. Object-Oriented – Follows OOP concepts like encapsulation, inheritance, and
abstract void start(); polymorphism.
}class Car extends Vehicle { 3. Platform-Independent – Java code runs on any OS using the JVM (Java Virtual Machine).
void start() {System.out.println("Car is starting..."); 4. Secure – Provides security features like bytecode verification and no direct memory
} access.
5. Robust – Strong memory management, exception handling, and automatic garbage
} 2. Write java program to display multiplication table of 4 collection.
Ans - public class MultiplicationTable { 6. Multithreading – Supports multiple threads for parallel execution, improving efficiency.
public static void main(String[] args) { 7. High Performance – Uses Just-In-Time (JIT) Compiler to speed up execution.
int num = 4; 8. Distributed – Supports distributed computing using RMI (Remote Method Invocation) and
networking features.
for (int i = 1; i <= 10; i++) {
9. Dynamic – Supports dynamic memory allocation and runtime class loading.
System.out.println(num + " × " + i + " = " + (num * i)); 10. Portable – Java programs are compiled into bytecode, which can run on any device with a
} JVM.
}
3. Write java program to display given 8. Explain the structure of java program.
}
number is positive or negative Ans - Structure of a Java Program
A Java program follows a specific structure, which includes the following components:
Ans –
1. Package Declaration (Optional)
Specifies the package in which the class belongs.
Example Java Program:
package mypackage;
// 1. Package declaration (optional)
2. Import Statements (Optional)
package mypackage;
Used to import built-in or user-defined classes.
// 2. Import statements (optional)
import java.util.Scanner;
import java.util.Scanner;
3. Class Definition
// 3. Class definition
Every Java program must have at least one class.
public class MyClass {
public class MyClass {
// 4. Main method (entry point)
4. Main Method
public static void main(String[] args) {
The entry point of a Java program.
// 5. Variable declaration
public static void main(String[] args) {
int num = 10;
5. Variable Declaration and Initialization
Variables store data for program execution.
int num = 10;

You might also like