class 8 computer chapter 5

1. Java Keyword

👉 Definition:
Keywords are reserved words in Java that have special meaning to the compiler. They cannot be used as identifiers (like variable names).

👉 Example:
class, public, static, void, int, if, else

public class Example {
    public static void main(String[] args) {
        int number = 10; // 'int' is a keyword
        if(number > 5) { // 'if' is a keyword
            System.out.println("Number is greater than 5");
        }
    }
}

2. Java Token

👉 Definition:
A token is the smallest unit in a Java program.

👉 Types of Tokens:

  1. Keywords

  2. Identifiers

  3. Literals (numbers, characters, strings)

  4. Operators (+, -, *, /)

  5. Separators (;, {}, ())

👉 Example:

int a = 10; // Tokens: int, a, =, 10, ;

3. Java Data Types

👉 Definition:
Data types define the type of data a variable can store.

Two categories:

  1. Primitive Data Types (8 types)

    • byte → 1 byte (e.g. byte b = 100;)

    • short → 2 bytes (e.g. short s = 1000;)

    • int → 4 bytes (e.g. int n = 5000;)

    • long → 8 bytes (e.g. long l = 123456789L;)

    • float → 4 bytes (e.g. float f = 5.5f;)

    • double → 8 bytes (e.g. double d = 12.345;)

    • char → 2 bytes (e.g. char ch = 'A';)

    • boolean → 1 bit (e.g. boolean flag = true;)

  2. Non-Primitive Data Types

    • String → sequence of characters (e.g. String name = "Kiran";)

    • Arrays, Classes, Objects, Interfaces

👉 Example Code:

public class DataTypesExample {
    public static void main(String[] args) {
        int age = 20;
        double price = 99.99;
        char grade = 'A';
        boolean isPass = true;
        String name = "Kiran";

        System.out.println("Age: " + age);
        System.out.println("Price: " + price);
        System.out.println("Grade: " + grade);
        System.out.println("Pass: " + isPass);
        System.out.println("Name: " + name);
    }
}

4. Java Variable

👉 Definition:
A variable is a container that holds data in memory.

👉 Types of Variables:

  1. Local Variable → declared inside method

  2. Instance Variable → declared inside class but outside method

  3. Static Variable → declared with static keyword, shared by all objects

👉 Example Code:

public class VariableExample {
    int instanceVar = 50;       // Instance variable
    static String college = "Carmel"; // Static variable

    public void show() {
        int localVar = 10;      // Local variable
        System.out.println("Local Variable: " + localVar);
        System.out.println("Instance Variable: " + instanceVar);
        System.out.println("Static Variable: " + college);
    }

    public static void main(String[] args) {
        VariableExample obj = new VariableExample();
        obj.show();
    }
}

5. Java Operators

👉 Definition:
Operators are symbols used to perform operations on variables and values.

👉 Types of Operators:

  1. Arithmetic Operators: +, -, *, /, %

  2. Relational Operators: ==, !=, >, <, >=, <=

  3. Logical Operators: &&, ||, !

  4. Assignment Operators: =, +=, -=, *=, /=

  5. Unary Operators: ++, --, +, -

  6. Ternary Operator: ?:

👉 Example Code:

public class OperatorExample {
    public static void main(String[] args) {
        int a = 10, b = 5;

        // Arithmetic
        System.out.println("a + b = " + (a + b));

        // Relational
        System.out.println("a > b = " + (a > b));

        // Logical
        System.out.println((a > 5) && (b < 10));

        // Assignment
        a += 2;
        System.out.println("a after += : " + a);

        // Unary
        b++;
        System.out.println("b after increment: " + b);

        // Ternary
        int max = (a > b) ? a : b;
        System.out.println("Max = " + max);
    }
}

Q1. Which operator is used to assign a value to a variable?
a. Arithmetic
b. Assignment
c. Relational
d. Logical

✅ Answer: b. Assignment


Q2. Which of the following is not a feature of OOP?
a. Object
b. Image
c. Abstraction
d. Encapsulation

✅ Answer: b. Image


Q3. BlueJ is an ______ for the Java programming language.
a. IDE
b. JFR
c. MNV
d. ACX

✅ Answer: a. IDE




Multiple Choice Questions (MCQs)

Q4. ______ keyword does not return any value.
a. Void
b. Main
c. String
d. Int

✅ Answer: a. Void


Q5. ______ are the values that do not change during the execution of a program.
a. Constants
b. Keywords
c. Instances
d. Characters

✅ Answer: a. Constants


True (T) or False (F)

  1. Relational operators determine the relationship between two operands.
    ✅ True

  2. Variables are used to store the data value permanently.
    ✅ False (Variables store data temporarily in memory.)

  3. Java keywords are case-sensitive and should be typed in lowercase only.
    ✅ True

  4. Encapsulation ensures the users can access the data without proper authorisation.
    ✅ False (Encapsulation restricts unauthorized access.)

  5. Java is a high-level, object-oriented programming language.
    ✅ True


Fill in the blanks using the words in the box

(Encapsulation, Data Type, Compilation, OOP, Networking)

  1. OOP is a programming style that consists of class, functions and objects.

  2. The wrapping of data and functions in an object is known as Encapsulation.

  3. Networking enables us to make programs that allow us to play online games.

  4. Compilation is the process of converting the source code into machine code by the compiler.

  5. The type of value that a variable can hold is known as Data Type.


Subjective Question

Q1. What is object-oriented programming?
✅ Answer:
Object-Oriented Programming (OOP) is a programming approach that organizes a program using classes and objects. It focuses on concepts like encapsulation, inheritance, polymorphism, and abstraction to make programs more modular, reusable, and easy to understand.



Q2. Explain the basic structure of a Java program.

✅ Answer:
A Java program has the following parts:

  1. Class – Every program must have a class.

  2. Main Method – This is where the program starts running.

  3. Statements – Instructions written inside the main method.

Example:

class Hello {
   public static void main(String[] args) {
      System.out.println("Hello, World!");
   }
}

Q3. What is BlueJ? List its features.

✅ Answer:
BlueJ is a software (IDE) used to write and run Java programs.

Features:

  • Easy to use for beginners.

  • Shows classes and objects in a diagram.

  • Allows testing of methods directly.

  • Helpful in learning OOP concepts.


Q4. What is a variable? How is variable different from constant?

✅ Answer:
A variable is a name given to a memory location that stores a value. The value can change during the program.

A constant is a fixed value that does not change.

Example:

int age = 15;     // variable
final int PI = 3; // constant

Q5. What are operators? Differentiate between arithmetic and comparison operators.

✅ Answer:
Operators are special symbols used to perform actions on data.

  • Arithmetic Operators: Used for math ( + , - , * , / , % ).

  • Comparison Operators: Used to compare values ( == , != , > , < ).

Difference:

  • Arithmetic operators do calculations.

  • Comparison operators check conditions and give true or false.


👉

Comments

Popular posts from this blog

CLASS 8 COMPUTER

Class 5 computer chapter 4