Join Our Telegram Community - Aspire2Learn
“We are here to provide you with simplified
notes for BCA and to help you throughout
your BCA journey...
Team, Aspire2Learn”
Join Our Telegram Community - Aspire2Learn
PROGRAMMING IN JAVA
SYLLABUS
UNIT - I :
Introduction to Java: -History of Java, features of Java, getting started with Java.
Java programs:-Introduction of Application & Applets. Variables: -Variable
naming,
variable initialization, assign values, Rules of variables, Scope of variable.
Operators:
Arithmetic, Assignment, Unary, Comparison, Shift, Bit- Wise, Logical, Conditional,
New, Special, Relational. Data types:-Integers, Char, String, Float etc. Typecasting:
Tokens: -Java tokens Order of precedence of operators Streams: - Input and
output.
UNIT - II :
Creating a class & subclass: -Declaring a class, Naming class, Rules to assign Class
&
Subclass, Creating a new object, Class of an object. Data members: -Declaring
data
member, Naming variables, using class members. Methods: -Using data members,
Invoke a method, passing arguments to a method, calling method. Access
Specifier &
Modifiers: -Public, Private, Protected, Static & Final. Overloading: -Method
overloading, Constructor overloading. Java class library: - Different types of
classes.
Decision making & loops:-If-then-else, Switch,? : operator, While-loop, do-while
loop,
for. Array: -Creating an array, one-dimensional array, two-dimensional array.
String:
String array, string methods. Inheritance: -Single & multiple inheritances
Interfaces:
Defining interfaces, extending interfaces, implementing interfaces.
UNIT - III :
Join Our Telegram Community - Aspire2Learn
Packages: -Java API packages, creating packages, accessing packages, adding a
class to
packages. Import statement: - Introduction & implementation of import
statement.
Applets:-Introduction to Applets & Application, how applets application are
different
creating An applet. Applets life cycle, designing a web page, creating an
executable
applet, running the applet, applet tags, passing a parameter to applet, HTML tag,
Converting applet to application. Threads:-Overview of threads, single & multiple
threads, lift cycle of threads, stopping & blocking threads, working with threads,
priority
to thread, synchronization. Exceptions & Errors:-Introduction, types of error,
exception,
syntax of exception, handling techniques, exception for Debugging.
UNIT - IV :
Event: -Event driven programming, handling an (AWT) events. Graphic class:
Introduction, the graphic classes, drawing & filling of lines, rectangle, circle &
ellipse,
arcs, polygons, text & fonts, creating a font class, font objects, text, coloring
object.
Streams:-Introduction, Abstract stream classes, file input & output.
AWI Applications: -Creating a GUI using AWT toolkit, using component class,
frames.
Components & Control: -Textfield, textarea class, label, button, choice, list,
checkbox,
class, and combo. Menus: -Creating a popup menus. Image: - Type of image,
Properties
of an image, Displaying an image. Layouts: -Using Window Listener interface,
Different
types of Layout, Layout manager, Flow manager, Grid manager. Container: -
Different
types of container (Frame, Dialog, Panel).
Join Our Telegram Community - Aspire2Learn
UNIT ONE –
------------------------------------------------------------------------------
1. Explain different types of operators supported in java.
S[2024,2018].
OR
2. What are different operator in java ? Explain conditional
operator with example. S[2023].
OR
3. Wrie different types of operators in java. Explain Bit-wise
operator with example. W[2019].
OR
4. List the operator supported by java explain bitwise
operator with example. W[2018].
Ans –
Types of Operators in Java –
1. Arithmetic Operators
Used to perform mathematical operations.
Operator Description Example
+ Addition a+b
Join Our Telegram Community - Aspire2Learn
- Subtraction a-b
* Multiplication a*b
/ Division a/b
% Modulus a%b
(Remainder)
Example:
2. Assignment Operators -
Used to assign values to variables.
Operator Description Example
= Assign a = 10
+= Add & assign a += 5 (a = a + 5)
-= Subtract & assign a -= 3 (a = a - 3)
*= Multiply & assign a *= 2 (a = a * 2)
Join Our Telegram Community - Aspire2Learn
/= Divide & assign a /= 2 (a = a / 2)
Example:
3. Unary Operators
Used with a single operand.
Operator Description Example
+ Positive value +a
- Negative value -a
++ Increment a++ or ++a
-- Decrement a-- or --a
Example:
Join Our Telegram Community - Aspire2Learn
4. Relational (Comparison) Operators
Used to compare values.
Operator Description Example
== Equal to a == b
!= Not equal to a != b
> Greater than a>b
< Less than a<b
>= Greater than or a >= b
equal to
<= Less than or equal a <= b
to
Example:
5. Logical Operators
Used to perform logical operations.
Join Our Telegram Community - Aspire2Learn
Operator Description Example
&& Logical AND (a > 5 && b < 10)
|| Logical OR (a>5 || b<10)
! Logical NOT !(a > b)
Example:
6. Bitwise Operators
Used for binary operations.
Operator Description Example
& Bitwise AND a&b
| BITWISE OR a|b
^ Bitwise XOR a^b
~ Bitwise ~a
Complement
Join Our Telegram Community - Aspire2Learn
<< Left Shift a << 2
>> Right Shift a >> 2
Example:
7. Ternary(Conditional) Operator -
Short form of if-else statement.
Syntax:
Example:
Join Our Telegram Community - Aspire2Learn
8. Instanceof Operator
Checks if an object is an instance of a class.
Example:
------------------------------------------------------------------------------
5. Explain the structure of java program with suitable
example. S[2024,2019,2018].
Ans –
Structure of a Java Program
A Java program follows a specific structure that consists
of various components. Understanding the structure
helps in writing clean and efficient code.
Basic Structure of a Java Program
Join Our Telegram Community - Aspire2Learn
Explanation of Java Program Components
Component Description
1. Package Declaration Declares a package
(optional). Used for
organizing related classes.
2. Import Statements Imports built-in or user-
defined packages (optional).
3. Class Declaration Every Java program must
have at least one class.
Join Our Telegram Community - Aspire2Learn
4. Main Method Execution starts from public
static void main(String[]
args).
5. Variable Declaration Declaring and initializing
variables.
6. Printing Output System.out.println() is used
for displaying output.
Example: Java Program with All Components
Join Our Telegram Community - Aspire2Learn
Explanation of Example Program -
1. Package Declaration: Declares myPackage, grouping
related classes together.
2. Import Statement: Imports Scanner class from java.util
for user input.
Join Our Telegram Community - Aspire2Learn
3. Class Declaration: Declares ExampleProgram as the
main class.
4. Main Method: Execution starts from public static void
main(String[] args).
5. Variable Declaration: Uses Scanner to take user input.
6. Printing Output: Displays a welcome message based on
user input.
Expected Output
Explanation of Output -
The program prompts the user: "Enter your name:"
If the user enters "John", the program reads the input.
It then prints: "Hello, John! Welcome to Java."
------------------------------------------------------------------------------
6. Explain the concept of typecasting in java.
S[2024,2023],W[2019].
OR
7. Explain with example type casting and conversion in java.
W[2018].
Join Our Telegram Community - Aspire2Learn
Ans –
Definition:
Typecasting in Java is the process of converting one data
type into another. It is used when we need to store a
value of one type into another type of variable.
Types of Typecasting in Java –
1. Implicit Typecasting (Widening Conversion)
Automatically done by Java.
Converts a smaller data type to a larger data type.
No data loss occurs.
Example:
Output:
Join Our Telegram Community - Aspire2Learn
2. Explicit Typecasting (Narrowing Conversion)
Done manually using (type).
Converts a larger data type into a smaller data type.
May lead to data loss.
Example:
Output:
Join Our Telegram Community - Aspire2Learn
Explanation: The decimal part 0.99 is lost during
conversion.
Real-World Example
Implicit Casting: Assigning an integer (100) to a double
variable in a shopping cart system.
Explicit Casting: Converting a product's price (double)
into an integer for discount calculations.
------------------------------------------------------------------------------
8. What is variable ? Write rules for naming variable with
example. S[2023,2019].
Ans –
Definition:
A variable in Java is a container that stores data values. It
acts as a named memory location where we can store,
modify, and retrieve data during program execution.
Rules for Naming Variables in Java -
1. Must start with a letter (A-Z or a-z), _ (underscore), or $
(dollar sign).
2. Cannot be a Java keyword (e.g., int, class, static are not
allowed).
Join Our Telegram Community - Aspire2Learn
3. Can contain letters, digits (0-9), _, and $.
4. Case-sensitive (Age and age are different variables).
5. Should be meaningful (e.g., studentName is better than
s).
6. No spaces allowed (use camelCase like firstName).
7. Should not start with a digit (e.g., 1name is invalid).
8. Follow camelCase convention (myVariable,
totalAmount).
Example: Valid & Invalid Variable Names –
Variable Name Valid/Invalid Reason
age ✅ Valid Starts with a letter
_name ✅ Valid Can start with _
$price ✅ Valid Can start with $
1student ❌ Invalid Cannot start with
a digit
Join Our Telegram Community - Aspire2Learn
class ❌ Invalid class is a Java
keyword
first Name ❌ Invalid No spaces allowed
my-variable ❌ Invalid Hyphens (-) are
not allowed
Example Java Program: Declaring Variables –
Output:
Join Our Telegram Community - Aspire2Learn
------------------------------------------------------------------------------
9. Explain the feature of java in detail. S[2019,2018].
OR
10. What are the feature of java. W[2018].
OR
11. Explain the following feature of java :
I. Platform independent and portable.
II. Robust and secure. W[2019].
Ans –
Features of Java
Java is a high-level, object-oriented, platform-
independent programming language designed to be
secure, fast, and reliable.
Below are the key features of Java:
1. Simple -
Java syntax is easy to learn and similar to C/C++ but with
simplified memory management.
Join Our Telegram Community - Aspire2Learn
It removes complex features like pointers, multiple
inheritance, and explicit memory allocation (malloc and
free in C).
Example:
Output: Value of a: 10
2. Object-Oriented
Java follows the OOP (Object-Oriented Programming)
principles:
Encapsulation – Data hiding using classes and objects.
Abstraction – Hides implementation details from the
user.
Inheritance – Allows reusability of code.
Polymorphism – Enables a single function to behave
differently.
Example:
Join Our Telegram Community - Aspire2Learn
Output: This is a Car
3. Platform-Independent -
Java follows "Write Once, Run Anywhere (WORA)".
Java code is compiled into bytecode, which runs on JVM
(Java Virtual Machine) on any OS (Windows, Linux, Mac).
Example:
4. Secure -
Join Our Telegram Community - Aspire2Learn
No explicit use of pointers, which prevents unauthorized
memory access.
Automatic memory management (Garbage Collection).
Bytecode verification to prevent malicious code
execution.
Example:
5. Robust (Strong & Error-Free) -
Java has automatic garbage collection to prevent
memory leaks.
It has exception handling to catch runtime errors.
Example: Exception Handling
Join Our Telegram Community - Aspire2Learn
Output: Cannot divide by zero!
6. Multithreaded -
Java supports multitasking by allowing multiple threads
to execute simultaneously.
It improves performance and efficiency.
Example: Creating a thread
Join Our Telegram Community - Aspire2Learn
Output: Thread is running...
7. Distributed -
Java can be used in distributed computing, allowing
applications to communicate over a network.
Supports RMI (Remote Method Invocation) and web
technologies like Servlets, JSP.
8. High Performance -
Java uses JIT (Just-In-Time Compiler) to convert
bytecode into machine code at runtime, making
execution faster.
Join Our Telegram Community - Aspire2Learn
9. Dynamic and Extensible -
Java supports dynamic memory allocation.
It allows importing external libraries (JAR files)
dynamically.
Example: Importing external packages
10. Portable -
Java applications do not depend on system architecture
(e.g., 32-bit or 64-bit).
The same Java program runs on different devices.
------------------------------------------------------------------------------
12. Explain the OOP feature of java programming language.
W[2017].
------------------------------------------------------------------------------
Test Your Knowledge Through
Aspire2Learn Online Quiz –
Join Our Telegram Community - Aspire2Learn
------------------- Aspire2Learn Online Quiz-------------------
------------------------------------------------------------------------------
Aspire2Learn Feedback Form –
- Your Voice, Our Priority
----------------------- Feedback Link -----------------------------
------------------------------------------------------------------------------
Join Our Telegram Community - Aspire2Learn
Join Our Telegram Community - Aspire2Learn
Join Our Telegram Community - Aspire2Learn