Sunday, July 6, 2025

English basics example

 To identify parts of speech (noun, verb, adjective, etc.), examine a word’s **function and role** in a sentence. Here’s a step-by-step analysis using the example:  

**"Wow! She quickly gave her old book to me yesterday."**  


### **Line-by-Line Breakdown**  

1. **"Wow!"**  

   - **Interjection**: Expresses emotion ("Wow!" = surprise).  

   - *Clue*: Stands alone, ends with an exclamation mark.  


2. **"She"**  

   - **Pronoun**: Replaces a noun (refers to an unnamed female).  

   - *Clue*: Refers to a person without naming her.  


3. **"quickly"**  

   - **Adverb**: Modifies the verb "gave" (tells *how* she gave).  

   - *Clue*: Ends in *-ly* and answers "How?" or "In what manner?"  


4. **"gave"**  

   - **Verb**: Shows action (what "she" did).  

   - *Clue*: Describes an event (giving).  


5. **"her"**  

   - **Pronoun**: Shows possession (the book belongs to "her").  

   - *Clue*: Replaces a name (e.g., "Sarah’s book" → "her book").  


6. **"old"**  

   - **Adjective**: Describes the noun "book" (tells *what kind*).  

   - *Clue*: Answers "Which book?" or "What type?"  


7. **"book"**  

   - **Noun**: Names a thing (an object).  

   - *Clue*: Can be touched/seen (physical object).  


8. **"to"**  

   - **Preposition**: Links "gave" and "me" (shows direction/recipient).  

   - *Clue*: Indicates relationship (book given *to* whom?).  


9. **"me"**  

   - **Pronoun**: Replaces a noun (the receiver of the book).  

   - *Clue*: Refers to the speaker (object of the preposition "to").  


10. **"yesterday"**  

    - **Adverb**: Modifies "gave" (tells *when*).  

    - *Clue*: Answers "When?" (no *-ly* ending, but still an adverb).  




### **Key Questions to Identify Any Word**  

| **Part of Speech** | **Function** | **Key Questions** |  

|-------------------|-------------|-------------------|  

| **Noun** | Names a person/place/thing/idea | *Who? What?* (e.g., "book") |  

| **Verb** | Shows action/state | *What’s happening?* (e.g., "gave") |  

| **Adjective** | Describes a noun | *What kind? Which one? How many?* (e.g., "old" book) |  

| **Adverb** | Modifies verbs/adjectives/adverbs | *How? When? Where? To what extent?* (e.g., "quickly" gave) |  

| **Pronoun** | Replaces a noun | *Refers to who/what?* (e.g., "she", "me") |  

| **Preposition** | Links nouns to other words | *Shows relationship (time/place)* (e.g., "to" me) |  

| **Conjunction** | Connects words/clauses | *Joins ideas?* (e.g., "and", "but" – not in example) |  

| **Interjection** | Expresses emotion | *Sudden feeling?* (e.g., "Wow!") |  




### **Why Context Matters**  

- **Example**: "**Light** the **light**."  

  - First "light": **Verb** (action: to ignite).  

  - Second "light": **Noun** (object: a lamp).  

  - *Same word, different roles!*  


**Golden Rule**: Always check **what the word DOES** in the sentence! 

Day3-English(sentences -simple,compound,complex,paragraphs))

 What is a Simple Sentence?


A simple sentence has:


 One subject (who or what the sentence is about)


 One verb (action or state)


Optional: an object or extra info


 It expresses a complete idea



 Structure: Subject + Verb (+ Object/extra info)


Example 1:


Ravi eats.


🔹 Ravi = Subject (a noun – person)

🔹 eats = Verb (action)

This sentence makes complete sense


 Example 2:


The dog barks.


🔹 The dog = Subject

🔹 barks = Verb

One subject, one verb = simple sentence


Example 3:


She sings songs.


🔹 She = Subject (pronoun)

🔹 sings = Verb

🔹 songs = Object (noun – what she sings)

 Complete idea = Simple sentence


 Example 4:


Birds fly in the sky.


🔹 Birds = Subject

🔹 fly = Verb

🔹 in the sky = Prepositional phrase (extra info)

 Still a simple sentence – only one main clause


 Example 5:


I like ice cream.


 I = Subject (pronoun)

 like = Verb

 ice cream = Object (noun)

 It makes complete sense = Simple sentence


 Why are these called Simple Sentences?


Because:

Only one subject and one verb


No joining of two sentences


No dependent clauses (like "because", "when", etc.)


 SUMMARY of SIMPLE SENTENCES:


Sentence Subject Verb Object/Extra Info


Ravi eats.-- Ravi --eats

The dog barks.-- The dog-- barks

She sings songs. --She --sings --songs

Birds fly in the sky.-- Birds-- fly --in the sky (preposition)

I like ice cream. --I --like --ice cream


Now we move to PART 2: COMPOUND SENTENCES


 What is a Compound Sentence?


A compound sentence has:


 Two independent clauses (simple sentences)


 Joined by a conjunction like:

and, but, or, so, yet


 Structure: Simple Sentence + Conjunction + Simple Sentence


 Example 1:


Ravi plays cricket and Riya watches TV.


🔹 Ravi plays cricket = simple sentence 1

🔹 Riya watches TV = simple sentence 2

🔹 and = conjunction (joins both)

 This is a compound sentence.


 Example 2:


She was tired but she finished her work.


🔹 1st clause: She was tired

🔹 2nd clause: She finished her work

🔹 Joined by: but

 Two complete thoughts = compound sentence


 Example 3:


You can come with me or you can stay home.


🔹 Two full sentences:


You can come with me


You can stay home

🔹 Joined by: or

 Compound sentence


Why are these called Compound Sentences?


Because:


They contain two complete sentences


Joined using coordinating conjunctions (FANBOYS):



FANBOYS =


> For, And, Nor, But, Or, Yet, So


 SUMMARY of COMPOUND SENTENCES:


Sentence Clause 1 Conjunction Clause 2


Ravi plays cricket and Riya watches TV. Ravi plays cricket-- and ---Riya watches TV

She was tired but she finished her work. She was tired --but ---she finished her work

You can come or you can stay. You can come-- or --you can stay




-Now we move to PART 3: COMPLEX SENTENCES


 What is a Complex Sentence?


A complex sentence has:


One main (independent) clause


One or more dependent clauses


Uses words like: because, when, if, although, since

 Structure:

Main Clause + Dependent Clause

or

Dependent Clause + Main Clause


 Example 1:


I stayed home because it was raining.


🔹 Main clause: I stayed home

🔹 Dependent clause: because it was raining

 Complex sentence


 Example 2:


When the bell rang, the students left.


🔹 Dependent clause: When the bell rang

🔹 Main clause: the students left

 Complete meaning + a condition = Complex


 Example 3:


Although he was tired, he finished the project.


🔹 Dependent: Although he was tired

🔹 Main: he finished the project

 One complete idea with one supporting idea = Complex


 Why are these called Complex Sentences?


Because:


They mix one main idea and one supporting idea


The supporting part cannot stand alone


SUMMARY of COMPLEX SENTENCES:


Sentence Main Clause Dependent Clause


I stayed home because it was raining. --I stayed home--- because it was raining

When the bell rang, the students left. --the students left --When the bell rang

Although he was tired, he finished the project.---- he finished the project --Although he was tired


FINAL QUICK RECAP:


Type Structure Example


Simple --1 Subject + 1 Verb--- Ravi eats lunch.

Compound --2 Simple sentences + Conjunction ----She ran fast and he followed.

Complex-- 1 Main + 1 Dependent clause-- I went home because I was tired.


========================================


WHAT IS A PARAGRAPH?


And on what basis it is formed using everything we’ve learned — explained line by line, in a simple, clear, and easy manner.


Step 1: What is a Paragraph?


 A paragraph is a group of sentences that talk about one main idea.


It’s not just one sentence. It’s usually 3 to 6 sentences (sometimes more) that are connected and stay on one topic.


 Example Paragraph:


> My Pet Dog

I have a pet dog named Bruno.

He is very friendly and playful.

He loves to run in the garden and catch the ball.

I feed him every day and take care of him.

I love Bruno very much.


 This paragraph talks only about the dog.

All sentences are connected.

 It has a beginning, middle, and end.


Step 2: Parts of a Paragraph


We build a paragraph in 3 parts:


Part What it does Example


1 Topic Sentence Introduces the main idea I have a pet dog named Bruno.

2 Body Sentences Gives details, examples, reasons He is very friendly. He loves to run…

3 Conclusion Finishes the idea or adds a final thought I love Bruno very much.


 Step 3: On What Basis We Build Paragraphs (using Parts of Speech & Sentence Types)


Let’s now understand how we use everything learned:


 1. Nouns – to tell WHO or WHAT the paragraph is about


> e.g., dog, school, family, book, friend


 2. Pronouns – to avoid repeating nouns


> e.g., he, she, it, they


3. Verbs – to show actions


> e.g., runs, eats, plays, studies


 4. Adjectives – to describe nouns


> e.g., friendly dog, beautiful garden


 5. Adverbs – to describe actions


> e.g., runs quickly, speaks politely


 6. Prepositions – to show location/time


> e.g., in the park, at school, on the bed


 7. Conjunctions – to join ideas


> e.g., and, but, so, because


 8. Sentence types – mix of:


Simple sentences


Some compound sentences


Maybe one complex sentence


 Step-by-Step Paragraph Building (Line-by-Line)


Let’s build a paragraph line by line, using all the above.


Topic: My School



-Line 1: Start with a Topic Sentence


> I study at Green Valley School.


 Noun: school


Verb: study


Clear topic


Line 2: Describe your school


> It is a big and beautiful place.


 Pronoun: It

 Adjectives: big, beautiful


Line 3: Add action/details


> The teachers teach us well and help us in every subject.


 Verb: teach, help


 Conjunction: and


Simple + compound sentence


 Line 4: Add more activities


> We play games in the ground during break time.


Verb: play


Preposition: in the ground, during


Adverb: during break time


Line 5: Conclude with your feeling


> I love my school because it makes me feel happy.


 Conjunction: because


 Complex sentence


 Personal opinion


 Final Paragraph:


> My School

I study at Green Valley School.

It is a big and beautiful place.

The teachers teach us well and help us in every subject.

We play games in the ground during break time.

I love my school because it makes me feel happy.



 Summary: On What Basis Paragraphs Are Formed


Basis Used How


Topic Sentence Introduces main idea clearly

Parts of Speech Build meaningful and rich sentences

Sentence Types Use simple, compound, complex forms

Coherence & Unity All lines talk about the same topic

Flow (Line-by-line logic) Each sentence adds to the previous


I'll give you topics — you write a paragraph:


 Topics:


1. My Best Friend



2. A Day at the Park



3. My Favorite Festival



4. A Rainy Day



1. Paragraph: My Best Friend (Line-by-line)


 Line 1 (Topic sentence):

My best friend's name is Arjun.
Introduces the topic (noun: Arjun)


 Line 2 (Description):

He is very smart, kind, and helpful.
 Adjectives: smart, kind, helpful


 Line 3 (Activities together):

We play cricket every evening and also study together.
Verb: play, study
Conjunction: and
Adverb: every evening


 Line 4 (Helpful nature):

When I have a doubt, he explains it to me patiently.

Complex sentence
Adverb: patiently
Clause: When I have a doubt


 Line 5 (Conclusion):

I feel lucky to have Arjun as my best friend.

 Personal opinion, final line


Final Paragraph:

> My Best Friend
My best friend's name is Arjun.
He is very smart, kind, and helpful.
We play cricket every evening and also study together.
When I have a doubt, he explains it to me patiently.
I feel lucky to have Arjun as my best friend.




2. Paragraph: A Day at the Park (Line-by-line)


Line 1 (Topic):

Last Sunday, I went to the park with my family.
Nouns: Sunday, park, family
Verb: went


 Line 2 (Description):

The weather was pleasant and the park was full of people.
Adjective: pleasant
 Compound sentence: joined with and


 Line 3 (What you did):

I played on the swings, ran on the grass, and clicked pictures.
Verb list: played, ran, clicked


---

🔹 Line 4 (Feelings):

I felt so happy because I love spending time outdoors.
 Complex sentence using "because"
Verb: love
Adverb: happily (implied)


Line 5 (Conclusion):

That day at the park was truly memorable.
Closing line with opinion


 Final Paragraph:

> A Day at the Park
Last Sunday, I went to the park with my family.
The weather was pleasant and the park was full of people.
I played on the swings, ran on the grass, and clicked pictures.
I felt so happy because I love spending time outdoors.
That day at the park was truly memorable.



 3. Paragraph: My Favorite Festival (Line-by-line)


 Line 1 (Topic):

My favorite festival is Diwali.
 Clear start: introduces the main idea


 Line 2 (Description):

It is the festival of lights and happiness.
 Noun: lights
Abstract noun: happiness


 Line 3 (Activities):

We clean our house, decorate with lamps, and wear new clothes.
Verbs: clean, decorate, wear
 Adjective: new


 Line 4 (Celebration):

At night, we light diyas and burst crackers joyfully.
Preposition: at night
Adverb: joyfully


- Line 5 (Conclusion):

I enjoy Diwali because it brings joy and togetherness.
Complex sentence: "because"
Noun: joy, togetherness


 Final Paragraph:

> My Favorite Festival
My favorite festival is Diwali.
It is the festival of lights and happiness.
We clean our house, decorate with lamps, and wear new clothes.
At night, we light diyas and burst crackers joyfully.
I enjoy Diwali because it brings joy and togetherness.




 4. Paragraph: A Rainy Day (Line-by-line)


 Line 1 (Topic):

Yesterday, it rained heavily in our town.
 Verb: rained
Adverb: heavily


Line 2 (Atmosphere):

The sky was dark and full of clouds.
 Adjectives: dark, full


 Line 3 (Activities):

I stayed inside the house and watched cartoons with hot snacks.
 Compound sentence
Noun: cartoons, snacks


 Line 4 (Observation):

The children were playing in the puddles outside.
Prepositional phrase: in the puddles


 Line 5 (Conclusion):

Even though I stayed indoors, I really enjoyed the rainy day.
 Complex sentence using Even though


Final Paragraph:

> A Rainy Day
Yesterday, it rained heavily in our town.
The sky was dark and full of clouds.
I stayed inside the house and watched cartoons with hot snacks.
The children were playing in the puddles outside.
Even though I stayed indoors, I really enjoyed the rainy day.


 FINAL RECAP: Paragraph Formation Basis

Step What it Includes

Topic Sentence Starts with clear idea (noun + verb)
Body Sentences Use adjectives, adverbs, prepositions
Mixed Sentences--- Include simple, compound, and complex
Parts of Speech ---All 8 types: noun, verb, adjective, etc.
Logical Flow ----One idea connected line by line
Conclusion ---Finishes with feeling or final opinion
==========================================
BUILD SENTENCES USING THE WORD BANK

🔸 Word Bank:

Nouns Verbs Adjectives Adverbs  Prepositions

boy --runs-- tall --fast --on
girl reads happy slowly in
teacher sings clever loudly under
dog writes little quickly near

===≠=====================================
VERB + ADVERB PAIR PRACTICE

Let’s practice combining verbs with suitable adverbs.

🔹 Match the pairs:

Verb Adverb Full Sentence Example

run --quickly --He runs quickly.
speak --politely --She speaks politely.
write --neatly-- Riya writes neatly.
cry --loudly --The baby cries loudly.
walk --slowly-- Grandma walks slowly.

====≠===================================
What is an Adjective?

An adjective is a word that:

> Describes or gives more information about a noun (person, place, thing).



It tells us:

What kind? (big, beautiful, red)

How many? (two, many, few)

Which one? (this, that, these)



 Step 2: What is a Noun?

A noun is a name of a person, place, thing, or idea.

Example nouns:

boy, dog, school, house, car



-Step 3: What do "big" and "beautiful" do?

Let’s look at this sentence:

> It is a big and beautiful house.



Now break it:

house = noun (thing)

big = tells size of the house

beautiful = tells appearance or quality of the house


So,

"big" describes the noun → adjective

"beautiful" describes the noun → adjective



 Step 4: Real Examples:

Sentence Noun Adjective(s) Why it's an adjective

I live in a big house. house big tells the size of the house
She has a beautiful smile. smile beautiful tells the quality of the smile
They bought a red car. car -red -tells the color of the car
He is a smart boy. boy smart tells the nature of the boy
We ate two mangoes. mangoes- two-- tells the quantity of mangoes


Easy Trick to Know if It's an Adjective:

Ask yourself:

> "Is this word describing a noun?"



If yes → It's an adjective

If it tells size, color, shape, quality, number → It's an adjective



 Final Test:

Let’s test “big” and “beautiful”:

Word What does it describe? Describes a noun? Is it an adjective?

big --size --yes (house) -- Yes
beautiful --appearance/quality --yes (house/smile) --Yes



In Short:

Word Part of Speech Why?

big Adjective Describes the size of a noun
beautiful Adjective Describes the quality of a noun


=========================================

Day-2 english (parts of speech)

 PART 1: WHAT ARE PARTS OF SPEECH?


In English, every word belongs to a category. These categories are called parts of speech. There are 8 main parts of speech:


No. -->Part of Speech --->Role / Job


1 -->Noun -->Names a person, place, thing, or idea

2 -->Pronoun -->Replaces a noun

3 --->Verb --->Shows action or state

4 --- >Adjective---> Describes a noun/pronoun

5 --->Adverb --->Describes a verb/adjective/another adverb

6 -->Preposition --->Shows the relationship between a noun and another word

7 ---->Conjunction --->Connects words, phrases, or clauses

8 --->Interjection --->Expresses emotions or sudden feelings


 PART 2: HOW TO IDENTIFY PARTS OF SPEECH (WITH EXAMPLES)


Let's take this sample sentence:


> Wow! She quickly eats a tasty apple under the tree and smiles.




Let’s break it line by line:


Line 1: “Wow!”


 It expresses sudden feeling.


 Interjection.


 Line 2: “She”


 Refers to a girl/woman but doesn’t name her.


 Pronoun (replaces a noun like "Riya").



 Line 3: “quickly”


 Describes how she eats.


 Adverb (modifies the verb "eats").



 Line 4: “eats”


 Shows action.


 Verb.


 Line 5: “a tasty apple”


“apple” is a thing  = Noun


“tasty” describes “apple” = Adjective


“a” is an article, but acts as a determiner with noun.


 Line 6: “under the tree”


“tree” = place = Noun


“under” = shows position = Preposition


“the” = article/determiner


 Line 7: “and”


Joins two actions: “eats” and “smiles”


Conjunction 


 8: “smiles”


Shows an action.


Verb


Summary of the sentence:


Word --->Part of Speech


Wow --->Interjection

She --->Pronoun

quickly --->Adverb

eats --->Verb

a --->Article (determiner)

tasty --->Adjective

apple---> Noun

under---> Preposition

the --->Article

tree --->Noun

and ---->Conjunction

smiles---> Verb


 PART 3: HOW TO FORM SENTENCES (Structure)


Basic sentence structure:


Subject + Verb + Object + (extra info)

 Example 1:


> Ravi plays cricket.


Ravi = Subject (Noun)


plays = Verb


cricket = Object (Noun)


Example 2:


> The girl sings beautifully on stage.


“The girl” = Subject (Noun phrase)


“sings” = Verb


“beautifully” = Adverb


“on stage” = Prepositional phrase


FORMULA TO FORM SENTENCES


Step --->What to add ---->Example


1 --->Start with a subject (noun/pronoun) --->He, Riya, The cat

2 -->Add a verb --->runs, eats, dances

3 -->Add an object or complement-->a mango, loudly, in the park

4 -->Add modifiers (adjective, adverb, preposition)--->quickly, under the table


Sentence:


> The smart boy reads a book silently.

Breakdown:

The smart boy = Noun phrase (with adjective)

reads = Verb

a book = Object

silently = Adverb


Final Tips to Identify Part of Speech


Clue--->Look for…---->Example


 Who/what? --->Noun -->Dog, City

Replaces noun?---> Pronoun -->He, They

Action or state?--> Verb--> Run, Is

Describes noun?---> Adjective -->Big, Blue

 How, when, where? -->Adverb -- Quickly, Today

Shows place/time?--  Preposition--> Under, Before

 Joins? -->Conjunction -->And, But

Emotion word?---> Interjection---> Oh!, Wow!

========================================

WHAT IS A SENTENCE?


A sentence is a group of words that:


1. Makes complete sense


2. Starts with a capital letter


3. Ends with a punctuation mark (like ., ?, or !)


 A sentence must have at least:


 Subject (who/what the sentence is about)


 Verb (what the subject does or is)


 Example 1:


Ravi eats.

Ravi = Subject

 eats = Verb

It makes sense, so it is a sentence.

 Example 2:

The dog barks.

 The dog = Subject

 barks = Verb

Complete sentence.


 Not a sentence:

Running fast

This is just a phrase.

It doesn’t tell us who is running or why — so it's not a sentence.


BASIC SENTENCE STRUCTURE


The most basic sentence follows this structure:


Subject + Verb + Object


 Sentence Building Formula


Step---> What to use--->Example


1--> Subject (Noun/Pronoun)--> Riya, He, The boy

2--> Verb (Action word)--> plays, runs, eats

3--> Object (Thing receiving the action) -->cricket, food, guitar


Example:


> Riya plays guitar.

 Riya = Subject

 plays = Verb

guitar = Object

Complete sentence

 TYPES OF WORDS IN A SENTENCE (Parts of Speech) — with SIMPLE EXAMPLES

Let’s now go over each part of speech with easy examples.

1) Noun (Name of person, place, thing, idea)

Examples:

Ravi is a student.

I live in Hyderabad.

She has a pen.

Clue: Can you touch it or is it a name? It’s probably a noun.


2) Pronoun (Replaces a noun)


 Examples:


He is smart. (instead of "Ravi")


She sings well.


They are friends.


Clue: If you use it instead of a name, it’s a pronoun.


3) Verb (Shows action or state)


 Examples:


Birds fly.


She is happy.


I write letters.


 Clue: Ask: “What is the subject doing?”


4) Adjective (Describes a noun)


 Examples:


She has a beautiful dress.


It’s a big house.


The food is hot.

 Clue: Ask: “What kind of...?”

5) Adverb (Describes verb/adjective/another adverb)

 Examples:

He runs fast. (describes verb)

She sings very well. (modifies another adverb)

It is really hot. (modifies adjective)

 Clue: Ask: “How?”, “When?”, “Where?”, “To what extent?”

6) Preposition (Shows relation of place/time/direction)

 Examples:

The cat is under the table.

He arrived after lunch.

She lives near the market.

 Clue: Shows where, when, direction.


7) Conjunction (Joins words/sentences)


 Examples:


I like tea and coffee.


She is sad but strong.


Study hard or fail.


Clue: Joins two things.


8) Interjection (Sudden feeling or emotion)

 Examples:


Wow! You did it.


Oh no! I forgot my book.


Yay! It's a holiday.



Clue: If it shows feeling and stands alone, it’s an interjection.


HOW TO FORM SENTENCES (With More Examples)

 Sentence 1:


The boy runs.


Noun: boy


Verb: runs

 Full sentence: Who? The boy. What action? runs.


 Sentence 2:


She sings beautifully.


Pronoun: she


Verb: sings


Adverb: beautifully

 How does she sing? beautifully

 Sentence 3:


Ravi eats a tasty mango.


Noun: Ravi


Verb: eats


Object: mango


Adjective: tasty

What does Ravi eat? a tasty mango


 Sentence 4:


The dog sleeps under the table.


Subject: The dog


Verb: sleeps


Prepositional Phrase: under the table

Where? under the table


Sentence 5:


Wow! That’s amazing.


Interjection: Wow!


Sentence: That’s amazing

 Expressing feeling



Mini Exercise (Try to Identify the Parts of Speech):


> The little girl danced gracefully at the party.


Breakdown:


The little girl = Noun + Adjective


danced = Verb


gracefully = Adverb


at the party = Prepositional Phrase


 Full sentence structure!


Sentence Part:


"The little girl"


We will now identify each word:



 1. The


This is an article (also called a determiner)


It helps define the noun.


Example: The boy, a cat, an apple



 2. little


This is an adjective


It describes what kind of girl.


It gives more information about the noun (size, color, shape, etc.).


 Adjective = describing word


 So, "little" is an adjective.


 3. girl


This is a noun


It is the name of a person (a female child)


Noun = person, place, thing, or idea


 So, "girl" is a noun.


 Final Breakdown:


Word--- Part of Speech


The --Article

little ---Adjective

girl ---Noun


 How to remember easily?


> Adjective + Noun = Described Thing


Like:


big house → big = adjective, house = noun


red apple → red = adjective, apple = noun


happy child → happy = adjective, child = noun


little girl → little = adjective, girl = noun


-->What is a Verb?


A verb shows action or state.


Examples:


run


eat


sing


is, are, was (state of being)



What is an Adverb?


An adverb describes/modifies:


a verb


an adjective


or another adverb



It tells how, when, where, how often, or to what extent an action happens.


 Common adverb endings: -ly

(E.g., quickly, slowly, beautifully, happily)


 Let's break your question into two parts:


 1. Why is "beautifully" an adverb?


Let’s look at the sentence:


> She sings beautifully.


sings = verb (action)


beautifully = tells how she sings

So, beautifully is describing the verb "sings" → That makes it an adverb.


 Clue: If a word tells how something is done → it’s usually an adverb


 2. Why is "quickly" not a verb?


Let’s use "quickly" in a sentence:


> He runs quickly.

runs = verb (action)

quickly = tells how he runs

So, quickly is also an adverb, not a verb.

Even though “quickly” sounds like an action, it’s not doing the action — it is describing the verb (runs).

 

Final Comparison:


Word--- Part of Speech---- Reason


beautifully ----Adverb---- Describes how someone sings (a verb)

quickly -----Adverb---- Describes how someone runs (a verb)

run, sing---- Verb ----Show the actual action


 Tip to Identify:


If the word tells how the action happens, and ends in -ly, it's almost always an adverb.


 Examples to Practice:


Sentence---> Verb---> Adverb


She dances gracefully.--->dances--->gracefully

They work quickly.--->work--->quickly

He speaks politely.--->speaks--->politely

I eat slowly.--- >eat--->slowly






Day1 - English basics

 

1)Parts of Speech::

These are the building blocks of grammar. Here’s a quick overview with examples:

  • Noun: Names a person, place, or thing. Example: “The dog is barking.”

  • Verb: Shows an action or state. Example: “She runs every morning.”

  • Adjective: Describes a noun. Example: “It’s a beautiful day.”

  • Adverb: Describes a verb, adjective, or another adverb. Example: “He speaks softly.”

  • Pronoun: Replaces a noun. Example: “They are playing football.”

  • Preposition: Shows position or relationship. Example: “The book is on the table.”

  • Conjunction: Connects words or sentences. Example: “I like tea and coffee.”

  • Interjection: Expresses emotion. Example: “Wow! That’s amazing.”

2)Sentence Structure::

Sentences are made up of subjects, verbs, and objects. Let’s look at the types:

  • Simple Sentence: One idea. Example: “The cat sleeps.”

  • Compound Sentence: Two ideas joined by a conjunction. Example: “The cat sleeps, and the dog barks.”

  • Complex Sentence: One main idea + extra detail. Example: “I smiled because I was happy.”

3)Tenses (Simple Forms)

  • Present Simple: For regular actions or facts. Example: “I play football every day.”

  • Past Simple: For completed actions in the past. Example: “I played football yesterday.”

  • Future Simple: For actions that will happen. Example: “I will play football tomorrow.”

4)Articles

Articles are small but important words that come before nouns.

  • A: Use before words starting with consonant sounds. Example: “I saw a tiger.”

  • An: Use before words starting with vowel sounds. Example: “She wants an apple.”

  • The: Use for something specific. Example: “The sun is shining.”

5)Basic Prepositions

Prepositions show the relationship between words.

  • In: Inside something. Example: “The pen is in the box.”

  • On: On top of something. Example: “The book is on the table.”

  • At: A specific location. Example: “She is at the door.”

6)Common Verbs

These are the most frequently used verbs in English:

  • Be: am/is/are Example: “She is happy.”

  • Have: possession Example: “I have a car.”

  • Do: actions Example: “I do my homework.”

  • Go: movement Example: “They go to school.”

  • Make: create Example: “He makes delicious food.”

Writing Exercise::

Write 5 sentences using different parts of speech. For example:

  1. The dog (noun) is running (verb) in the park (noun).

  2. She quickly (adverb) finished her homework (noun).

  3. Wow! (interjection) That’s a beautiful (adjective) painting.

  4. I like tea and (conjunction) coffee.

  5. The book is on (preposition) the table.

How to learn basics to advanced grammar in english

 How to learn basics to advanced grammar in english::


Step 1: Build a Strong Foundation (Basics)


Start with the essential building blocks:


- Parts of Speech: Nouns, verbs, adjectives, adverbs, pronouns, prepositions, conjunctions, interjections


- Sentence Structure: Subject + verb + object; simple, compound, and complex sentences


- Tenses: Present, past, and future (simple forms)


- Articles: A, an, the


- Basic Prepositions: In, on, at, from, to


- Common Verbs: Be, have, do, go, make


 Step 2: Intermediate Grammar::


Once you're comfortable with the basics, move on to:


- Verb Tenses: Perfect and continuous forms (e.g., present perfect, past continuous)


- Modal Verbs: Can, could, should, would, may, might


- Conditionals: Zero, first, second, third conditionals


- Passive Voice: How to form and use it


- Reported Speech: Changing direct to indirect speech


- Comparatives & Superlatives: Better, best, more, most


Step 3: Advanced Grammar


Now you're ready to refine your skills:

- Gerunds & Infinitives: “Swimming is fun” vs. “To swim is fun”


- Relative Clauses: Who, which, that


- Subjunctive Mood: “If I were you…”


- Sentence Inversion: “Never have I seen such beauty” 


- Causative Verbs: “She had her car washed”


- Advanced Connectors: Nevertheless, although, in spite of



Tips to Learn Effectively::


 Read daily: Books, articles, or even subtitles in English


 Write regularly: Journals, essays, or social media posts


 Speak and listen: Practice with friends or use language apps


 Practice exercises: Grammar quizzes and worksheets

Saturday, July 5, 2025

Coverletter,Email Application model for the post of Software engineer

 **Formal Cover Letter (PDF Attachment)**  

*(Save as: `uday_CoverLetter_SoftwareEngineer_Infosys.pdf`)*  

```  

Uday 

123 Tech Street • San Francisco, CA 94105  

(555) 123-4567 • uday@gmail.com  

July 5, 2025  


Hiring Manager  

Infosys Solutions  

456 Innovation Drive  

San Jose, CA 95134  


Dear Hiring Manager,  


I am writing to apply for the position of **Software Engineer** at **Infosys Solutions**, as advertised on Social media u. With **4 years of experience in full-stack JavaScript development**, I am confident in my ability to contribute to your engineering team’s success in creating AI-driven healthcare solutions.  


At Innovate Labs, I designed a React.js customer dashboard that **improved data processing speed by 35%** and **boosted user engagement by 28%**. My expertise includes developing RESTful APIs with Node.js/Express, cloud deployment on AWS (Lambda/S3), and database architecture with MongoDB/PostgreSQL – all aligned with your technical requirements.  


I am excited about the opportunity to bring my background in scalable web applications to Infosys innovative environment. I’ve attached my resume detailing additional projects and qualifications for your review.  


Thank you for your time and consideration.  


Sincerely,  

Uday 


=========================================


**Email Application**  

**Subject:** Application for Software Engineer Position - uday 

**To:** HR Manager, TechNova Solutions (hr@technovasolutions.com)  

**Attachments:**  

1. `uday_CoverLetter_SoftwareEngineer_TechNova.pdf`  

2. `uday_Resume_SoftwareEngineer_TechNova.pdf`  


**Email Body:**  

```  

Dear Hiring Manager,  


Please accept my application for the Software Engineer position at Infosys Solutions. I have attached:  

1. My formal cover letter detailing my qualifications  

2. My resume highlighting technical skills and achievements  


With 4 years' experience in JavaScript full-stack development (React/Node.js) and cloud solutions, I’m confident I can contribute to your team’s work in healthcare technology innovation.  


Thank you for your consideration. I look forward to discussing how my skills align with TechNova’s goals.  


Sincerely,  

Uday 

(555) 123-4567 | uday@gmail.com  

LinkedIn: linkedin.com/in/uday

GitHub: github.com/uday


Applying for the post of Software engineer

 *Email Subject*

`Application for Software Engineer Position - Bhaskar 


 *Email Body*

To: HR Manager, Infotech Solutions  

From: bhaskar (bhasp335@gmail.com)  

Date: July 5, 2025  


Dear Hiring Manager,


I am writing to express my enthusiastic interest in the **Software Engineer position** at **Infotech Solutions**, as advertised on Social media. With 4 years of experience in **full-stack JavaScript development** (React.js, Node.js) and a proven ability to deliver scalable solutions, I am confident I can contribute significantly to your engineering team’s success.  


In my previous role at **Innovate Labs**, I designed and optimized a customer analytics dashboard using **React.js**, which **improved data processing speed by 35%** and **boosted user engagement by 28%**. I also developed RESTful APIs with **Node.js/Express**, integrated AWS cloud services (Lambda, S3), and collaborated using Agile methodologies to ensure rapid deployment.  


I am particularly drawn to  Infotech's pioneering work in **AI-driven healthcare solutions** and your commitment to sustainable technology. I am eager to apply my skills in database architecture (MongoDB, PostgreSQL), cloud integration, and problem-solving to advance your mission of transforming patient care.  


Please find my detailed resume attached for further information about my technical competencies, projects, and professional background. I welcome the opportunity to discuss how my expertise aligns with Infotech’s goals during an interview.  


Thank you for considering my application. I look forward to your response.  


Sincerely,

Bhaskar 

 phone number 

bhasp335@gmail.com

Friday, July 4, 2025

Today's exam answers

 VERBAL AND TECHNICAL SECTION 

SOLUTIONS

Passage 1

1) 1. stay

2) 2. by

3) 3. glancing

4) 4. also

5) 5. tired

6) 6. along with

7) 7. by

8) 8. returned

9) 9. As

10) 10. Worth


Passage 2

1) A. Blew

2) B. Drops

3) C. From

4) D. Minding

5) C. Better

6) D. Sun

7) B. Feeling

8) B. Where

9) C. Practised

10) D. For


III. Change to Passive Voice

11) The question was answered by Julie.

12) Many tricks had been learned by the dolphins.

13) The house will be built by the construction crew in five months.


IV. Will/Would Sentences

14) 14) would

15) 15) would

16) 16) will

17) 17) would


V. Tenses

18) 18) frequently drives

19) 19) usually stay

20) 20) already played

21) 21) slowly dropped

22) 22) will meet

23) 23) are looking



VI. Synonyms

24) C. Clear

25) D. Aesthetic

26) B. Flexible

27) C. To come forth in a flood

VII. Antonyms

28) A. Absolute freedom

29) A. Make greater

30) D. Pious

Today's exam answers

 1) Two students appeared at an exam. One scored 9 more and got 56% of total marks.


Let one be x, other is x+9

Sum = 2x + 9

56% of total = x+9

→ (56/100)(2x+9) = x+9

Solve: x = 33, x+9 = 42


 Answer: C) 42, 33


2) Population increase from 1,75,000 to 2,62,500 in 10 years


Use compound interest formula:


\text{Rate} = \left(\frac{262500}{175000}\right)^{1/10} - 1 \approx 4.37\%


 Answer: A) 4.37%


3) 40% of a number = 352


Let number = x

40% of x = 352 ⇒ x = (352 × 100)/40 = 880


 Answer: D) 880


4) 1st = 40% more than 3rd, 2nd = 30% less than 3rd


Let 3rd = x

1st = 1.4x, 2nd = 0.7x

% of 2nd on 1st = (0.7x / 1.4x) × 100 = 50%


 Answer: B) 50%


5) Unit digit of (156)^376 + (234)^458 + (651)^456 + (789)^2


6^n = 6


4^even = 6


1^n = 1


9^even = 1

Add unit digits: 6 + 6 + 1 + 1 = 14 ⇒ Unit digit = 4



 Answer: A) 4


6) Unit digit of (150)^376 + (237)^458 + (651)^456 + (789)^2


0, 9, 1, 1 ⇒ Total = 11 ⇒ Unit digit = 1



 Answer: B) 1


7) Unit digit of (1533)^78 * (236)^458 * (652)^456 * (781)^892


3^n cycle: ends in 9


6^n = 6


2^even = 6


1^n = 1

⇒ 9 × 6 × 6 × 1 = ends in 4



 Answer: A) 4



8) Same as Q7 ⇒ Unit digit = 4


 Answer: A) 4


9) Last 2 digits of (456785)^568


Power of 85 always ends in 25


 Answer: B) 25


10) Last 2 digits of (456741)^568


Focus on last 2 digits of 41^n

Cycle is: 41 → 81 → 21 → 61 → 01

568 mod 5 = 3 ⇒ 3rd value = 21


 Answer: C) 21



11) Last 2 digits of (4599)^568


99^even power = ends in 01


 Answer: B) 01


12) Last 2 digits of (4547)^568


47^n → cycle gives last 2 digits = 41


 Answer: D) 41



13) CP of 20 = SP of x. Profit = 25%


⇒ CP = SP ⇒ CP × (1 + 25/100) = x

x = 16


 Answer: B) 16


14) CP = Rs. 1400, loss 15% ⇒ SP = 85% of 1400 = Rs. 1190


Answer: C) Rs. 1190


15) Buy 6 for Rs.5, Sell 5 for Rs.6 ⇒ Gain%


CP of 1 = 5/6 = 0.833..., SP = 6/5 = 1.2

Gain = (1.2 - 0.833)/0.833 × 100 ≈ 44%


Answer: D) 44%


16) 17 balls sold at Rs. 720 with loss of 5 balls’ cost


⇒ SP of 17 = CP of 12

So, CP of 1 ball = 720 / 12 = 60


 Answer: D) Rs. 60


17) Reflex angle at 3:50


Minute = 50 × 6 = 300°

Hour = 3×30 + (50/60)×30 = 115°

Angle = |115 – 300| = 185°

Reflex = 360 – 185 = 175°


 Answer: C) 175 degrees


18) Coincide between 12 and 1 ⇒ 1 hr 5 5/11 min


 Answer: A) 1 hr 5 5/11 min


19) Mirror image of 16:45 = 12:00 – 4:45 = 7:15 PM


 Answer: A) 7:15pm


20) Clock hands coincide 11 times in 12 hrs ⇒ 22 times/day


 Answer: C) 22 times


21) August 15, 1947 – Which day of week?


You can remember or verify via calendar:

15 August 1947 = Friday


 Answer: B) Friday


22) Next leap year after 1796


1800 is not leap (century not divisible by 400)

Next = 1804


 Answer: C) 1804


23) 3rd Thursday of October 2012


1st Oct 2012 = Monday

So 1st Thursday = 4th

3rd Thursday = 18th


 Answer: A) October 18th


24) Pair of prime numbers


C) 83 and 73 are both prime.


 Answer: C) 83,73


25) Find leap year


Only 2800 is divisible by 400 → leap year.


 Answer: B) 2800


26) Find x if 1847x96 divisible by 8


Last 3 digits = x96

Try x = 2 ⇒ 296 ÷ 8 = 37 


 Answer: A) 2


27) Pair of prime numbers


C) 197 and 223 are both prime


 Answer: C) 197,223


28) Time between 3 and 4 when hands are opposite


Use formula:

Time = (60/11)(H ± 6)

= (60/11)(3 ± 6) = (60/11)(9) = 49 1/11 min

→ 3:49 1/11


 Answer: B) 3hr 49 1/11 min


29) 52nd leap year after 1980


Leap year every 4 years ⇒ 52×4 = 208 years

⇒ 1980 + 208 = 2188


Answer: B) 2188


30) A:B = 2:3, B:C = 5:6


Make B common:


A:B = 10:15


B:C = 15:18 ⇒ A:B:C = 10:15:18



 Answer: A) 10:15:21


31) Bag of coins in 4:3:5 ratio; Total Rs.350


Let coins = 4x, 3x, 5x

Values = 4x×1 + 3x×2 + 5x×5 = 35x

35x = 350 ⇒ x = 10

So coins = 40, 30, 50


Answer: B) 40,30,50


32) A:B Income = 13:8, B:C Exp = 16:5; 1/4 saved


A's saving = 13×1/4 = 3.25

B's = 8×1/4 = 2

⇒ 3.25:2 = 13:8


Answer: A) 13:8


33) A:B = 4:5, B:C = 10:3, C:D = 6:5


Convert to same base:


A:B = 8:10


B:C = 10:3


C:D = 6:5

Combine all → A:D = 16:5 (None)



 Answer: D) None


34) A:B = 2:3, B:C = 4:5, C:A = 4:5


Let’s find total A+B = x

⇒ A = 7, B = 30 (from given ratio)


 Answer: A) 7:30


35) Cost 15, 20 in 2:3, mix = 16.5


Use allegation rule:

(20 – 16.5):(16.5 – 15) = 3.5:1.5 = 7:3


Answer: A) 7:3


36) 40L milk, 4L removed 2 times


Use formula:

Milk left = V × (1 - r/V)^n

= 40 × (0.9)^2 = 32.4 ≈ 32L


 Answer: C) 32L


37) Cost of rice mixed in 2:3 ratio


(15×2 + 20×3) / 5 = (30 + 60)/5 = 18


Answer: A) Rs. 18


38) Number series: 216,125,64,27,8,...


This is cube pattern in reverse:

6³, 5³, 4³... ⇒ next is 1³ = 1


 Answer: D) 1


39) Series: 100, 98, 95, 90, 83, 72, ?


Subtracting primes:

–2, –3, –5, –7, –11, –13 ⇒ next is –17

72 – 13 = 59


 Answer: C) 59


40) Next number in the series? 100,98,95,90,83,72,?


Answer from Q39 → 59


 Answer: C) 59

Today's exam program

 Java::


 import java.util.*;


public class KennyCoolDrinks {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);


        int n = sc.nextInt(); // total number of shops

        int[] prices = new int[n];


        // read prices of each shop

        for (int i = 0; i < n; i++) {

            prices[i] = sc.nextInt();

        }


        int t = sc.nextInt(); // number of test cases


        for (int testCase = 0; testCase < t; testCase++) {

            int m = sc.nextInt(); // number of days (not used)

            int p = sc.nextInt(); // money per day


            int count = 0;


            // check each shop

            for (int i = 0; i < n; i++) {

                if (prices[i] <= p) {

                    count++;

                }

            }


            // print: test case number and count

            System.out.print(testCase + " " + count + " ");

        }

    }

}



In c language::


#include <stdio.h>


int main() {

    int n;

    scanf("%d", &n); // total shops


    int prices[n];

    for (int i = 0; i < n; i++) {

        scanf("%d", &prices[i]); // shop prices

    }


    int t;

    scanf("%d", &t); // number of test cases


    for (int testCase = 0; testCase < t; testCase++) {

        int m, p;

        scanf("%d %d", &m, &p); // m is unused, p is money per day


        int count = 0;

        for (int i = 0; i < n; i++) {

            if (prices[i] <= p) {

                count++;

            }

        }


        printf("%d %d ", testCase, count);

    }


    return 0;

}


 Concepts used in above program::


Array--> A list of values To store the prices of Coca Cola at each shop


Loop (for)--> Repeat something multiple times To go through each shop and check if Kenny can afford it


If Condition---> Decide whether something is true or false To check: if (rate ≤ p)


Input Reading--> Getting values from user or keyboard Use Scanner in Java or scanf in C


Output --->Showing result to the user Use System.out.print in Java or printf in C


 Program Flow:


1) Read total shops and prices


2) For each test case:


Read money Kenny has per day


Check how many shops have prices ≤ Kenny's money


Print: test case number and how many shops he can afford


 Final Output :


0 4 1 5





Kenny = Customer


Shop = Vendor


Rate = Cost of service or product


This program filters which vendors fall under the customer’s daily budget

Today's exam answers

 Answers for today's test:::

======================


Method with if condition


public void test(int x) {

  int odd = 1;

  if (odd) {

    System.out.println("odd");

  } else {

    System.out.println("even");

  }

}



Problem:


if (odd)


 This is invalid in Java!


Why?



Java does NOT allow non-boolean conditions in if


Unlike C/C++, where:


if (1) → true

if (0) → false


In Java, the if condition must be a boolean expression:


if (true)    yes

if (false)   yes

if (x > 5)   yes

if (odd)     false because odd is `int`, not boolean



 Correct version:


public void test(int x) {

  int odd = 1;

  if (odd == 1) {

    System.out.println("odd");

  } else {

    System.out.println("even");

  }

}



Program Flow (After Fix):


1. odd = 1



2. Check: odd == 1 → yes true



3. So it prints:




odd


==============================================



 What is a Default Constructor?


public class Test { }


This is a simple class with no code.



 What is a Default Constructor?


If no constructor is defined, Java automatically provides a:


public Test() { }


Called the default constructor.


 Important Points:


It takes no arguments


It is added by compiler


It does nothing internally


As soon as you create any constructor manually, default is not provided




 Example Use:


Test obj = new Test();  //  This calls the default constructor


=========================================


I. public int a[];


✔️ Valid


Declares an integer array named a


a[] is another way to write [] a



 You can also write: int[] a;



 II. static int [] a;


✔️ Valid


Declares a static integer array named a


Static means it's shared by the class, not object-specific




 III. public [] int a;


 Invalid Syntax


In Java, the brackets [] must come after the data type, not before it



 Correct: public int[] a;


IV. private int a[3];


 Invalid


You cannot specify the array size in the declaration in Java



This is allowed in C/C++, but not in Java


 In Java, do like this:


private int[] a = new int[3];



-V. private int[3] a;


 Invalid


You cannot write size [3] in the type declaration



 Correct format:


private int[] a;       // declaration

a = new int[3];        // size initialized later



 VI. public final int [] a;


✔️ Valid


Declares a final integer array a


final means: reference to array cannot change


You can't assign a new array


But you can change the values inside it


 Example:


a[0] = 10; // allowed

a = new int[5]; //  not allowed


==========================================

Line 1:


class Tree {}


This creates a base class called Tree


It’s a parent class or superclass



 Think of Tree like a general category (like: All trees 🌳)



Line 2:


class Pine extends Tree {}


Pine is a subclass of Tree


It inherits everything from Tree



 So Pine is a Tree.



 Line 3:


class Oak extends Tree {}


Oak is another subclass of Tree



 Oak also is a Tree, but different from Pine



Line 4:


public class Forest1 {


Declares the main class containing the main() method.


Execution starts here.


 Line 5:


public static void main(String[] args) {


Main method: Entry point of the program



 Line 6:


Tree tree = new Pine();


 What's happening?


A variable named tree is declared with type Tree (parent class)


But we are assigning it a new object: new Pine() (child class)



 This is called polymorphism:


> The reference (tree) is of type Tree, but it actually points to a Pine object.




 Now:


tree → Pine object



Line 7:


if(tree instanceof Pine)


Checks whether the object tree is an instance of the Pine class.



Since:


tree = new Pine();


 This condition is true


 So, it goes inside this if block



 Line 8:


System.out.println("Pine");


Since the condition was true, this line is executed.


 Output:


Pine



 Rest of the code is not executed because if already matched:


else if(tree instanceof Tree) // skipped

else if(tree instanceof Oak)  // skipped

else                           // skipped



 Final Output:


Pine



 Program Flow:


Step-- Code-- What Happens


1 -->Tree tree = new Pine(); -->A Pine object is created but referenced as Tree


2 -->tree instanceof Pine -- True →--> object is actually of type Pine


3 -->System.out.println("Pine"); --->Prints Pine to output


4 -->All other else if blocks--> --> Skipped




Business::


Think of this:


Tree = General class of employees


Pine = Developer


Oak = Designer



You hire a Developer, but you assign them to a general Employee reference.


You later check:


"Is this employee a Developer?" → ✅ Yes, so you print Developer.



 Concepts Used in This Program:


Concept--> Meaning


Class & Inheritance--> Pine and Oak extend Tree


Polymorphism--> Tree tree = new Pine();


instanceof operator -->To check actual object type at runtime


Conditional if-else--> Executes only the first true block


=========================================

Line 1:


String x = "xyz";


 What it does:


Creates a String variable named x


Stores the value "xyz" in it



 Now:


x = "xyz"


Line 2:


x.toUpperCase();  // Line 2 – no assignment


 What it does:


Tries to convert the string to uppercase


But it does NOT assign the result to anything



 So x remains unchanged


 Important:


Strings in Java are immutable


x.toUpperCase() returns "XYZ" but it’s not stored



 So still:


x = "xyz"



 Line 3:


String y = x.replace('Y', 'y');


 What it does:


Calls replace('Y', 'y') on string x



But:


x = "xyz"


There’s no capital 'Y' in "xyz"


So, the replace() does nothing, returns the same string


 So:


y = "xyz"


Line 4:


y = y + "abc";


 What it does:


Adds (concatenates) "abc" to the current value of y



Current:


y = "xyz"


So:


y = "xyz" + "abc" → "xyzabc"


 Final:


y = "xyzabc"



 Line 5:


System.out.println(y);


 What it does:


Prints the final value of y to the console


 Final Output:


xyzabc


========================================={

import java.util.*;


public class KennyCoolDrinks {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);


        int n = sc.nextInt(); // Step 1

        int[] prices = new int[n]; // Step 2


        for (int i = 0; i < n; i++) { // Step 3

            prices[i] = sc.nextInt();

        }


        int t = sc.nextInt(); // Step 4


        for (int testCase = 0; testCase < t; testCase++) { // Step 5

            int m = sc.nextInt(); // Step 6

            int p = sc.nextInt(); // Step 7


            int count = 0; // Step 8


            for (int i = 0; i < n; i++) { // Step 9

                if (prices[i] <= p) {     // Step 10

                    count++;

                }

            }


            System.out.print(testCase + " " + count + " "); // Step 11

        }

    }

}


=====≠==================================

Above program flow::::

===================


import java.util.*


 This line imports the Scanner class from Java's utility package, which lets us read input from the keyboard or console.



 public class KennyCoolDrinks {


 Declares the main class of the program. You can name it anything, but here it's named KennyCoolDrinks.



 public static void main(String[] args) {


 This is the starting point of the Java program. The JVM (Java Virtual Machine) begins execution here.



 Scanner sc = new Scanner(System.in);


 Creates a Scanner object named sc, which reads user input from the keyboard (console).


 Example: If user types 5, then sc.nextInt() will read that 5.



int n = sc.nextInt();


 Reads the number of shops Kenny wants to check.


 Example Input:


5


 Now: n = 5 → there are 5 shops


int[] prices = new int[n];


Creates an array of integers named prices, with n elements, to store the Coca Cola price at each shop.



 for (int i = 0; i < n; i++) { prices[i] = sc.nextInt(); }


 Reads the price at each shop, and stores it in the prices array.


 Example Input:


3 10 8 6 11


 Now:

prices[0] = 3

prices[1] = 10

prices[2] = 8

prices[3] = 6

prices[4] = 11


 int t = sc.nextInt();


 Reads the number of test cases (scenarios), meaning how many different money amounts Kenny will try.


 Example Input:


2


 Now: t = 2 → Two test cases will follow


for (int testCase = 0; testCase < t; testCase++) {


 Starts a loop to process each test case one by one.


First time → testCase = 0

 Second time → testCase = 1



 int m = sc.nextInt();


 Reads the number of days Kenny wants to buy the drink.

 We do not use this value in our logic (it's ignored).


 Example Input for test case 0:


1


int p = sc.nextInt();


 Reads the money Kenny has per day.

 This value is used to check affordability.


 Example Input:


10


 So Kenny has ₹10 per day in test case 0.



 int count = 0;


 Initializes a counter to count how many shops Kenny can afford in this test case.



 for (int i = 0; i < n; i++) { if (prices[i] <= p) { count++; } }


 Goes through each shop:


Checks if the price of that shop is less than or equal to Kenny’s daily money p


If true, increases the count


 For example:

If p = 10 and prices = {3, 10, 8, 6, 11},

→ Kenny can buy from shops at index 0, 1, 2, 3

→ So, count = 4



 System.out.print(testCase + " " + count + " ");


 Prints the result for the current test case in this format:


test_case_number count


For test case 0: 0 4

 For test case 1: 1 5


Final Output:


0 4 1 5



 Final Output:::


0 4 → Test case 0 → Kenny can buy from 4 shops

1 5 → Test case 1 → Kenny can buy from 5 shops





 Flow Diagram (Simplified)::


INPUT

Number of shops → shop prices → number of test cases

For each test case:

   → Read daily money

   → Loop through shops

   → Count how many prices ≤ daily money

   → Print test case number and count

END


Business::


Let’s say Kenny is a customer:


He checks multiple daily budgets.


You (as a developer) write a program to help him filter which vendors are affordable under each budget.

=========================================

For each test case, print:


Test Case Number --> Count of shops--> Kenny can afford



 Let's Process Test Case by Test Case:



 Test Case 0 → 1 10


> Meaning: Kenny wants to buy for 1 day, and has ₹10 that day.




We don’t care about the number of days here.


We only care about:


Which shop has price ≤ 10



 Shop Prices:


Index → 0   1   2   3   4  

Price → 3   10  8   6   11


 Step-by-step Check:


Shop Index--> Price--> Can Kenny afford?


0 -->3   -->Yes (3 ≤ 10)

1 -->10 --> Yes (10 ≤ 10)

2 -->8--> Yes (8 ≤ 10)

3 --->6 --->Yes (6 ≤ 10)

4 --->11 --> No (11 > 10)



 Total valid shops = 4


So we print:


0 4


0 → test case 0


4 → 4 valid shops




 Test Case 1 → 3 11


> Kenny has ₹11 per day




Step-by-step Check:


Shop Index Price Can Kenny afford?


0 3   Yes (3 ≤ 11)

1 10   Yes (10 ≤ 11)

2 8    Yes (8 ≤ 11)

3 6     Yes (6 ≤ 11)

4 11     Yes (11 ≤ 11)



 Total valid shops = 5


 So we print:


1 5


1 → test case 1


5 → 5 valid shops




 Final Output:


0 4 1 5


Value --Meaning


0-- Test case 0

4 --4 shops can be afforded in test 0

1 --Test case 1

5-- 5 shops can be afforded in test 1




  Summary:


Test Case 0:

→ Kenny has ₹10

→ Shops affordable = 0, 1, 2, 3 (4 shops)

→ Print: 0 4


Test Case 1:

→ Kenny has ₹11

→ Shops affordable = all (5 shops)

→ Print: 1 5



 Concepts Behind the Output:


Concept-- Used for...


Loop --To go through each shop

Condition --To check if rate ≤ p


Counter-- To count how many shops are affordable


Index Print --To show which test case it is (0, 1, etc.)


Output:: 0 4 1 5


=========================================

Java Concepts Used:


Concept -->How It’s Used in Program


Arrays -->To store shop prices

Loops (for) -->To read input and check each shop

Conditionals (if) -->To check if shop rate ≤ p

Scanner -->To read input from user

while loop -->To process multiple test cases


 Example:


A subscription app wants to check which vendors' prices are affordable for a customer’s daily budget.


Each test case represents a different customer or different day


Helps in filtering shops or creating purchase recommendations


Summary::::


You count how many shops have rate ≤ Kenny’s daily budget (p)


The output format is:


test_case_number count


That’s why the output is: 0 4 1 5

=======================================


Sample Input:


5

3 10 8 6 11

4

10


Let’s break this down:


Input Line -->Meaning


5 -->Total number of shops n = 5

3 10 8 6 11 -->Rates of cool drinks in each shop

4 -->Number of days m = 4

10 -->Money Kenny has each day, p = 10


========================================

Wednesday, July 2, 2025

Super keyword

 What is super keyword in Java?


 super is a reference variable used inside a subclass (child class) to access members (methods, variables, constructors) of the parent class (superclass).


When is super used?


Use Case----> Purpose Example


Access parent class variable---> super.name refers to the superclass name


Call parent class method---> super.display() calls superclass method


Call parent constructor---> super(...) calls superclass constructor


Example:


Imagine you are building an Employee Payroll System for a company. There are:


Base class Employee → common features like name, salary


Child class Manager → adds extra features like bonus

We’ll use super to:


Access base class constructor from Manager


Access methods and variables of the parent class


Java Program Using super Keyword


// Parent class

class Employee {

    String name;

    double salary;


    // Constructor

    Employee(String name, double salary) {

        this.name = name;

        this.salary = salary;

    }


    void displayDetails() {

        System.out.println("Employee Name: " + name);

        System.out.println("Base Salary: ₹" + salary);

    }

}


// Child class

class Manager extends Employee {

    double bonus;


    // Constructor with super() call

    Manager(String name, double salary, double bonus) {

        super(name, salary); // Call parent class constructor

        this.bonus = bonus;

    }


    void displayDetails() {

        super.displayDetails(); // Call parent method

        System.out.println("Bonus: ₹" + bonus);

        System.out.println("Total Salary: ₹" + (salary + bonus));

    }

}


public class CompanyPayroll {

    public static void main(String[] args) {

        Manager m1 = new Manager("Priya", 50000, 10000);

        m1.displayDetails();

    }

}


Creates a Manager object m1 with:


name = "Priya"


salary = ₹50,000


bonus = ₹10,000



Calls m1.displayDetails() → prints all info.


Output:


Employee Name: Priya

Base Salary: ₹50000.0

Bonus: ₹10000.0

Total Salary: ₹60000.0


 







Java interview questions

 1. Basic Programs (Input, Output, Loops)


 Q1. Write a program to check if a number is even or odd.


import java.util.Scanner;


public class EvenOdd {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in); // For input

        System.out.print("Enter a number: ");

        int num = sc.nextInt(); // Read number from user


        if(num % 2 == 0) {

            System.out.println(num + " is even");

        } else {

            System.out.println(num + " is odd");

        }

    }

}


 Flow:


Input a number → Check num % 2 → Print result.



Output:


Enter a number: 5

5 is odd





2. OOPS Concepts – Classes, Objects, Methods


 Q2. Program to demonstrate Class & Object


class Car {

    String color = "Red";

    void drive() {

        System.out.println("Car is driving");

    }

    

    void displayColor() {

        System.out.println("Color is: " + color);

    }

}


public class Main {

    public static void main(String[] args) {

        Car myCar = new Car();  // Object creation

        myCar.drive();          // Method call

        myCar.displayColor();   // Method call

    }

}


 Output:


Car is driving

Color is: Red


 Flow:


Create class Car → Create object in main → Call methods






 3. Constructor Overloading


 Q3. Program to demonstrate constructor overloading


class Student {

    String name;

    int age;


    Student() {

        name = "Default";

        age = 18;

    }


    Student(String n, int a) {

        name = n;

        age = a;

    }


    void show() {

        System.out.println("Name: " + name + ", Age: " + age);

    }

}


public class Test {

    public static void main(String[] args) {

        Student s1 = new Student();         // Calls default constructor

        Student s2 = new Student("Raj", 20); // Calls parameterized constructor


        s1.show();

        s2.show();

    }

}


Output:


Name: Default, Age: 18

Name: Raj, Age: 20





 4. Inheritance and Polymorphism


Q4. Program to demonstrate method overriding


class Animal {

    void sound() {

        System.out.println("Animal makes sound");

    }

}


class Dog extends Animal {

    void sound() {

        System.out.println("Dog barks");

    }

}


public class Test {

    public static void main(String[] args) {

        Animal a = new Dog(); // Upcasting

        a.sound();  // Calls Dog's sound() method

    }

}


 Output:


Dog barks


 Flow:


Dog overrides sound() → Object is of Dog → Dog's method is called






 5. Encapsulation


 Q5. Program with getter and setter


class Employee {

    private String name;


    public void setName(String n) {

        name = n;

    }


    public String getName() {

        return name;

    }

}


public class Test {

    public static void main(String[] args) {

        Employee e = new Employee();

        e.setName("Ajay");

        System.out.println("Name: " + e.getName());

    }

}


 Output:


Name: Ajay





6. Abstraction


Q6. Abstract class example


abstract class Shape {

    abstract void draw();

}


class Circle extends Shape {

    void draw() {

        System.out.println("Drawing Circle");

    }

}


public class Test {

    public static void main(String[] args) {

        Shape s = new Circle();

        s.draw();

    }

}


 Output:


Drawing Circle





 7. Interface


 Q7. Interface implementation


interface Bank {

    double rateOfInterest();

}


class SBI implements Bank {

    public double rateOfInterest() {

        return 7.0;

    }

}


public class Test {

    public static void main(String[] args) {

        Bank b = new SBI();

        System.out.println("ROI: " + b.rateOfInterest());

    }

}


 Output:


ROI: 7.0





 8. Exception Handling


 Q8. Try-catch-finally example


public class Test {

    public static void main(String[] args) {

        try {

            int a = 10 / 0; // Throws exception

        } catch(ArithmeticException e) {

            System.out.println("Error: " + e.getMessage());

        } finally {

            System.out.println("Finally block executed");

        }

    }

}


 Output:


Error: / by zero

Finally block executed



 9. String Programs


Q9. Reverse a string


public class ReverseString {

    public static void main(String[] args) {

        String s = "Java";

        String rev = "";


        for(int i = s.length() - 1; i >= 0; i--) {

            rev += s.charAt(i);

        }


        System.out.println("Reversed: " + rev);

    }

}


Output:


Reversed: avaJ





 10. Collections (ArrayList)


Q10. Add elements to ArrayList


import java.util.*;


public class Test {

    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();


        list.add("Apple");

        list.add("Banana");

        list.add("Mango");


        for(String fruit : list) {

            System.out.println(fruit);

        }

    }

}


 Output:


Apple

Banana

Mango





 11. Multithreading (Thread)


 Q11. Thread example using Runnable


class MyThread implements Runnable {

    public void run() {

        System.out.println("Thread is running...");

    }

}


public class Test {

    public static void main(String[] args) {

        MyThread obj = new MyThread();

        Thread t = new Thread(obj);

        t.start();

    }

}


 Output:


Thread is running...





 12. File Handling


 Q12. Write to file


import java.io.FileWriter;

import java.io.IOException;


public class WriteFile {

    public static void main(String[] args) {

        try {

            FileWriter writer = new FileWriter("test.txt");

            writer.write("Hello Java!");

            writer.close();

            System.out.println("File written successfully");

        } catch(IOException e) {

            e.printStackTrace();

        }

    }

}

13. Swapping Two Numbers Without Temporary Variable


public class SwapNumbers {

    public static void main(String[] args) {

        int a = 10, b = 20;


        System.out.println("Before Swap: a = " + a + ", b = " + b);


        a = a + b; // a = 30

        b = a - b; // b = 10

        a = a - b; // a = 20


        System.out.println("After Swap: a = " + a + ", b = " + b);

    }

}


 Flow:


Add both → Store in one variable → Subtract step-by-step.



 Output:


Before Swap: a = 10, b = 20

After Swap: a = 20, b = 10



 14. Check if a String is Palindrome


public class PalindromeCheck {

    public static void main(String[] args) {

        String original = "madam";

        String reverse = "";


        for(int i = original.length()-1; i >= 0; i--) {

            reverse += original.charAt(i);

        }


        if(original.equals(reverse)) {

            System.out.println(original + " is a Palindrome");

        } else {

            System.out.println(original + " is not a Palindrome");

        }

    }

}


 Flow:


Reverse the string → Compare with original.



Output:


madam is a Palindrome



 15. Factorial using Recursion


public class FactorialRec {

    static int factorial(int n) {

        if(n == 0 || n == 1)

            return 1;

        else

            return n * factorial(n - 1);

    }


    public static void main(String[] args) {

        int num = 5;

        System.out.println("Factorial of " + num + " is " + factorial(num));

    }

}


 Flow:


Recursive call until n == 1.



 Output:


Factorial of 5 is 120





 16. Armstrong Number (3-digit)


public class Armstrong {

    public static void main(String[] args) {

        int num = 153, sum = 0, temp = num;


        while(num != 0) {

            int digit = num % 10;

            sum += digit * digit * digit;

            num /= 10;

        }


        if(sum == temp) {

            System.out.println(temp + " is an Armstrong number");

        } else {

            System.out.println(temp + " is not an Armstrong number");

        }

    }

}


 Flow:


Extract each digit → Cube it → Add → Compare with original.



Output:


153 is an Armstrong number



---


 17. Check Prime Number


public class PrimeCheck {

    public static void main(String[] args) {

        int num = 29;

        boolean isPrime = true;


        for(int i = 2; i <= num/2; i++) {

            if(num % i == 0) {

                isPrime = false;

                break;

            }

        }


        if(isPrime)

            System.out.println(num + " is a Prime Number");

        else

            System.out.println(num + " is not a Prime Number");

    }

}


 Flow:


Divide by all numbers from 2 to n/2.



 Output:


29 is a Prime Number



 18. Find Duplicate Characters in a String


public class DuplicateCharacters {

    public static void main(String[] args) {

        String str = "programming";

        char[] chars = str.toCharArray();


        System.out.println("Duplicate characters:");


        for(int i = 0; i < chars.length; i++) {

            for(int j = i+1; j < chars.length; j++) {

                if(chars[i] == chars[j]) {

                    System.out.println(chars[i]);

                    break;

                }

            }

        }

    }

}


 Flow:


Compare every char with the rest.



 Output:


Duplicate characters:

r

g

m





 19. Java 8 – Stream API Filter Example


import java.util.*;

import java.util.stream.*;


public class StreamExample {

    public static void main(String[] args) {

        List<Integer> numbers = Arrays.asList(5, 10, 15, 20, 25, 30);


        List<Integer> result = numbers.stream()

                                      .filter(n -> n > 15)

                                      .collect(Collectors.toList());


        System.out.println(result);

    }

}


 Flow:


Stream → Filter → Collect → Print.



Output:


[20, 25, 30]



 20. Lambda Expression Example


interface Operation {

    int operate(int a, int b);

}


public class LambdaExample {

    public static void main(String[] args) {

        Operation add = (a, b) -> a + b;

        Operation mul = (a, b) -> a * b;


        System.out.println("Add: " + add.operate(10, 20));

        System.out.println("Multiply: " + mul.operate(10, 20));

    }

}


 Flow:


Use lambda instead of anonymous class.



 Output:


Add: 30

Multiply: 200



 21. Sorting Array in Ascending Order


import java.util.Arrays;


public class SortArray {

    public static void main(String[] args) {

        int[] arr = {5, 2, 8, 1, 3};


        Arrays.sort(arr);


        System.out.print("Sorted Array: ");

        for(int num : arr) {

            System.out.print(num + " ");

        }

    }

}


 Output:


Sorted Array: 1 2 3 5 8



 22. Count Vowels and Consonants in a String


public class VowelConsonant {

    public static void main(String[] args) {

        String str = "Hello World";

        int vowels = 0, consonants = 0;


        str = str.toLowerCase();


        for(char ch : str.toCharArray()) {

            if(ch >= 'a' && ch <= 'z') {

                if("aeiou".indexOf(ch) != -1)

                    vowels++;

                else

                    consonants++;

            }

        }


        System.out.println("Vowels: " + vowels);

        System.out.println("Consonants: " + consonants);

    }

}


 Output:


Vowels: 3

Consonants: 7

 Output:


File written successfully



23. Reverse a String (Using StringBuilder)


public class ReverseStringBuilder {

    public static void main(String[] args) {

        String str = "JavaDeveloper";

        StringBuilder sb = new StringBuilder(str);

        sb.reverse(); // Reverses in-place

        System.out.println("Reversed: " + sb);

    }

}


Flow:


StringBuilder is mutable → use reverse() method



Output:


Reversed: repoleveDavaJ



24. Reverse a Number


public class ReverseNumber {

    public static void main(String[] args) {

        int num = 1234, rev = 0;


        while(num != 0) {

            int digit = num % 10;

            rev = rev * 10 + digit;

            num /= 10;

        }


        System.out.println("Reversed Number: " + rev);

    }

}


 Output:


Reversed Number: 4321



 25. Java Collections – ArrayList Example


import java.util.*;


public class ArrayListExample {

    public static void main(String[] args) {

        List<String> list = new ArrayList<>();


        list.add("Java");

        list.add("Python");

        list.add("C++");


        System.out.println("Languages: " + list);

    }

}


Output:


Languages: [Java, Python, C++]



 26. Java Collections – HashSet (No duplicates)


import java.util.*;


public class HashSetExample {

    public static void main(String[] args) {

        Set<String> names = new HashSet<>();


        names.add("Alice");

        names.add("Bob");

        names.add("Alice"); // Duplicate


        System.out.println("Names: " + names);

    }

}


Output:


Names: [Bob, Alice]  // order may vary (no duplicates)



27. Java Collections – HashMap Example (Key-Value Pairs)


import java.util.*;


public class HashMapExample {

    public static void main(String[] args) {

        Map<Integer, String> map = new HashMap<>();


        map.put(101, "John");

        map.put(102, "Alice");

        map.put(103, "Bob");


        for(Map.Entry<Integer, String> entry : map.entrySet()) {

            System.out.println("ID: " + entry.getKey() + ", Name: " + entry.getValue());

        }

    }

}


Output:


ID: 101, Name: John

ID: 102, Name: Alice

ID: 103, Name: Bob



 28. Stream API – Print Even Numbers


import java.util.*;

import java.util.stream.*;


public class StreamEven {

    public static void main(String[] args) {

        List<Integer> numbers = Arrays.asList(2, 3, 4, 5, 6, 7, 8);


        numbers.stream()

               .filter(n -> n % 2 == 0)

               .forEach(System.out::println);

    }

}


 Output:


2

4

6

8





29. Stream API – Sum of List Elements


import java.util.*;

import java.util.stream.*;


public class StreamSum {

    public static void main(String[] args) {

        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);


        int sum = list.stream().mapToInt(i -> i).sum();

        System.out.println("Sum: " + sum);

    }

}


Output:


Sum: 15





30. Stream API – Convert List of Strings to Uppercase


import java.util.*;

import java.util.stream.*;


public class StreamUpperCase {

    public static void main(String[] args) {

        List<String> names = Arrays.asList("java", "python", "spring");


        List<String> upper = names.stream()

                                  .map(String::toUpperCase)

                                  .collect(Collectors.toList());


        System.out.println(upper);

    }

}


Output:


[JAVA, PYTHON, SPRING]





31. Lambda Expression – Comparator to Sort by Length


import java.util.*;


public class LambdaSort {

    public static void main(String[] args) {

        List<String> list = Arrays.asList("Banana", "Apple", "Cherry");


        // Sort by length using lambda

        list.sort((a, b) -> a.length() - b.length());


        System.out.println("Sorted by length: " + list);

    }

}


Output:


Sorted by length: [Apple, Banana, Cherry]





32. Functional Interface Example


@FunctionalInterface

interface Greetable {

    void greet(String name);

}


public class FunctionalInterfaceExample {

    public static void main(String[] args) {

        Greetable g = (name) -> System.out.println("Hello, " + name + "!");

        g.greet("Ravi");

    }

}


Output:


Hello, Ravi!




1. Check if Two Strings Are Anagrams


import java.util.Arrays;


public class AnagramCheck {

    public static void main(String[] args) {

        String s1 = "listen";

        String s2 = "silent";


        char[] a1 = s1.toCharArray();

        char[] a2 = s2.toCharArray();


        Arrays.sort(a1);

        Arrays.sort(a2);


        if(Arrays.equals(a1, a2)) {

            System.out.println("Anagram");

        } else {

            System.out.println("Not Anagram");

        }

    }

}


 Output:


Anagram



 2. Left Rotate an Array by 1


public class LeftRotate {

    public static void main(String[] args) {

        int[] arr = {1, 2, 3, 4, 5};

        int first = arr[0];


        for(int i = 0; i < arr.length - 1; i++) {

            arr[i] = arr[i + 1];

        }

        arr[arr.length - 1] = first;


        for(int num : arr) {

            System.out.print(num + " ");

        }

    }

}


 Output:


2 3 4 5 1



 3. Print Pascal’s Triangle


public class PascalsTriangle {

    public static void main(String[] args) {

        int rows = 5;


        for(int i = 0; i < rows; i++) {

            int num = 1;

            for(int j = 0; j <= i; j++) {

                System.out.print(num + " ");

                num = num * (i - j) / (j + 1);

            }

            System.out.println();

        }

    }

}


 Output:


1 1 

1 2 1 

1 3 3 1 

1 4 6 4 1



 4. Find First Non-Repeated Character in a String


public class FirstUniqueChar {

    public static void main(String[] args) {

        String str = "aabbcde";

        for (char c : str.toCharArray()) {

            if (str.indexOf(c) == str.lastIndexOf(c)) {

                System.out.println("First non-repeating: " + c);

                break;

            }

        }

    }

}


 Output:


First non-repeating: c



 5. Reverse Each Word in a Sentence


public class ReverseWords {

    public static void main(String[] args) {

        String str = "Java is fun";

        String[] words = str.split(" ");


        for(String word : words) {

            StringBuilder rev = new StringBuilder(word);

            System.out.print(rev.reverse() + " ");

        }

    }

}


Output:


avaJ si nuf



 6. Count Words in a Sentence


public class WordCount {

    public static void main(String[] args) {

        String sentence = "Java is a popular language";

        String[] words = sentence.trim().split("\\s+");

        System.out.println("Word count: " + words.length);

    }

}


 Output:


Word count: 5





 7. Static Block Execution Before Main


public class StaticDemo {

    static {

        System.out.println("Static block called before main");

    }


    public static void main(String[] args) {

        System.out.println("Main method");

    }

}


 Output:


Static block called before main  

Main method



 8. Count Set Bits (1s) in a Binary Number


public class CountSetBits {

    public static void main(String[] args) {

        int num = 13; // Binary = 1101

        int count = 0;


        while(num > 0) {

            count += num & 1;

            num >>= 1;

        }


        System.out.println("Set Bits: " + count);

    }

}


 Output:


Set Bits: 3



 9. Compare Two Objects Using .equals() and ==


public class ObjectCompare {

    public static void main(String[] args) {

        String a = new String("Java");

        String b = new String("Java");


        System.out.println(a == b);        // false (reference)

        System.out.println(a.equals(b));   // true (content)

    }

}


 Output:


false  

true



 10. Find Missing Number in Array 1 to N


public class MissingNumber {

    public static void main(String[] args) {

        int[] arr = {1, 2, 4, 5, 6}; // Missing 3

        int n = 6;

        int total = n * (n + 1) / 2;


        int sum = 0;

        for(int num : arr) sum += num;


        System.out.println("Missing number: " + (total - sum));

    }

}


 Output:


Missing number: 3



 11. Find Duplicate Elements in Array


import java.util.*;


public class DuplicateElements {

    public static void main(String[] args) {

        int[] arr = {1, 2, 3, 2, 4, 1};


        Set<Integer> seen = new HashSet<>();

        Set<Integer> dup = new HashSet<>();


        for(int num : arr) {

            if(!seen.add(num)) {

                dup.add(num);

            }

        }


        System.out.println("Duplicates: " + dup);

    }

}


 Output:


Duplicates: [1, 2]



1. Check if a Number is a Power of Two


public class PowerOfTwo {

    public static void main(String[] args) {

        int num = 16;


        if ((num & (num - 1)) == 0 && num != 0)

            System.out.println(num + " is a power of 2");

        else

            System.out.println(num + " is not a power of 2");

    }

}


 Output:


16 is a power of 2


 Logic: A power of 2 has only one set bit in binary.





 2. Check Armstrong Number for Any Digits


public class ArmstrongAnyDigit {

    public static void main(String[] args) {

        int num = 9474, temp = num, sum = 0;

        int digits = String.valueOf(num).length();


        while(temp > 0) {

            int digit = temp % 10;

            sum += Math.pow(digit, digits);

            temp /= 10;

        }


        System.out.println(num + (sum == num ? " is " : " is not ") + "an Armstrong number");

    }

}


 Output:


9474 is an Armstrong number



 3. Swap Two Strings Without Using Third Variable


public class SwapStrings {

    public static void main(String[] args) {

        String a = "Hello";

        String b = "World";


        System.out.println("Before Swap: a = " + a + ", b = " + b);


        a = a + b;

        b = a.substring(0, a.length() - b.length());

        a = a.substring(b.length());


        System.out.println("After Swap: a = " + a + ", b = " + b);

    }

}


 Output:


Before Swap: a = Hello, b = World  

After Swap: a = World, b = Hello



 4. Find the Second Largest Number in an Array


public class SecondLargest {

    public static void main(String[] args) {

        int[] arr = {10, 25, 60, 12, 45};

        int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;


        for (int num : arr) {

            if (num > first) {

                second = first;

                first = num;

            } else if (num > second && num != first) {

                second = num;

            }

        }


        System.out.println("Second Largest: " + second);

    }

}


 Output:


Second Largest: 45



 5. Sum of Digits Until a Single Digit (Digital Root)


public class DigitalRoot {

    public static void main(String[] args) {

        int num = 9875;


        while(num > 9) {

            int sum = 0;

            while(num != 0) {

                sum += num % 10;

                num /= 10;

            }

            num = sum;

        }


        System.out.println("Digital Root: " + num);

    }

}


 Output:


Digital Root: 2



 6. Check if All Characters in a String Are Unique


public class UniqueCharacters {

    public static void main(String[] args) {

        String str = "abcdef";

        boolean[] seen = new boolean[128]; // ASCII chars


        boolean unique = true;

        for (char ch : str.toCharArray()) {

            if (seen[ch]) {

                unique = false;

                break;

            }

            seen[ch] = true;

        }


        System.out.println(unique ? "All characters are unique" : "Duplicates found");

    }

}


Output:


All characters are unique



 7. Count Vowels, Consonants, Digits and Special Characters


public class CharTypesCounter {

    public static void main(String[] args) {

        String str = "Java@123#";


        int vowels = 0, consonants = 0, digits = 0, specials = 0;


        for(char ch : str.toCharArray()) {

            if(Character.isDigit(ch)) digits++;

            else if(Character.isLetter(ch)) {

                ch = Character.toLowerCase(ch);

                if("aeiou".indexOf(ch) != -1) vowels++;

                else consonants++;

            } else specials++;

        }


        System.out.println("Vowels: " + vowels);

        System.out.println("Consonants: " + consonants);

        System.out.println("Digits: " + digits);

        System.out.println("Special characters: " + specials);

    }

}


 Output:


Vowels: 2  

Consonants: 2  

Digits: 3  

Special characters: 2



 8. Check Whether a String Contains Only Digits


public class OnlyDigits {

    public static void main(String[] args) {

        String s = "12345a";


        if (s.matches("\\d+")) {

            System.out.println("Only digits");

        } else {

            System.out.println("Contains non-digit characters");

        }

    }

}


 Output:


Contains non-digit characters



 9. Create Pyramid Pattern


public class PyramidPattern {

    public static void main(String[] args) {

        int n = 5;


        for(int i = 1; i <= n; i++) {

            for(int space = 1; space <= n-i; space++)

                System.out.print(" ");

            for(int j = 1; j <= 2*i-1; j++)

                System.out.print("*");

            System.out.println();

        }

    }

}


 Output:


*

   ***

  *****

 *******

*********



 10. Check Whether a String is a Pangram (All 26 Letters Present)


public class PangramCheck {

    public static void main(String[] args) {

        String str = "The quick brown fox jumps over the lazy dog";

        str = str.toLowerCase();


        boolean[] alphabet = new boolean[26];


        for(char ch : str.toCharArray()) {

            if(ch >= 'a' && ch <= 'z') {

                alphabet[ch - 'a'] = true;

            }

        }


        boolean isPangram = true;

        for(boolean present : alphabet) {

            if(!present) {

                isPangram = false;

                break;

            }

        }


        System.out.println(isPangram ? "Pangram" : "Not a Pangram");

    }

}


 Output:


Pangram


1. Check if a Number is Palindrome (Reverse Integer)


public class PalindromeNumber {

    public static void main(String[] args) {

        int num = 121;

        int temp = num, rev = 0;


        while (temp != 0) {

            int digit = temp % 10;

            rev = rev * 10 + digit;

            temp /= 10;

        }


        System.out.println((rev == num) ? "Palindrome" : "Not Palindrome");

    }

}


 Output:


Palindrome





 2. Count Occurrence of Each Word in a Sentence


import java.util.*;


public class WordFrequency {

    public static void main(String[] args) {

        String sentence = "this is java and java is powerful";

        String[] words = sentence.split(" ");


        Map<String, Integer> freq = new HashMap<>();

        for(String word : words) {

            freq.put(word, freq.getOrDefault(word, 0) + 1);

        }


        System.out.println(freq);

    }

}


 Output:


{this=1, is=2, java=2, and=1, powerful=1}



3. Check if a String is a Rotation of Another


public class StringRotation {

    public static void main(String[] args) {

        String s1 = "abcde";

        String s2 = "deabc";


        if(s1.length() == s2.length() && (s1 + s1).contains(s2))

            System.out.println("Rotation");

        else

            System.out.println("Not Rotation");

    }

}


Output:


Rotation





 4. Reverse an Integer Without String Conversion


public class ReverseInt {

    public static void main(String[] args) {

        int num = 1234, rev = 0;


        while(num != 0) {

            int digit = num % 10;

            rev = rev * 10 + digit;

            num /= 10;

        }


        System.out.println("Reversed: " + rev);

    }

}


Output:


Reversed: 4321



 5. Print All Permutations of a String (Recursion)


public class Permutations {

    public static void permute(String s, String answer) {

        if(s.length() == 0) {

            System.out.println(answer);

            return;

        }


        for(int i = 0; i < s.length(); i++) {

            char ch = s.charAt(i);

            String rest = s.substring(0, i) + s.substring(i+1);

            permute(rest, answer + ch);

        }

    }


    public static void main(String[] args) {

        String str = "abc";

        permute(str, "");

    }

}


Output:


abc

acb

bac

bca

cab

cba



 6. Find All Pairs in Array with Sum = K


public class PairSum {

    public static void main(String[] args) {

        int[] arr = {2, 4, 3, 5, 7};

        int target = 7;


        for(int i = 0; i < arr.length; i++) {

            for(int j = i+1; j < arr.length; j++) {

                if(arr[i] + arr[j] == target) {

                    System.out.println(arr[i] + " + " + arr[j] + " = " + target);

                }

            }

        }

    }

}


 Output:


2 + 5 = 7  

4 + 3 = 7



 7. Remove Duplicate Characters from a String


public class RemoveDuplicateChars {

    public static void main(String[] args) {

        String str = "programming";

        StringBuilder result = new StringBuilder();


        for(int i = 0; i < str.length(); i++) {

            char ch = str.charAt(i);

            if(result.indexOf(String.valueOf(ch)) == -1) {

                result.append(ch);

            }

        }


        System.out.println("Without duplicates: " + result);

    }

}


 Output:


Without duplicates: progamin





 8. Convert Roman Numerals to Integer


import java.util.*;


public class RomanToInteger {

    public static int romanToInt(String s) {

        Map<Character, Integer> map = Map.of(

            'I', 1, 'V', 5, 'X', 10, 'L', 50,

            'C', 100, 'D', 500, 'M', 1000

        );


        int total = 0;

        for(int i = 0; i < s.length(); i++) {

            int val = map.get(s.charAt(i));

            if(i + 1 < s.length() && val < map.get(s.charAt(i+1))) {

                total -= val;

            } else {

                total += val;

            }

        }

        return total;

    }


    public static void main(String[] args) {

        System.out.println("Result: " + romanToInt("MCMIV")); // 1904

    }

}


 Output:


Result: 1904



 9. Reverse Words in a Sentence (Not Characters)


public class ReverseSentenceWords {

    public static void main(String[] args) {

        String sentence = "Java is easy";

        String[] words = sentence.split(" ");


        for(int i = words.length - 1; i >= 0; i--) {

            System.out.print(words[i] + " ");

        }

    }

}


 Output:


easy is Java



 10. Sort Characters in a String Alphabetically


import java.util.Arrays;


public class SortChars {

    public static void main(String[] args) {

        String s = "developer";

        char[] arr = s.toCharArray();

        Arrays.sort(arr);

        System.out.println("Sorted: " + new String(arr));

    }

}


 Output:


Sorted: deeloperv



1. Count Number of Digits in an Integer


public class CountDigits {

    public static void main(String[] args) {

        int num = 12345;

        int count = 0;


        while (num != 0) {

            num = num / 10;

            count++;

        }


        System.out.println("Total digits: " + count);

    }

}


 Output:


Total digits: 5



2. Find GCD of Two Numbers


public class GCD {

    public static void main(String[] args) {

        int a = 24, b = 36;

        int gcd = 1;


        for (int i = 1; i <= a && i <= b; i++) {

            if (a % i == 0 && b % i == 0)

                gcd = i;

        }


        System.out.println("GCD: " + gcd);

    }

}


 Output:


GCD: 12





 3. Find LCM of Two Numbers


public class LCM {

    public static void main(String[] args) {

        int a = 12, b = 18;

        int max = Math.max(a, b);


        while (true) {

            if (max % a == 0 && max % b == 0) {

                System.out.println("LCM: " + max);

                break;

            }

            max++;

        }

    }

}


 Output:


LCM: 36





 4. Linear Search in Array


public class LinearSearch {

    public static void main(String[] args) {

        int[] arr = {10, 20, 30, 40};

        int key = 30;

        boolean found = false;


        for (int i = 0; i < arr.length; i++) {

            if (arr[i] == key) {

                found = true;

                System.out.println("Found at index: " + i);

                break;

            }

        }


        if (!found)

            System.out.println("Not found");

    }

}


 Output:


Found at index: 2





 5. Binary Search (Sorted Array)


import java.util.*;


public class BinarySearch {

    public static void main(String[] args) {

        int[] arr = {5, 10, 20, 30, 50};

        int key = 30;

        int low = 0, high = arr.length - 1;

        boolean found = false;


        while (low <= high) {

            int mid = (low + high) / 2;


            if (arr[mid] == key) {

                found = true;

                System.out.println("Found at index: " + mid);

                break;

            } else if (arr[mid] < key) {

                low = mid + 1;

            } else {

                high = mid - 1;

            }

        }


        if (!found)

            System.out.println("Not found");

    }

}


 Output:


Found at index: 3



 6. Check Whether a Number is Perfect Number


> A perfect number = sum of its proper divisors (excluding itself)




public class PerfectNumber {

    public static void main(String[] args) {

        int num = 28, sum = 0;


        for (int i = 1; i < num; i++) {

            if (num % i == 0)

                sum += i;

        }


        if (sum == num)

            System.out.println(num + " is Perfect Number");

        else

            System.out.println(num + " is Not Perfect");

    }

}


Output:


28 is Perfect Number





 7. Constructor Overloading Example


public class Student {

    String name;

    int age;


    Student() {

        name = "Default";

        age = 18;

    }


    Student(String name, int age) {

        this.name = name;

        this.age = age;

    }


    void display() {

        System.out.println(name + " - " + age);

    }


    public static void main(String[] args) {

        Student s1 = new Student();

        Student s2 = new Student("Rahul", 21);


        s1.display();

        s2.display();

    }

}


 Output:


Default - 18  

Rahul - 21





 8. Check Armstrong Number (3 digits)


public class Armstrong {

    public static void main(String[] args) {

        int num = 153, temp = num, sum = 0;


        while (temp != 0) {

            int d = temp % 10;

            sum += d * d * d;

            temp /= 10;

        }


        System.out.println((sum == num) ? "Armstrong" : "Not Armstrong");

    }

}


Output:


Armstrong



 9. Reverse a Number Using Recursion


public class ReverseRecursion {

    static int rev = 0;

    public static void reverse(int num) {

        if (num == 0)

            return;

        rev = rev * 10 + num % 10;

        reverse(num / 10);

    }


    public static void main(String[] args) {

        int num = 1234;

        reverse(num);

        System.out.println("Reversed: " + rev);

    }

}


 Output:


Reversed: 4321



 10. Print Floyd's Triangle


public class FloydTriangle {

    public static void main(String[] args) {

        int n = 5, num = 1;


        for (int i = 1; i <= n; i++) {

            for (int j = 1; j <= i; j++) {

                System.out.print(num++ + " ");

            }

            System.out.println();

        }

    }

}


 Output:


1  

2 3  

4 5 6  

7 8 9 10  

11 12 13 14 15



 11. Check Whether a String Is Palindrome (Ignoring Case & Space)


public class PalindromeClean {

    public static void main(String[] args) {

        String str = "A man a plan a canal Panama";

        str = str.replaceAll("\\s+", "").toLowerCase();


        String rev = new StringBuilder(str).reverse().toString();

        System.out.println(str.equals(rev) ? "Palindrome" : "Not Palindrome");

    }

}


 Output:


Palindrome



 12. Check Leap Year


public class LeapYearCheck {

    public static void main(String[] args) {

        int year = 2024;


        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)

            System.out.println(year + " is a Leap Year");

        else

            System.out.println(year + " is not a Leap Year");

    }

}


Output:


2024 is a Leap Year



//  1. Inheritance Example

class Animal {

    void sound() {

        System.out.println("Animal makes sound");

    }

}


class Dog extends Animal {

    void sound() {

        System.out.println("Dog barks");

    }

}



//  2. Interface Implementation

interface Vehicle {

    void run();

}


class Bike implements Vehicle {

    public void run() {

        System.out.println("Bike is running");

    }

}



//  3. File Handling - Write to File

import java.io.*;

class WriteFile {

    public static void main(String[] args) {

        try {

            FileWriter fw = new FileWriter("output.txt");

            fw.write("Hello, this is file handling example in Java.");

            fw.close();

            System.out.println("File written successfully.");

        } catch (IOException e) {

            System.out.println("An error occurred.");

        }

    }

}



//  4. File Handling - Read from File

import java.io.*;

class ReadFile {

    public static void main(String[] args) {

        try {

            BufferedReader br = new BufferedReader(new FileReader("output.txt"));

            String line;

            while ((line = br.readLine()) != null) {

                System.out.println(line);

            }

            br.close();

        } catch (IOException e) {

            System.out.println("File not found.");

        }

    }

}



//  5. Collections - ArrayList Example

import java.util.*;

class ListExample {

    public static void main(String[] args) {

        List<String> list = new ArrayList<>();

        list.add("Apple");

        list.add("Banana");

        list.add("Orange");

        for (String item : list) {

            System.out.println(item);

        }

    }

}



//  6. Collections - HashMap Example

import java.util.*;

class MapExample {

    public static void main(String[] args) {

        Map<Integer, String> map = new HashMap<>();

        map.put(1, "Java");

        map.put(2, "Python");

        map.put(3, "C++");

        for (Map.Entry<Integer, String> entry : map.entrySet()) {

            System.out.println(entry.getKey() + " - " + entry.getValue());

        }

    }

}

1. Basic Programs (Input, Output, Loops)


 Q1. Write a program to check if a number is even or odd.


import java.util.Scanner;


public class EvenOdd {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in); // For input

        System.out.print("Enter a number: ");

        int num = sc.nextInt(); // Read number from user


        if(num % 2 == 0) {

            System.out.println(num + " is even");

        } else {

            System.out.println(num + " is odd");

        }

    }

}


 Flow:


Input a number → Check num % 2 → Print result.



Output:


Enter a number: 5

5 is odd





2. OOPS Concepts – Classes, Objects, Methods


 Q2. Program to demonstrate Class & Object


class Car {

    String color = "Red";

    void drive() {

        System.out.println("Car is driving");

    }

    

    void displayColor() {

        System.out.println("Color is: " + color);

    }

}


public class Main {

    public static void main(String[] args) {

        Car myCar = new Car();  // Object creation

        myCar.drive();          // Method call

        myCar.displayColor();   // Method call

    }

}


 Output:


Car is driving

Color is: Red


 Flow:


Create class Car → Create object in main → Call methods






 3. Constructor Overloading


 Q3. Program to demonstrate constructor overloading


class Student {

    String name;

    int age;


    Student() {

        name = "Default";

        age = 18;

    }


    Student(String n, int a) {

        name = n;

        age = a;

    }


    void show() {

        System.out.println("Name: " + name + ", Age: " + age);

    }

}


public class Test {

    public static void main(String[] args) {

        Student s1 = new Student();         // Calls default constructor

        Student s2 = new Student("Raj", 20); // Calls parameterized constructor


        s1.show();

        s2.show();

    }

}


Output:


Name: Default, Age: 18

Name: Raj, Age: 20





 4. Inheritance and Polymorphism


Q4. Program to demonstrate method overriding


class Animal {

    void sound() {

        System.out.println("Animal makes sound");

    }

}


class Dog extends Animal {

    void sound() {

        System.out.println("Dog barks");

    }

}


public class Test {

    public static void main(String[] args) {

        Animal a = new Dog(); // Upcasting

        a.sound();  // Calls Dog's sound() method

    }

}


 Output:


Dog barks


 Flow:


Dog overrides sound() → Object is of Dog → Dog's method is called






 5. Encapsulation


 Q5. Program with getter and setter


class Employee {

    private String name;


    public void setName(String n) {

        name = n;

    }


    public String getName() {

        return name;

    }

}


public class Test {

    public static void main(String[] args) {

        Employee e = new Employee();

        e.setName("Ajay");

        System.out.println("Name: " + e.getName());

    }

}


 Output:


Name: Ajay





6. Abstraction


Q6. Abstract class example


abstract class Shape {

    abstract void draw();

}


class Circle extends Shape {

    void draw() {

        System.out.println("Drawing Circle");

    }

}


public class Test {

    public static void main(String[] args) {

        Shape s = new Circle();

        s.draw();

    }

}


 Output:


Drawing Circle





 7. Interface


 Q7. Interface implementation


interface Bank {

    double rateOfInterest();

}


class SBI implements Bank {

    public double rateOfInterest() {

        return 7.0;

    }

}


public class Test {

    public static void main(String[] args) {

        Bank b = new SBI();

        System.out.println("ROI: " + b.rateOfInterest());

    }

}


 Output:


ROI: 7.0





 8. Exception Handling


 Q8. Try-catch-finally example


public class Test {

    public static void main(String[] args) {

        try {

            int a = 10 / 0; // Throws exception

        } catch(ArithmeticException e) {

            System.out.println("Error: " + e.getMessage());

        } finally {

            System.out.println("Finally block executed");

        }

    }

}


 Output:


Error: / by zero

Finally block executed



 9. String Programs


Q9. Reverse a string


public class ReverseString {

    public static void main(String[] args) {

        String s = "Java";

        String rev = "";


        for(int i = s.length() - 1; i >= 0; i--) {

            rev += s.charAt(i);

        }


        System.out.println("Reversed: " + rev);

    }

}


Output:


Reversed: avaJ





 10. Collections (ArrayList)


Q10. Add elements to ArrayList


import java.util.*;


public class Test {

    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();


        list.add("Apple");

        list.add("Banana");

        list.add("Mango");


        for(String fruit : list) {

            System.out.println(fruit);

        }

    }

}


 Output:


Apple

Banana

Mango





 11. Multithreading (Thread)


 Q11. Thread example using Runnable


class MyThread implements Runnable {

    public void run() {

        System.out.println("Thread is running...");

    }

}


public class Test {

    public static void main(String[] args) {

        MyThread obj = new MyThread();

        Thread t = new Thread(obj);

        t.start();

    }

}


 Output:


Thread is running...





 12. File Handling


 Q12. Write to file


import java.io.FileWriter;

import java.io.IOException;


public class WriteFile {

    public static void main(String[] args) {

        try {

            FileWriter writer = new FileWriter("test.txt");

            writer.write("Hello Java!");

            writer.close();

            System.out.println("File written successfully");

        } catch(IOException e) {

            e.printStackTrace();

        }

    }

}


 Output:


File written successfully



English basics example

 To identify parts of speech (noun, verb, adjective, etc.), examine a word’s **function and role** in a sentence. Here’s a step-by-step anal...