Essential Web Development and Java Networking Concepts

CSS Box Model Explained

Every HTML element is treated as a rectangular box made up of four layers, from inside out:

┌─────────────────────────────┐
│          MARGIN             │
│  ┌─────────────────────────┐ │
│  │        BORDER           │ │
│  │  ┌─────────────────────┐ │ │
│  │  │      PADDING        │ │ │
│  │  │  ┌─────────────────┐ │ │ │
│  │  │  │     CONTENT     │ │ │ │
│  │  │  └─────────────────┘ │ │ │
│  │  └─────────────────────┘ │ │
│  └─────────────────────────┘ │
└─────────────────────────────┘
  • Content: The actual text or image inside the element.
  • Padding: Transparent space between content and border.
  • Border: The line surrounding the padding.
  • Margin: Transparent space outside the border, separating it from other elements.
div {
  width: 200px;
  padding: 10px;
  border: 5px solid black;
  margin: 20px;
}

Total element width = content + left/right padding + left/right border + left/right margin.

box-sizing property: By default (content-box), width/height apply only to content. Setting box-sizing: border-box makes width/height include padding and border, which is standard for responsive design.

CSS Selectors Reference

Selector TypeSyntaxExample
Universal** { margin: 0; }
Elementtagnamep { color: blue; }
Class.classname.highlight { background: yellow; }
ID#idname#header { font-size: 24px; }
DescendantA Bdiv p { color: red; }
ChildA > Bdiv > p { color: green; }
Adjacent SiblingA + Bh1 + p { margin-top: 0; }
Attribute[attr=value]input[type="text"] { border: 1px; }
GroupA, Bh1, h2 { font-family: Arial; }
Pseudo-class:statea:hover { color: red; }

Pseudo-classes and Pseudo-elements

Pseudo-classes select elements based on their state or position (single colon :):

Pseudo-classDescription
:hoverMouse hovers over element
:focusElement gains focus
:visitedVisited links
:first-childFirst child of parent
:nth-child(n)Selects nth child

Pseudo-elements style a specific part of an element (double colon ::):

Pseudo-elementDescription
::beforeInsert content before element
::afterInsert content after element
::first-letterStyle first letter
::first-lineStyle first line

CSS Positioning and Floating

Positioning (position property):

ValueBehavior
staticDefault; normal document flow
relativeRelative to normal position
absoluteRelative to nearest positioned ancestor
fixedRelative to browser viewport
stickyToggles between relative and fixed

Floating: The float property moves an element to the left or right, allowing text to wrap around it. Use clear to stop wrapping.

Webpage Layout with Flexbox

<div class="container" style="display:flex">
  <aside>Sidebar</aside>
  <main>Main Content</main>
</div>

Flexbox is the modern standard for creating responsive layouts.

Advanced CSS Features

  • Grouping: h1, h2 { color: navy; }
  • Display: Controls rendering (block, inline, flex, grid).
  • Image Sprites: Combining multiple images into one file to reduce server requests.

Applying CSS to HTML

  • Inline: style attribute.
  • Internal: <style> block in <head>.
  • External: Linked .css file (recommended for performance).

AJAX Fundamentals

AJAX (Asynchronous JavaScript and XML) enables updating parts of a webpage without a full reload. It uses XMLHttpRequest or the fetch API to communicate with servers asynchronously.

JavaScript Essentials

  • Functions: Reusable code blocks (Declaration, Expression, Arrow functions).
  • DOM Manipulation: Methods like getElementById() and querySelector() allow dynamic page updates.
  • Event Handling: Responding to user actions via onclick or addEventListener().

Java Networking

  • InetAddress: Represents IP addresses. Use factory methods like getByName().
  • URL/URLConnection: Classes for accessing web resources.
  • Sockets: Socket and ServerSocket provide reliable TCP communication.
  • Datagrams: DatagramSocket provides faster, connectionless UDP communication.