1. What are the types of variable in JavaScript? Ans: Two types of variables Local variable Global variable 2. What is the use of typeof in JavaScript? Ans: It is used to find the datatype of variable. 3. How to create Objects in JavaScript? Ans: Three ways to create Objects in JavaScript. By object literal. By creating instance of object. By object constructor. 4. How to create an Array in JavaScript? Ans: Three ways to create Array in JavaScript. By array literal. By creating instance of array. By using an Array constructor. 5. What are the pop-up boxes available in JavaScript? Ans: Three kinds of Pop-up boxes available in JavaScript. Alert box Confirm box Prompt box 6. How to set the cursor to wait in JavaScript? Ans: The cursor can be set to wait in JavaScript by using property “cursor”. Ex: <script> window.document.body.style.cursor=”wait”; </script> 7. What is the use of debugger Keyword in JavaScript? Ans: JavaScript debugger keyword sets the breakpoint through the code itself. The debugger stops the execution of the program at the position it is applied. 8. What do you understand by Hoisting in JavaScript? Ans: Hoisting is the default behavior of JavaScript, where all the variable and function declarations are moved on top. They are moved on the top of scope. The scope can be both local and global. 9. What is Anonymous Functions? Ans: Function without a name is known as Anonymous function. In JavaScript, we can pass a function as an argument, that’s where the anonymous functions will be used. 10. What is Function Expressions? Ans: If a function can be referred with a variable, then it is known as Function Expressions. 11. What is First Class Functions? Ans: If a function can be passed as an argument, referred with a variable and returned from another function then we call those functions as first class functions. 12. Difference between Normal and Arrow function in JavaScript? Ans: Normal function return value and is declared using function keyword whereas Arrow function does not return any value and it can be declared without using function keyword. 13. What is Closures? Ans: A Closure is a scope that gets formed when a function(inner) is created inside another function. The reason to create inner functions is to create private functions. 14. Is it possible that what we create an object can’t be modified? Ans: Yes it is possible that whatever object we create can’t be modified. Ex: var v1= Object.freeze({ }); 15. What is Scopes and it’s type? Ans: Scopes determines the accessibility(visibility) of variables. There are several types of scopes: Local Scope Global Scope Functional Scope Block Scope 16. What is the Scope of var, let and const? Ans: Var is a functional scope whereas let and const are block scope. 17. What is Variable shadowing? Ans: Variable shadowing occurs when a inner scope declares a variable name which is same as of outer scope variable. If we try to shadow let variable by var variable it is known as illegal shadowing and it give us the error that variable is already define. But if we try to shadow var variable by let variable it will work. 18. What is Arrow Function? Ans: Function without a name and are not bounded by an identifier. Arrow function do not return any value and can be declared without the function keyword. It is also known as lambda function. 19. What is Callback Function? Ans: Passing function definition as a parameter/argument to another function is called as Callback function. Syntax: Function x() { } function y(x){ } y(x); 20. What is promises? Ans: A Promises is an object that represent the completion or failure of an asynchronous operation. Asynchronous operation: Task that will be executed after certain period of time. Syntax: Const Promise= new Promise(function(resolve, reject){ resolve (value); reject (value); }); Promise.then(function(response) { //success dependent statements }).catch(function(error){ //failure dependent statements }); 21. What is Shift and unshift in JavaScript? Ans: Shift function is used to remove first element from array whereas Unshift function is used to add element in the first position of array. Ex: Shift var a=[1,2,3,4,5]; a.Shift(); console.log(a); o/p – [2,3,4,5] UnShift var b=[2,3,4,5]; b.unShift(7); console.log(b); o/p – [7,2,3,4,5] 22. What is Call, Apply and Bind Function? Ans: Call: It is used to call a function of other object by substituting another object. Ex: var obj1= { name: “aman” , addr: “HYD”,
HTML and CSS Interview Questions
Ever walked into an interview feeling like you knew your stuff, only to get stumped by a “simple” question on the box model or semantic tags? Yeah, I’ve been there. Early in my web dev career, I bombed a few rounds because I treated HTML and CSS as basics I could wing. Big mistake. These foundations are what interviewers love to probe—testing not just knowledge, but how you think about real-world application. That’s why I put together this list of 40 questions and answers. It’s drawn from my own experiences interviewing and being interviewed, plus patterns I’ve seen in tech job hunts over the years. We’ll start with the fundamentals and build up to trickier stuff. Each question gets a clear, complete answer with practical tips or examples. Read through, practice explaining them out loud, and you’ll walk in confident. Let’s dive in. 1) What is HTML, and what problem does it solve? HTML, or HyperText Markup Language, is the backbone of web pages—it structures content so browsers can display it properly. Think of it as the skeleton: it organizes text, images, links, and forms using tags like <p> for paragraphs or <img> for images. The big problem it solves? Turning raw text into interactive, accessible web experiences that work across devices, from phones to desktops. Without HTML, the internet would just be a mess of unformatted data. 2) What is CSS, and why is it separated from HTML? CSS stands for Cascading Style Sheets, and it’s all about making HTML look good—handling colors, layouts, fonts, spacing, and even animations. We keep it separate from HTML to follow the “separation of concerns” principle: HTML handles structure and meaning, while CSS focuses on presentation. This setup makes sites easier to maintain (change one stylesheet, update everywhere) and more efficient for teams—designers tweak styles without messing with content. 3) What’s new in HTML5 compared to earlier HTML versions? HTML5 brought a ton of upgrades that made web development smoother. Key additions include semantic tags like <header>, <nav>, <main>, <section>, <article>, <aside>, and <footer> for better structure; native support for <audio> and <video> (no more plugins!); the <canvas> element for drawing graphics; new form features like input types (email, date) and validation attributes (required, pattern); plus storage options like localStorage and sessionStorage, and APIs for geolocation. It basically made sites more interactive and accessible without relying on extra tech. 4) What are semantic HTML elements, and why do they matter? Semantic elements are tags that describe what the content means, not just how it looks—like <nav> for navigation menus, <article> for standalone posts, or <footer> for bottom-of-page info. They matter because they boost accessibility (screen readers can navigate better), improve SEO (search engines understand the structure), and make code more readable for developers. Using them properly helps everyone—from your users to future teammates. 5) Explain the difference between block-level and inline elements. Block-level elements (like <div>, <p>, <h1>) take up the full width available and always start on a new line—think of them as stacking vertically. Inline elements (like <span>, <a>, <strong>) only take up as much width as their content and flow within a line, like words in a sentence. Knowing this distinction is crucial for layout: use block-level for structure, inline for styling pieces of text or small content chunks. 6) What are HTML attributes? Give examples. Attributes are extra information added to HTML tags that modify their behavior. They’re written inside the opening tag. For example: <a href=”https://example.com”>Link</a> uses the href attribute to define the URL; <img src=”photo.jpg” alt=”Profile picture”> uses src to specify the image file and alt to provide alternative text for accessibility. Attributes let you fine-tune how elements work and interact. 7) Explain the difference between relative, absolute, and fixed positioning in CSS. Relative positioning moves an element relative to its normal position using top, left, right, or bottom. Absolute positioning removes an element from the normal flow and positions it relative to its nearest positioned ancestor (not the viewport, unless none exists). Fixed positioning locks an element to the viewport, so it stays put while scrolling—like sticky navigation bars. Each mode serves different layout needs. 8) What’s the difference between inline, internal, and external CSS? Inline CSS applies styles directly to an element via the style attribute (e.g., <p style=”color:red”>). Internal CSS goes inside a <style> block in the <head> of the HTML file. External CSS is stored in a separate .css file linked via <link>. Inline is quick but messy, internal is good for single-page tweaks, and external is best for consistency and maintainability across multiple pages. 9) What are pseudo-classes in CSS? Give examples. Pseudo-classes define special states of elements. For example: :hover applies styles when you mouse over a link; :focus applies when an input field is active; :nth-child(2) targets the second child in a list. They let you style dynamic interactions and patterns without adding extra classes or JavaScript. 10) Explain the CSS box model. The box model is how browsers calculate the space an element takes. Every element is a box with four layers: content (text, images), padding (space around content), border (edge), and margin (space outside). For example, if a div has 200px width, 10px padding, 5px border, and 20px margin, the total space it occupies horizontally is 200 + 10+10 + 5+5 + 20+20 = 270px. Mastering this is essential for layout debugging. 11) What’s the difference between id and class in HTML? An id is a unique identifier for a single element (e.g., <div id=”header”>), while a class can be shared by multiple elements (e.g., <p>). In CSS, you target ids with #idName and classes with .className. Use ids for unique elements and classes for groups of elements that share styles. 12) What are media queries in CSS? Media queries allow you to apply styles conditionally based on device properties like screen size, resolution, or orientation. For example: @media (max-width: 600px) { body { font-size:
Core Java Technical Interview Questions and Answers for Freshers
Landing your first Java job starts with nailing the basics. Recruiters often grill freshers on Core Java concepts, so mastering these 29 frequently asked questions will give you the confidence—and the vocabulary—to shine in any interview room. Q1. How do JDK and JRE differ? The JDK (Java Development Kit) contains tools to write, compile, and debug Java code. In contrast, the JRE (Java Runtime Environment) only provides the libraries and JVM needed to run already compiled Java applications. Simply put, you need the JDK to build; you need the JRE to execute. Q2. Why is Java platform independent? Java achieves platform independence through the Java Virtual Machine (JVM). When you compile your source code, the Java compiler produces bytecode—a universal format. Any JVM on Windows, macOS, or Linux then interprets that bytecode, so you write once and run anywhere. Q3. What is an Access Modifier? An access modifier controls where classes, methods, and variables can be accessed in your code. It’s your tool to enforce encapsulation and protect internal details. Q4. Which Access Modifiers does Java offer? Java provides four levels of access:private: visible only within the same classdefault (no keyword): visible within the same packageprotected: visible to the same package and subclassespublic: visible everywhere Q5. Abstract class vs. Interface: What sets them apart? An abstract class can hold both concrete methods and fields, and you can extend only one abstract class per class. An interface defines pure method signatures (and constants). Since Java 8, interfaces can also have default and static methods, and you can implement multiple interfaces. Q6. How does stack memory differ from heap memory? The stack stores local variables and method calls in a last-in, first-out structure. It’s fast and short-lived. The heap holds all objects and instance data; it’s larger, garbage-collected, and has a longer lifespan. Q7. Method overloading vs. method overriding? Overloading: Multiple methods share the same name but differ in parameter lists within the same class.Overriding: A subclass redefines a parent class method with the same signature, enabling runtime polymorphism. Q8. Private vs. Protected: What’s the difference? private members are accessible only within their defining class.protected members extend that visibility to subclasses (even in different packages) and to other classes in the same package. Q9. What is constructor overloading in Java? Constructor overloading lets you create multiple constructors with different parameter lists in a class. Each constructor initializes objects in a distinct way, making object creation flexible. Q10. Static methods, variables, and classes—how do they differ? static variables belong to the class, not any instance.static methods can run without an object reference and can only access other static members.static nested classes behave like top-level classes but are scoped inside another class. Q11. Why is main method static? Declaring public static void main(String[] args) makes Java invoke your program’s entry point without creating an object first. It’s the JVM’s requirement to kick off execution. Q12. Does Java use a compiler or an interpreter? Java uses both. The compiler transforms source code into bytecode, while the JVM’s interpreter (and JIT compiler) executes that bytecode at runtime. Q13. What is a package in Java? A package groups related classes and interfaces. It helps you organize code, avoid name conflicts, and control access with package-level visibility. Q14. Why do we need Wrapper classes in collections? Java collections only handle objects, not primitives. Wrapper classes (e.g., Integer, Double) let you store primitive values in ArrayList, HashMap, and other collections seamlessly. Q15. What are Control Statements? Control statements decide the flow of execution:Selection: if, else if, else, switchIteration: for, while, do-while, enhanced forTransfer: break, continue, return Q16. Why use else-if over switch if switch is faster? A switch offers quick lookup for discrete constants (int, enum, String), but it can’t evaluate ranges or complex conditions. Interviewers favor else-if for its flexibility to handle any boolean expression. Q17. When to use for, while, and do-while loops? for: When you know the iteration count ahead of time.while: When the loop should continue until a condition changes.do-while: When you must execute the loop body at least once before checking the condition. Q18. What is Type Casting? Type casting converts one data type to another:Implicit (widening): int → longExplicit (narrowing): double → int using a cast operator Q19. What is a Functional Interface? A Functional Interface defines exactly one abstract method. They power Java’s lambda expressions and method references (@FunctionalInterface ensures compliance). Q20. What is the purpose of instanceof? The instanceof operator checks at runtime whether an object belongs to a particular class or implements a specific interface, preventing ClassCastException. Q21. Difference between final, finally, and finalize? final: A keyword to lock variables, methods, or classes from modification.finally: A block that executes after try/catch, regardless of exceptions.finalize(): A deprecated method invoked by the garbage collector before reclaiming object memory. Q22. Which OOP features does Java support? Java is fully object-oriented, offering:Abstraction: Hide implementation, expose behavior.Encapsulation: Bundle data and methods; use access modifiers.Inheritance: Reuse code via extends.Polymorphism: Same interface, different implementations (overloading/overriding). Q23. Java access specifiers revisited Recall the four access levels: private, package-private (default), protected, and public. Use them wisely to encapsulate and reduce coupling. Q24. Inheritance vs. Composition Inheritance (“is-a”): A Car extends Vehicle.Composition (“has-a”): A Car has an Engine.Favor composition for flexible designs and to avoid tight coupling. Q25. What is an abstract class used for? Use an abstract class to share common code among related classes while forcing subclasses to implement certain methods. It’s the blueprint for a family of classes. Q26. Constructor vs. Method: What separates them? Constructor: Initializes new objects, must match the class name, and has no return type.Method: Defines behavior, always declares a return type (void or otherwise) and can be called repeatedly on an object. Q27. Explain Java’s diamond problem and its solution The classic diamond problem arises in multiple inheritance when two parent classes share the same ancestor. Java avoids it by forbidding multiple class inheritance. Instead, it uses interfaces (since Java 8 they can even contain default methods) to simulate multiple inheritance