You are on page 1of 25

11 Good Study Habits to Develop

Good study habits include finding a quiet location to study, taking breaks,
settings goals, and taking practice tests.
Here's the full list, and the psychological reasons why they work.
Studying can be hard. The good news is that anybody can develop good study habits
to make studying more effective, efficient, and enjoyable.

Want to develop good study habits? Start small—don’t expect to do everything in


this list, at least not right away; pick one or two instead. It’s also important to
set realistic and achievable goals for yourself.

How to Learn:
Powerful mental tools to help you master tough subjects.
You’ll learn the psychology behind procrastination and memory, plus many ways to
help you get the most out of your study time.

Good study habits to develop


Here are 11 tips to improve your study habits:

1.Find a good place to study.


2.Minimize distractions.
3.Take breaks.
4.Space out your studying.
5.Set study goals for each session.
6.Reward yourself.
7.Study with a group.
8.Take practice tests.
9.Use your own words.
10.Ask for help.
11.Take care of yourself.

Skills you'll build:Personal Branding, Planning, Social Capital, Self-Motivation

1. Find a good place to study.


Finding a good location to study is one of the most important elements of studying
well.
Look for a quiet place with minimal distractions—someplace where you’ll be able to
focus, and won’t be interrupted by loud sounds or people who constantly want your
attention.A school or public library, a coffee shop, or a quiet corner of your
house can all be good places to start.

Should I stick to one place to study?


Not necessarily. Some studies show that occasionally changing where you study can
help retain information.
This is because studying the same material in different locations helps your brain
create multiple associations with that material, making it easier for you to
remember it . It can be beneficial to find three or four places you like to study
and switch locations when you’re feeling stuck or need a change of pace. That said,
everybody is different. Find what works best for you.

2. Minimize distractions.
Picking a good location to study can be the first step in keeping yourself focused
on your work.
But there are many types of distractions that can reach you no matter where you
choose to work.
Here are some tips on minimizing these distractions:.Turn off your wifi:
If you’re working on a computer and you don’t need your wifi, try turning it off.
This can keep you from inadvertently wandering into the distracting parts of the
internet.

4.Be mindful of your phone: It’s no secret that our smartphones can be hugely
distracting.
Turning off your notifications, keeping your phone out of sight in your bag, or
giving it to a friend to keep you from checking it too often can help you stay
focused. You might also try a focus app, like Forest or Focus To-Do, that can block
distracting apps and set timers for study sessions.

5.Study with a friend:


Sometimes studying with a friend or two, whether or not you’re working on the same
material, can help keep you accountable and focused.
Make sure you each are on the same page about studying and keeping one another
distraction-free, at least until it’s time to take a break.

Should I listen to music while I study?


Listening to music while you study has some benefits; it can boost your mood and
calm anxiety or stress.
But studies show that reading comprehension tends to fall when the music is too
loud, fast-paced, or contains lyrics
Stick with calming, wordless songs while studying, and save the upbeat numbers for
breaks.

3. Take breaks.
Taking intentional breaks has been linked to better retention, increased attention,
and boosts in energy.
Research shows that working for around 50 minutes, then giving yourself a 15- to
20-minute break, can lead to optimum productivity .
Here are a few ways you can give yourself a break:

1.Take a short walk


2.Listen to a mood-boosting song
3.Relax with a friend
4Stretch
5.Meditate
6.Zone out and daydream
7.Have a snack
8.Take a shower
9.Clean your desk or roomNot all breaks are created equal. Checking your phone or
social media as a study break has actually been linked to a decrease in performance
.

4. Space out your studying.


Cramming can still help you get a good grade on a test, but studies show that
you’re much more likely to forget that information as soon as the test is over.
Really holding onto the material you learned requires consistent and well-spaced
study sessions.

Instead of saving your studying for before a test, briefly review material you
learned once a week. If you are studying for an exam, space out your studying up to
several weeks (or even months, depending on the test) leading up to the exam day.
This can help you retain the information long term.
Work Smarter, Not Harder: Time Management for Personal & Professional Productivity
You will be able to gain and apply your knowledge and understanding of personal and
professional awareness, organization and commitment, and use the tools,
Skills you'll build:Task Management, Management, Planning, Plan

5. Set study goals for each session.


Set study goals for each session of studying you have. These can be time-based or
content-based.
For example, you might aim to study for two hours, or review three chapters of your
textbook—or both.
Don’t be too harsh on yourself if you didn’t get through as much as you had
planned; sometimes studying can take longer than expected.Keep taking well-spaced
breaks, and schedule another study session.

6. Reward yourself.
Rewarding yourself with treats—“bribing” yourself—has been linked to better self-
control, and can be helpful in forming good habits .
Telling yourself you’ll get a small reward if you finish the section you wanted to
get through, or perhaps a larger reward if you have a productive day of studying,
can be good motivation to get to your goal.
Small rewards can be a candy bar, a hot drink from your favorite coffee shop, a
quick game of your choice, or a short episode of a TV show.
Bigger rewards for a long day of studying or getting done with an exam can include
getting your favorite meal, spending some time relaxing with friends, or making
time for your favorite activity.

7. Study with a group.


There are several benefits to forming a study group.
Group members can help one another work through difficult problems, provide
encouragement, hold each other accountable to studying goals, provide different
perspectives, and make studying more enjoyable. Even explaining difficult concepts
to others can help with comprehension and retention.
If you have a group study session, set a goal the group will work towards and take
periodic breaks as you would studying by yourself.

8. Take practice tests.


Tests and practice tests have been long seen as useful tools to help students learn
and retain information.
Besides revealing gaps in knowledge and reducing exam anxiety, being tested makes
us retrieve information from memory—a powerful, study-backed way of holding onto
information we’ve learned .There are several ways you can “test” yourself and gain
the same benefits. Try the following methods:

1.Create flashcards
2.Write your own questions
3.Search for practice questions online

Mindshift is designed to help boost your career and life in today’s fast-paced
learning environment.
Whatever your age or stage, Mindshift teaches you ...Skills you'll build:Learning
To Learn, Lifelong Learning, Pomodoro Technique, Meta Learning

9. Use your own words.


Expressing an idea in your own words increases your understanding of a subject and
helps your brain hang on to information.
After you read a section of text, summarize important points by paraphrasing.

10. Ask for help.


You might find yourself stuck on a problem or unable to understand the explanation
in a textbook.
Somebody who is able to walk through the issue with you might provide the fresh
explanation you need.
Approach your teacher or professor, teaching assistant, friend, or study group
member for new ways to understand what you’re stuck on.
Feel like you can benefit from being coached through a subject? Consider looking
for a tutor.

11. Take care of yourself.


At the end of the day, your brain is an organ in your body—take care of it by
taking care of yourself.
Get regular exercise, eat well, don’t overdrink, get good sleep, and take care of
your mental wellbeing.

Sleep: Studies have linked sleep deprivation to decreased cognitive function,


including reduced attention spans and doing worse on tests .Everybody’s sleep needs
are different, but people typically need between seven and eight-and-a-half hours
of sleep a night.
Plus, getting more sleep can make you happier and benefit your social life.
Food: Try to incorporate more fruits, vegetables, plant sources of proteins, nuts,
and unsaturated oils like olive oil into your diet, all of which have been linked
to better cognitive performance .

Around the world, we find ourselves facing global epidemics of obesity, Type 2
Diabetes and other predominantly diet-related diseases. To address these ...
Skills you'll build:

Health Informatics, Nutrition, Food Safety, Food Science

Exercise: Exercise brings oxygen to the part of your brain responsible for thought,
encourages the development of new nerve cells, and boosts brain cell connections.
This makes for brains that are more neuroplastic and efficient—plus it brings a
host of other health benefits, like lower blood pressure, reduced mental stress,
and weight control.

Mental wellness: Mental health is important because it helps us deal with stress,
improves our relationships with others, allows us to live more meaningfully, and be
more productive in our work. Exercising, eating well, and getting good sleep can
each boost our mental health. But there are other ways of fortifying mental
strength, such as connecting with others, practicing gratitude, meditating, and
developing a sense of meaning in life [9].
Full-Stack Developer Interview Questions Java
Full-stack developers are skilled programmers who can work with both the front-end
and back end of a website and applications.
They are responsible for developing and designing front/ back ends web
architecture, server-side applications, design databases, server-side applications,
and much more.Full-Stack Developer Interview Questions Java

Q.1) What should a full-stack developer know?


Programming Languages: A full-stack developer must have proficient in more than one
programming language like Java, Python, Ruby, C++, etc.
One must familiar with different ways to structure design, implement and test the
project based on the programming language.
1.Front End: One must familiar with the front-end technologies like HTML5, CSS3,
Angular, etc.
The understanding of third-party libraries like jQuery, Ajax, SASS, adds more
advantages.
2.Frameworks: Proficiency in words that are accompanied by development frameworks
.
3.Databases: One must be familiar with at least one database. If you are familiar
with MySQL, Oracle, and MongoDB it is sufficient.
4.Design Ability:The knowledge of prototype design like UI and UX design is also
necessary.

Q.2) What are MVC and MVP and how MVC is different from MVP?
MVC and MVP both are architectural patterns that are used to develop applications.

MVC:MVC stands for Model View Controller.


It is an architectural pattern that is used to develop Java Enterprise
Applications.
It splits an application into three logical components i.e. Model, View, and
Controller.
It separates the business-specific logic (Model component) from the presentation
layer (View component) from each other.

The model components contain data and logic related to it. The View component is
responsible for displaying model objects inside the user interface.
The Controller receives the input and calls model objects based on handler mapping.
It also passes model objects to views in order to display output inside the view
layer.

MVP:
MVP stands for Model View Presenter. It is derived from the MVC architectural
pattern.
It adds an extra layer (known as indirection) to the architectural pattern that
splits the View and Controller into View and Presenter.
The role of Controller is replaced with a Presenter.
It exists at the same level as View in MVC. It contains UI business logic for the
View.
The invocations received from the View directly sends to the Presenter. It
maintains the action (events) between View and Model.
The Presenter does not directly communicate with the View. It communicates through
an interface.

The major difference between MVC and MVP architectural pattern is that in MVC
architectural pattern Controller does not pass the data from the Model to the View.
It only notifies the View to get the data from the Model itself.
While in MVP architectural pattern the View and Model layers are connected with
each other.
The presenter itself receives the data from the Model and sends it to the View to
show.
Another difference is that MVC is often used in web-frameworks while MVP is used in
app development.

3) What is pair programming?


Pair programming is an agile software development technique in which two developer
works together on the same machine (system).
The developer who writes the code is called the driver and the developer who
reviews (checks code, proofread, and spell checks) the code is called the
navigator. The programming technique is more efficient and coding mistakes reduced
to the minimum.
The disadvantage of pair programming is that it increases the cost.

4) What is CORS in MVC and how it works?


CORS stands for Cross-Origin Resource Sharing. It is a W3C standard and HTTP-
header-based mechanism.
It permits a server to indicate any other origins (like domain, port, etc.) instead
of the requested one.
In other words, it enables one website to access the resources of another website
using JavaScript.

It supports secure cross-origin requests and transfers data between servers and
browsers. Advanced browsers use CORS in APIs.
It is flexible and safe in comparison to JSONP (JSON with Padding). It provides
better web service integration.
While using the MVC to enable CORS, the same CORS service can be used but we cannot
use the same CORS middleware.
We can use a particular CORS for a particular action, for a particular controller,
and globally for all controllers.
A pre-flight check (or request) is sent by the browser to the server which ensures
that the server will permit the actual request or not.
For example, invoking the URL https://example.com through https://demo.com.

5) How to enhance a website's scalability and efficiency?


We can use the following ways to optimize the scalability and efficiency of a
website:
1.Reducing DNS lookup
2.Avoiding URL redirects
3.Avoiding duplicate codes
4.Avoiding unnecessary images
5.Leveraging browser caching
6.Deferring parsing of JavaScript
7.Avoiding inline JavaScript and CSS
8.Using srcset for responsive images
9.Placing all assets on a cookie-free domain, preferably using a CDN.

7) What is referential transparency in functional programming?


A program may have the property of referential transparency if any two expressions
in the program that have the same value can be substituted for one another anywhere
in the program without changing the result of the program. It is used in functional
programming.
For example, consider the following code snippet:count1 = (fun(x) + y) * (fun(x) -
z); temp = fun(a); count2 = temp + y * temp - z;
The variables count1 and count2 will be equal if the value of fun(x) is not
reflected.
If the variable count1 is not equal to the variable count2, the referential
transparency is violated.

8) What is RESTful API?


The term REST stands for Representational State Transfer. It is an architectural
style that is used to create Web Services.
It uses HTTP requests to access and use the data. We can create, update, read, and
delete data.
An API (Application Program Interface) for a website is the code that allows two
software programs to communicate with each other.
It allows us to write requesting services from an operating system or other
application.

9) What do you mean by promise, also explain its states?


A promise is an object that can be returned synchronously from an asynchronous
function. It may be in the following three states:
1.Fulfilled: If a promise called the onFulfilled() method, a promise will be in
fulfilled state.
2.Rejected: If a promise called the onRejceted() method, a promise will be in
rejected state.
3.Pending: If a promise is not yet fulfilled or rejected, a promise will be in
pending state.A promise will be settled if and only if it is not pending.
10) How to reduce the load time of a web application?
There are the following ways to optimize the load time of a web application:

1.Optimize image size and format


2.Compress and optimize the content
3.Avoid redirects
4.Cache the web page
5.Minimize the HTTP requests
6.Optimize dependencies
7.Put stylesheet reference at the top
8.Place script reference at the bottom
9.Put JavaScript and CSS externally

Q.11 What is a continuous integration and continuous delivery (CI/CD)?


CI/CD is a best practice to develop applications in which code changes more
frequently and rapidly. Sometimes, it is also known as CI\CD pipeline. It is widely
used in DevOps and also an agile methodology.
Continuous integration is a coding philosophy or deployment practice in which
developers integrate their code in a shared repository several times a day. Because
modern application requires developing code in different platforms. The goal of
continuous integration is to establish an automated mechanism that builds, test,
and package the application.Continuous delivery starts where CI ends. It
automatically delivers the application to the selected infrastructure.
CD ensures the automated delivery of code if any changes are made in the code.

Q.12 Which architectural designs are mostly used to design applications?


In software design, we use the following architectural design patterns:
1.Model View Controller
2.Master-Slave Pattern
3.Layered Pattern
4.Model View Presenter
5.Monolithic Architecture
6.Event-Driven Architecture Pattern

13) What is long polling?


Long polling is an effective method for creating a stable server connection without
using the WebSocket or Server-Side Events protocols.
It operates at the top of the conventional client-server model. Note : Node.js is
using the same technique as the next development model.
In this method, the client sends the request and the server responds until the
connexon is open as it contains new and unique information.
As soon as the server responds, a request to the client can be submitted. When the
data is available, the server will return a query.
It functions when the client application stops and the server ends requests.

Q.14 Explain semantic HTML with an example and why we should use it?
In web design, the idea of using HTML elements to indicate what they actually
are.It is known as semantic HTML or semantic markup.

Semantic HTML is HTML that represents meaning to the web page rather than just
presentation.
For example, tag <p> indicates that a paragraph is enclosed in it.
It is both semantic and presentational because the user know what paragraph are
and the browser also know how to display them.
On the other hand, tags such as <b> and <i> are not semantic.
They only represent how text should look. These tags do not provide any additional
meaning to the markup.
Example of semantic HTML tags are header tags <h1> to <h6>, <abbr>, <cite>, <tt>,
<code>, <blockquote>, <em>, etc.
There are some other semantic HTML tags that are used to build a standards-
compliant website.
We should use the semantic HTML for the following reasons:
It provides additional information about the document in which it is used. It also
aids in communication.
Semantic tags make it clear to the browser what the meaning of a page and its
content is.
It provides information about the contents of those tags that goes beyond just how
they look on a page.
It gives us many more hooks for styling the content of the page.
The clarity of semantic tag is also communicated with search engines that ensure
the right pages are delivered for the right queries.

Q.15 How null is different from undefined in JavaScript?


Null: 1.Null means a variable is assigned with a null value. If we use it with
typeof operator it gives result as an object.
We should never assign a variable to null because the programmer uses it to
represent a variable that has no value.
Note: JavaScript will never automatically assign the value to null.

2.Undefined: Undefined means the variable is declared but not assigned any value to
it. It may be a variable itself does not exist.
If we use it with typeof operator it gives the result undefined. It is not valid in
JSON.
Note: Null and undefined both are primitive.Let's understand it through an example.

var var1
var var2 = null //assigning null value to the variable var2
console.log(`var1 : ${var1}, type : ${typeof(var1)}`)
console.log(`var2 : ${var2}, type : ${typeof(var2)}`)
When we execute the above code, it generates the following output:

Var1 : undefined, type : undefined


var2 : null, type : object
From the above output, we can observe that the value of var1 is undefined also its
type is undefined.
Because we have not assigned any value to the variable var1. The value null is
assigned to the variable var2. It prints its type as abject.
Since null is an assignment value and we can assign it to a variable.
Therefore, JavaScript treats null and undefined relatively equally because both
represent an empty value.

16) What are the key differences between GraphQL and REST?
Both, REST and GraphQL, are API design architectures that can be used to develop
web services, especially for data-driven applications.

GraphQL REST
GraphQL is an API design architecture, but with a different approach that is much
flexible.
REST is a robust methodology and API design architecture used to implement web
services.
It follows client-driven architecture. It follows server-driven architecture.
It does not deal with the dedicated resources. It deals with the dedicated
resources.
It has a single endpoint that takes dynamic parameters. It has multiple
endpoints.
It provides stateless servers and structured access to resources.
It provides stateless servers and flexible controlled access to resources.
It is elastic in nature. It is not rigid in nature.
It supports only JSON format. It supports XML, JSON, HTML, YAML, and other formats
also.
The client defines response data that it needs via a query language. Data
represented as resources over HTTP through URI.
It provides synchronous and asynchronous communication in multiple protocols such
as HTTP, MQTT, AMQP. It provides synchronous communication through HTTP only.
Its design based on HTTP (status, methods, and URI). Its design based on message
exchange.
It provides high consistency across all platforms. It is difficult to achieve
high consistency across all platforms.
Development speed is fast. Development speed is slow.
17) Compare fail-fast and fail-safe iterators?
Basis of Comparison Fail Fast Iterator Fail Safe Iterator
Operates It operates directly on the collection itself. It operates on a cloned
copy of the collection.
Exception It throws a ConcurrentModificationException in modifying the object
during the iteration process. It does not throw Exception.
Clone Object No clone object is created during the iteration process. A copy
or clone object is created during the iteration process.
Memory utilization It requires low memory during the process. It requires
more memory during the process.
Modification It does not allow modification during iteration. It allows
modification during the iteration process.
Performance It is fast. It is slightly slower than Fail Fast.
Examples HashMap, ArrayList, Vector, HashSet, etc. CopyOnWriteArrayList,
ConcurrentHashMap, etc.

18) What is a connection leak in Java and how can we fix it?
In Java, a connection leak is a situation when the developer forgets to close the
JDBC connection, it is known as connection leak.
The most common type of Connection Leak experienced in Java development, is when
using a Connection Pool .
We can fix it by closing the connection and giving special attention to the error
handling code.

19) What are the different methods of session management in Servlet?


A session is a conversational state between client and server and it can consist of
multiple requests and responses between client and server.
Therefore, HTTP and web server both are stateless, the only way to maintain a
session is when some unique information about the session (session-id) is passed
between server and client in every request and response.
We can use the following methods to maintain the session:
1.User Authentication
2.HTML Hidden Field
3.Cookies
4.URL Rewriting
5.Session Management API

Q.20 How ServletContext is differ from ServletConfig?


ServletContext ServletConfig
ServletContext represents the whole web application running on a particular JVM and
common for all the servlet.
ServletConfig object represents single servlet.
It is just like a global parameter associated with the whole application. It is
the same as the local parameter associated with a particular servlet.
It has application-wide scope so define outside servlet tag in the web.xml file.It
is a name-value pair defined inside the servlet section of web.xml files so it has
servlet wide scope.
getServletContext() method is used to get the context object.
getServletConfig() method is used to get the config object.
To get the MIME type of a file or application session related information is stored
using a servlet context object.
The shopping cart of a user is a specific to particular user so here we can use
servlet config.

21) What is a Request Dispatcher?


RequestDispatcher is an interface that is used to forward the request to another
resource that can be HTML, JSP, or another servlet in the same application. We can
also use it to include the content of another resource in the response.
The interface contains two methods forward() and include().
22) What are the differences between constructor injection and setter injection?
Constructor Injection Setter Injection
There is no partial injection of dependencies. There can be a partial injection of
dependencies.
It does not override the setter injection value. It overrides the constructor
injection value if both are defined.
It always creates a new instance if any modification occurs. It does not create
a new instance if we made any changes to it.
Using constructor injection is better for too many properties. Using setter
injection is better for few properties.
It makes bean class objects as immutable. It makes bean class objects as mutable.

23) How many ways to handle exceptions in the Spring MVC Framework?
Spring MVC Framework provides the following ways to handle exceptions:

Controller-Based: We can define the exception handler method in our controller


class.
Global Exception Handler:
Exception handling is a cross-cutting concern that Spring
HandlerExceptionResolver:
Any Spring Bean declared in the DispatcherServlet's application context that
implements will be used to intercept and process any exception raised in the MVC
system and not handled by a Controller.

24) What are the advantages of Hibernate over JDBC?


There are the following advantages of Hibernate over JDBC:
Hibernate removes boilerplate code that comes with JDBC API.
It supports inheritance, associations, and collections that are not present in JDBC
API.It implicitly provides transaction management.
We need not to write a lot of try-catch block code.In Hibernate, HQL is more
object-oriented that is closed to Java programming language.
It provides better performance in comparison to JDBC because Hibernate supports
caching while JDBC does not support caching of queries.

Q25) What is callback hell and how to fix it?


Callback hell is a phenomenon in JavaScript in which the developer tries to execute
multiple asynchronous operations together.
The nesting of callback functions in such a way, we easily end up with error-
prone, hard to read, and hard to maintain code.
We can easily fix it by using the following methods:
1.Split large functions into smaller functions
2.Use Promises
3.Use Async/ Wait

26) What is double brace initialization in Java and where it is used?


In Java, double brace initialization is a combination of two separate processes.
The two consecutive curly braces {{ involved in it.

The first curly brace represents the creation of an anonymous inner class. .
Remember that the second curly brace will not be considered in such a case. It is
just like creating an anonymous inner class.

The second curly brace represents an initialization block that we have seen in it
as a class for initialization.
When we use the initialization block for an anonymous inner class it becomes Java
double brace initialization.
The inner class has a reference to the enclosing outer class. We can use the
reference by using this pointer.
It is used to initialize collections because it is easier to initialize a constant
collection using double brace initialization.

27) How to avoid deadlock in Java?


1Avoid Unnecessary Locks:
We should use locks only for those members on which it is required.
Unnecessary use of locks leads to a deadlock situation. It is recommended that use
a lock-free data structure.
If possible, keep your code free from locks.For example, instead of using
synchronized ArrayList use the ConcurrentLinkedQueue.

2.Avoid Nested Locks:


Another way to avoid deadlock is to avoid giving a lock to multiple threads if we
have already provided a lock to one thread.
Since we must avoid allocating a lock to multiple threads.

3.Using Thread.join() Method:


We can get a deadlock if two threads are waiting for each other to finish
indefinitely using thread join.
If a thread has to wait for another thread to finish, it's always best to use join
with the maximum time you want to wait for the thread to finish.

4.Use Lock Ordering: Always assign a numeric value to each lock.


Before acquiring the lock with a higher numeric value, acquire the locks with a
lower numeric value.

5.Lock Time-out: We can also specify the time for a thread to acquire a lock.
If a thread does not acquire a lock, the thread must wait for a specific time
before retrying to acquire a lock.

28) What is a critical section?


The critical section is a part of code in multi-threading that must be exclusively
modified by any thread.
The critical section is protected by Semaphore or mutex. In Java, there are two
ways to protect critical section:
1.Using Synchronized keyword 2.Using Reentrant Locks

29) What is numeric promotion?


The conversion of a smaller numeric type to a larger numeric type is known as
numeric promotion.
In this type, byte, char, and short values are converted to int values. The int
values are converted to long values, if necessary. The long and float values are
converted to double values, as needed.

30) What is the SOLID principle in Java?


In Java, SOLID principles are an object-oriented approach that are applied to
software structure design.
It is conceptualized by Robert C. Martin (also known as Uncle Bob).These five
principles have changed the world of object-oriented programming, and also changed
the way of writing software. It also ensures that the software is modular, easy to
understand, debug, and refactor.

The word SOLID acronym for:

1.Single Responsibility Principle (SRP)


2 Open-Closed Principle (OCP)
3.Liskov Substitution Principle (LSP)
4.Interface Segregation Principle (ISP)
5.Dependency Inversion Principle (DIP)

Q.1 What is C language?


C is a mid-level and procedural programming language.
The Procedural programming language is also known as the structured programming
language is a technique in which large programs are broken down into smaller
modules, and each module uses structured code.This technique minimizes error and
misinterpretation.

Q.2 Why is C known as a mother language?


C is known as a mother language because most of the compilers and JVMs are written
in C language.
Most of the languages which are developed after C language has borrowed heavily
from it like C++, Python, Rust, javascript, etc.
It introduces new core concepts like arrays, functions, file handling which are
used in these languages.

Q.3 Why is C called a mid-level programming language?


C is called a mid-level programming language because it binds the low level and
high -level programming language.
We can use C language as a System programming to develop the operating system as
well as an Application programming

4) Who is the founder of C language?


Ans Dennis Ritchie.

5) When was C language developed?


Ans C language was developed in 1972 at bell laboratories of AT&T. More details.

6) What are the features of the C language?


Ans The main features of C language are given below:

1.Simple C is a simple language because it follows the structured


approach, i.e.a program is broken into small parts.
2.Portable C is highly portable means that once the program is written can
be run on any machine with little or no modifications.
3.Mid Level C is a mid-level programming language as it combines the low-
level language with the features of the high-level language.
4.Structured C is a structured language as the C program is broken into
parts.
5.Fast Speed C language is very fast as it uses a powerful set of data types
and operators.
6.Memory Management C provides an inbuilt memory function that saves the memory and
improves the efficiency of our program.
7.Extensible: C is an extensible language as it can adopt new features in
the future.
7) What is the use of printf() and scanf() functions?
The printf() function is used to print the integer, character, float and string
values on to the screen.

Following are the format specifier:


1.%d: It is a format specifier used to print an integer value.
2.%s: It is a format specifier used to print a string.
3.%c: It is a format specifier used to display a character value.
4.%f: It is a format specifier used to display a floating point value.
5.scanf(): The scanf() function is used to take input from the user.

8) What is the difference between the local variable and global variable in C?
Following are the differences between a local variable and global variable:
Basis for comparison Local variable
Global variable
Declaration A variable which is declared inside function or block is known
as a local variable. A variable which is declared outside function or
block is known as a global variable.
Scope The scope of a variable is withina function in which they are declared.
The scope of a variable is available throughout the program.
Access Variables can be accessed only by those statements inside a function in
which declared Any statement in the entire program can access variables.
Life Life of a variable is created when the function block is entered and
destroyed . Life of a variable exists until the program is executing.
Storage Variables are stored in a stack unless specified. The compiler
decides the storage location of a variable.

9) What is the use of a static variable in C?


Following are the uses of a static variable:
1.A variable which is declared as static is known as a static variable.
2.The static variable retains its value between multiple function calls.
3.Static variables are used because the scope of the static variable is available
in the entire program.
4.So, we can access a static variable anywhere in the program.The static variable
is initially initialized to zero.
5.If we update the value of a variable, then the updated value is assigned.The
static variable is used as a common value which is shared by all the methods.
The static variable is initialized only once in the memory heap to reduce the
memory usage.

10) What is the use of the function in C?


Ans Uses of C function in C are:
1.C functions are used to avoid the rewriting the same code again and again in our
program.
2.C functions can be called any number of times from any place of program.
When a program is divided into functions,then any part of our program canbetracked.
3.C functions provide the reusability concept, i.e., it breaks the big task into
smaller tasks so that it makes the C program more understandable.

11) What is the difference between call by value and call by reference in C?
Following are the differences between a call by value and call by reference are:

Call by value
Call by reference
Description When a copy of the value is passed to the function, then the original
value is not modified. When a copy of the value is passed to the
function, then the original value is modified.
Memory location Actual arguments and formal arguments are created in separate
memory locations. Actual arguments and formal arguments are
created in the same memory location.
Safety In this case, actual arguments remain safe as they cannot be
modified.In this case, actual arguments are not reliable, as they are modified.
Arguments The copies of the actual arguments are passed to the formal arguments.
The addresses of actual arguments are passed to their respective formal arguments.

Example of call by value:


#include <stdio.h>
void change(int,int);
int main()
{
int a=10,b=20;
change(a,b); //calling a function by passing the values of variables.
printf("Value of a is: %d",a);
printf("\n");
printf("Value of b is: %d",b);
return 0;
}
void change(int x,int y)
{
x=13;
y=17;
}
Output:Value of a is: 10 Value of b is: 20

Example of call by reference:


#include <stdio.h>
void change(int*,int*);
int main()
{
int a=10,b=20;
change(&a,&b); // calling a function by passing references of variables.
printf("Value of a is: %d",a);
printf("\n");
printf("Value of b is: %d",b);
return 0;
}
void change(int *x,int *y)
{
*x=13;
*y=17;
}
Output:

Value of a is: 13
Value of b is: 17

12) What is recursion in C?


When a function calls itself, and this process is known as recursion. The function
that calls itself is known as a recursive function.
Recursive function comes in two phases:
1.Winding phase 2.Unwinding phase
1.Winding phase: When the recursive function calls itself, and this phase ends when
the condition is reached.
2.Unwinding phase: Unwinding phase starts when the condition is reached, and the
control returns to the original call.

Example of recursion
#include <stdio.h>
int calculate_fact(int);
int main()
{
int n=5,f;
f=calculate_fact(n); // calling a function
printf("factorial of a number is %d",f);
return 0;
}
int calculate_fact(int a)
{
if(a==1)
{
return 1;
}
else
return a*calculate_fact(a-1); //calling a function recursively.
}
Output:

factorial of a number is 120

Q13) What is an array in C?


An Array is a group of similar types of elements. It has a contiguous memory
location.
It makes the code optimized, easy to traverse and easy to sort. The size and type
of arrays cannot be changed after its declaration.

Arrays are of two types:


1.One-dimensional array:
One-dimensional array is an array that stores the elements one after the another.
Syntax:data_type array_name[size];
2.Multidimensional array: Multidimensional array is an array that contains more
than one array.
Syntax: data_type array_name[size];
Example of an array:
#include <stdio.h>
int main()
{
int arr[5]={1,2,3,4,5}; //an array consists of five integer values.
for(int i=0;i<5;i++)
{
printf("%d ",arr[i]);
}
return 0;
}
Output:

1 2 3 4 5
.
14) What is a pointer in C?
A pointer is a variable that refers to the address of a value. It makes the code
optimized and makes the performance fast.
Whenever a variable is declared inside a program, then the system allocates some
memory to a variable. The memory contains some address number.
The variables that hold this address number is known as the pointer variable.

For example:
Data_type *p;
The above syntax tells that p is a pointer variable that holds the address number
of a given data type value.

Example of pointer
#include <stdio.h>
int main()
{
int *p; //pointer of type integer.
int a=5;
p=&a;
printf("Address value of 'a' variable is %u",p);
return 0;
}
Output:Address value of 'a' variable is 428781252

Q15 What is the usage of the pointer in C?


Accessing array elements:
Pointers are used in traversing through an array of integers and strings.
The string is an array of characters which is terminated by a null character '\0'.

Dynamic memory allocation:


Pointers are used in allocation and deallocation of memory during the execution of
a program.

Call by Reference:The pointers are used to pass a reference of a variable to other


function.
Data Structures like a tree, graph, linked list, etc.:
The pointers are used to construct different data structures like tree, graph,
linked list, etc.

Q16 What is a NULL pointer in C?


A pointer that doesn't refer to any address of value but NULL is known as a NULL
pointer. When we assign a '0' value to a pointer of any type, then it becomes a
Null pointer.

17) What is a far pointer in C?


A pointer which can access all the 16 segments (whole residence memory) of RAM is
known as far pointer.
A far pointer is a 32-bit pointer that obtains information outside the memory in a
given section.

18) What is dangling pointer in C?


If a pointer is pointing any memory location, but meanwhile another pointer deletes
the memory occupied by the first pointer while the first pointer still points to
that memory location, the first pointer will be known as a dangling pointer.

This problem is known as a dangling pointer problem.Dangling pointer arises when an


object is deleted without modifying the value of the pointer.
The pointer points to the deallocated memory. an example.
#include<stdio.h>
void main()
{
int *ptr = malloc(constant value); //allocating a memory space.
free(ptr); //ptr becomes a dangling pointer.
}
In the above example, initially memory is allocated to the pointer variable ptr,
and then the memory is deallocated from the pointer variable.
Now, pointer variable, i.e., ptr becomes a dangling pointer.How to overcome the
problem of a dangling pointer
The problem of a dangling pointer can be overcome by assigning a NULL value to the
dangling pointer. Let's understand this through an example:

#include<stdio.h>
void main()
{
int *ptr = malloc(constant value); //allocating a memory space.
free(ptr); //ptr becomes a dangling pointer.
ptr=NULL; //Now, ptr is no longer a dangling pointer.
}
In the above example, after deallocating the memory from a pointer variable, ptr is
assigned to a NULL value.
This means that ptr does not point to any memory location. Therefore, it is no
longer a dangling pointer.

19) What is pointer to pointer in C?


In case of a pointer to pointer concept, one pointer refers to the address of
another pointer.
The pointer to pointer is a chain of pointers. Generally, the pointer contains the
address of a variable.
The pointer to pointer contains the address of a first pointer. Let's understand
this concept through an example:

#include <stdio.h>
int main()
{
int a=10;
int *ptr,**pptr; // *ptr is a pointer and **pptr is a double pointer.
ptr=&a;
pptr=&ptr;
printf("value of a is:%d",a);
printf("\n");
printf("value of *ptr is : %d",*ptr);
printf("\n");
printf("value of **pptr is : %d",**pptr);
return 0;
}
In the above example, pptr is a double pointer pointing to the address of the ptr
variable and ptr points to the address of 'a' variable.

20) What is static memory allocation?


In case of static memory allocation, memory is allocated at compile time, and
memory can't be increased while executing the program.
It is used in the array.The lifetime of a variable in static memory is the lifetime
of a program.
The static memory is allocated using static keyword.
The static memory is implemented using stacks or heap.
The pointer is required to access the variable present in the static memory.The
static memory is faster than dynamic memory.
In static memory, more memory space is required to store the variable.
For example: int a[10]; The above example creates an array of integer type, and
the size of an array is fixed, i.e., 10.

21) What is dynamic memory allocation?


In case of dynamic memory allocation, memory is allocated at runtime and memory can
be increased while executing the program. It is used in the linked list.
The malloc() or calloc() function is required to allocate the memory at the
runtime.
An allocation or deallocation of memory is done at the execution time of a program.
No dynamic pointers are required to access the memory.The dynamic memory is
implemented using data segments.Less memory space is required to store variable.
For example: int *p= malloc(sizeof(int)*10); This is used to allocates the memory
at runtime.

22) What functions are used for dynamic memory allocation in C language?
1.malloc():-The malloc() function is used to allocate the memory during the
execution of the program.
It does not initialize the memory but carries the garbage value.
It returns a null pointer if it could not be able to allocate the requested space.
Syntax:- ptr = (cast-type*) malloc(byte-size) // allocating the memory using
malloc() function.
2.calloc()
The calloc() is same as malloc() function, but the difference only is that it
initializes the memory with zero value.
Syntax:ptr = (cast-type*)calloc(n, element-size);// allocating the memory using
calloc() function.
realloc()
3.The realloc() function is used to reallocate the memory to the new size.
If sufficient space is not available in the memory, then the new block is allocated
to accommodate the existing data.
Syntax:- ptr = realloc(ptr, newsize); // updating the memory size using realloc()
function. ptr is allocated to a new size.

4.free():The free() function releases the memory allocated by either calloc() or


malloc() function.
Syntax:-free(ptr); // memory is released using free() function.
The above syntax releases the memory from a pointer variable ptr.

23) What is the difference between malloc() and calloc()?


calloc() malloc()
Description The malloc() function allocates a single block of requested memory.
The calloc() function allocates multiple blocks of requested memory.
Initialization It initializes the content of the memory to zero. It does not
initialize the content of memory, so it carries the garbage value.
Number of arguments It consists of two arguments. It consists of only one
argument.
Return value It returns a pointer pointing to the allocated memory. It
returns a pointer pointing to the allocated memory.
More details.

24) What is the structure?


The structure is a user-defined data type that allows storing multiple types of
data in a single unit.
It occupies the sum of the memory of all members.The structure members can be
accessed only through structure variables.
Structure variables accessing the same structure but the memory allocated for each
variable will be different.
Syntax of structure
struct structure_name
{
Member_variable1;
Member_variable2
}[structure variables];
Let's see a simple example.
#include <stdio.h>
struct student
{
char name[10]; // structure members declaration.
int age;
}s1; //structure variable
int main()
{
printf("Enter the name");
scanf("%s",s1.name);
printf("\n");
printf("Enter the age");
scanf("%d",&s1.age);
printf("\n");
printf("Name and age of a student: %s,%d",s1.name,s1.age);
return 0;
}
Output:

Enter the name shikha


Enter the age 26
Name and age of a student: shikha,26
More details.

25) What is a union?


The union is a user-defined data type that allows storing multiple types of data in
a single unit.
However, it doesn't occupy the sum of the memory of all members. It holds the
memory of the largest member only.
In union, we can access only one variable at a time as it allocates one common
space for all the members of a union.
Syntax of union
union union_name
{
Member_variable1;
Member_variable2;
Member_variable n;
}
[union variables];

#include<stdio.h>
union data
{
int a; //union members declaration.
float b;
char ch;
};
int main()
{
union data d; //union variable.
d.a=3;
d.b=5.6;
d.ch='a';
printf("value of a is %d",d.a);
printf("\n");
printf("value of b is %f",d.b);
printf("\n");
printf("value of ch is %c",d.ch);
return 0;
}
In the above example, the value of a and b gets corrupted, and only variable ch
shows the actual output.
This is because all the members of a union share the common memory space. Hence,
the variable ch whose value is currently updated.

26) What is an auto keyword in C?


In C, every local variable of a function is known as an automatic (auto) variable.
Variables which are declared inside the function block are known as a local
variable.
The local variables are also known as an auto variable. It is optional to use an
auto keyword before the data type of a variable.
If no value is stored in the local variable, then it consists of a garbage value.

27) What is the purpose of sprintf() function?


The sprintf() stands for "string print." The sprintf() function does not print the
output on the console screen.
It transfers the data to the buffer. It returns the total number of characters
present in the string.

28) Can we compile a program without main() function?


Yes, we can compile, but it can't be executed.

But, if we use #define, we can compile and run a C program without using the main()
function. For example:

#include<stdio.h>
#define start main
void start() {
printf("Hello");
}
More details.

29) What is a token?


The Token is an identifier. It can be constant, keyword, string literal, etc.
A token is the smallest individual unit in a program. C has the following tokens:

1.Identifiers: Identifiers refer to the name of the variables.


2.Keywords: Keywords are the predefined words that are explained by the compiler.
3.Constants: Constants are the fixed values that cannot be changed during the
execution of a program.
4.Operators: An operator is a symbol that performs the particular operation.
5.Special characters: All the characters except alphabets and digits are treated as
special characters.

30) What is command line argument?


The argument passed to the main() function while executing the program is known as
command line argument. For example:
main(int count, char *args[]){ //code to be executed }

31) What is the acronym for ANSI?


The ANSI stands for " American National Standard Institute." It is an organization
that maintains the broad range of disciplines including photographic film, computer
languages, data encoding, mechanical parts, safety and more.

32) What is the difference between getch() and getche()?


The getch() function reads a single character from the keyboard. It doesn't use any
buffer, so entered data will not be displayed on the output screen.
The getche() function reads a single character from the keyword, but data is
displayed on the output screen. Press Alt+f5 to see the entered character. simple
example
#include<stdio.h>
#include<conio.h>
int main()
{

char ch;
printf("Enter a character ");
ch=getch(); // taking an user input without printing the value.
printf("\nvalue of ch is %c",ch);
printf("\nEnter a character again ");
ch=getche(); // taking an user input and then displaying it on the screen.
printf("\nvalue of ch is %c",ch);
return 0;
}
Output:

Enter a character
value of ch is a
Enter a character again a
value of ch is a
In the above example, the value entered through a getch() function is not displayed
on the screen while the value entered through a getche() function is displayed on
the screen.

33) What is the newline escape sequence?


The new line escape sequence is represented by "\n". It inserts a new line on the
output screen.

34) Who is the main contributor in designing the C language after Dennis Ritchie?
Brain Kernighan.
35) What is the difference between near, far and huge pointers?
A virtual address is composed of the selector and offset.
A near pointer doesn't have explicit selector whereas far, and huge pointers have
explicit selector.
When you perform pointer arithmetic on the far pointer, the selector is not
modified, but in case of a huge pointer, it can be modified.
These are the non-standard keywords and implementation specific. These are
irrelevant in a modern platform.

36) What is the maximum length of an identifier?


It is 32 characters ideally but implementation specific.

37) What is typecasting?


The typecasting is a process of converting one data type into another is known as
typecasting.
If we want to store the floating type value to an int type, then we will convert
the data type into another data type explicitly.
Syntax:(type_name) expression;

38) What are the functions to open and close the file in C language?
The fopen() function is used to open file whereas fclose() is used to close file.

39) Can we access the array using a pointer in C language?


Yes, by holding the base address of array into a pointer, we can access the array
using a pointer.

40) What is an infinite loop?


A loop running continuously for an indefinite number of times is called the
infinite loop.
Infinite For Loop:for(;;){ //code to be executed }
Infinite While Loop:
while(1){ //code to be executed }
Infinite Do-While Loop:
do{
//code to be executed
}
while(1);

41) Write a program to print "hello world" without using a semicolon?


#include<stdio.h>
void main(){
if(printf("hello world")){} // It prints the ?hello world? on the screen.
}

42) Write a program to swap two numbers without using the third variable?
#include<stdio.h>
#include<conio.h>
main()
{
int a=10, b=20; //declaration of variables.
clrscr(); //It clears the screen.
printf("Before swap a=%d b=%d",a,b);

a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)

printf("\nAfter swap a=%d b=%d",a,b);


getch();
}
More details.
43) Write a program to print Fibonacci series without using recursion?
#include<stdio.h>
#include<conio.h>
void main()
{
int n1=0,n2=1,n3,i,number;
clrscr();
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);//printing 0 and 1

for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed


{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
getch();
}
More details.
44) Write a program to print Fibonacci series using recursion?
#include<stdio.h>
#include<conio.h>
void printFibonacci(int n) // function to calculate the fibonacci series of a given
number.
{
static int n1=0,n2=1,n3; // declaration of static variables.
if(n>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
printf("%d ",n3);
printFibonacci(n-1); //calling the function recursively.
}
}
void main(){
int n;
clrscr();
printf("Enter the number of elements: ");
scanf("%d",&n);
printf("Fibonacci Series: ");
printf("%d %d ",0,1);
printFibonacci(n-2);//n-2 because 2 numbers are already printed
getch();
}
More details.
45) Write a program to check prime number in C Programming?
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,m=0,flag=0; //declaration of variables.
clrscr(); //It clears the screen.
printf("Enter the number to check prime:");
scanf("%d",&n);
m=n/2;
for(i=2;i<=m;i++)
{
if(n%i==0)
{
printf("Number is not prime");
flag=1;
break; //break keyword used to terminate from the loop.
}
}
if(flag==0)
printf("Number is prime");
getch(); //It reads a character from the keyword.
}
More details.
46) Write a program to check palindrome number in C Programming?
#include<stdio.h>
#include<conio.h>
main()
{
int n,r,sum=0,temp;
clrscr();
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number ");
else
printf("not palindrome");
getch();
}
More details.
47) Write a program to print factorial of given number without using recursion?
#include<stdio.h>
#include<conio.h>
void main(){
int i,fact=1,number;
clrscr();
printf("Enter a number: ");
scanf("%d",&number);

for(i=1;i<=number;i++){
fact=fact*i;
}
printf("Factorial of %d is: %d",number,fact);
getch();
}

48) Write a program to print factorial of given number using recursion?


#include<stdio.h>
#include<conio.h>
long factorial(int n) // function to calculate the factorial of a given number.
{
if (n == 0)
return 1;
else
return(n * factorial(n-1)); //calling the function recursively.
}
void main()
{
int number; //declaration of variables.
long fact;
clrscr();
printf("Enter a number: ");
scanf("%d", &number);
fact = factorial(number); //calling a function.
printf("Factorial of %d is %ld\n", number, fact);
getch(); //It reads a character from the keyword.
}

Q.49 Write a program to check Armstrong number in C?


#include<stdio.h>
#include<conio.h>
main()
{
int n,r,sum=0,temp; //declaration of variables.
clrscr(); //It clears the screen.
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
getch(); //It reads a character from the keyword.
}

Q.50 Write a program to reverse a given number in C?


#include<stdio.h>
#include<conio.h>
main()
{
int n, reverse=0, rem; //declaration of variables.
clrscr(); // It clears the screen.
printf("Enter a number: ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf("Reversed Number: %d",reverse);
getch();
// It reads a character from the keyword.
}

You might also like