|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en-US"> |
| 3 | +<head> |
| 4 | +<meta charset="UTF-8"> |
| 5 | +<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | +<title>Tutorial Page Template</title> |
| 7 | +<link rel="stylesheet" href="https://www.w3schools.com/w3css/5/w3.css"> |
| 8 | +<style> |
| 9 | + /* Sidebar styling */ |
| 10 | + .sidebar { |
| 11 | + height: 100vh; |
| 12 | + overflow-y: auto; |
| 13 | + position: fixed; |
| 14 | + width: 180px; |
| 15 | + background-color: #003366; |
| 16 | + color: white; |
| 17 | + } |
| 18 | + .sidebar h3 { |
| 19 | + margin-top: 15px; |
| 20 | + margin-bottom: 5px; |
| 21 | + padding-left: 12px; |
| 22 | + color: #ff3333; |
| 23 | + font-size: 14px; |
| 24 | + } |
| 25 | + .sidebar a { |
| 26 | + display: block; |
| 27 | + padding: 6px 12px; |
| 28 | + text-decoration: none; |
| 29 | + color: white; |
| 30 | + font-size: 13px; |
| 31 | + border-radius: 4px; |
| 32 | + } |
| 33 | + .sidebar a:hover { |
| 34 | + background-color: #ff3333; |
| 35 | + color: white; |
| 36 | + } |
| 37 | + |
| 38 | + /* Main content area */ |
| 39 | + .main-content { |
| 40 | + margin-left: 190px; |
| 41 | + padding: 20px; |
| 42 | + background-color: white; |
| 43 | + color: #000; |
| 44 | + transition: background-color 0.3s, color 0.3s; |
| 45 | + } |
| 46 | + |
| 47 | + /* Dark mode class */ |
| 48 | + .darkmode { |
| 49 | + background-color: #1e1e1e; |
| 50 | + color: #f1f1f1; |
| 51 | + } |
| 52 | + .darkmode h1, |
| 53 | + .darkmode h3 { |
| 54 | + color: #ff6666; |
| 55 | + } |
| 56 | + |
| 57 | + /* Button */ |
| 58 | + .darkmode-btn { |
| 59 | + background-color: #ff3333; |
| 60 | + color: white; |
| 61 | + border: none; |
| 62 | + padding: 6px 12px; |
| 63 | + border-radius: 4px; |
| 64 | + cursor: pointer; |
| 65 | + margin-bottom: 15px; |
| 66 | + font-size: 14px; |
| 67 | + } |
| 68 | + .darkmode-btn:hover { |
| 69 | + background-color: #cc0000; |
| 70 | + } |
| 71 | + |
| 72 | + h1 { color: #003366; } |
| 73 | + |
| 74 | +</style> |
| 75 | +</head> |
| 76 | +<body> |
| 77 | + |
| 78 | +<!-- Sidebar / Navigation --> |
| 79 | +<div class="sidebar w3-card"> |
| 80 | + <h2 class="w3-center w3-padding-12" style="font-size:16px; color:white;">Tutorial Menu</h2> |
| 81 | + <h3>Java Syntax</h3> |
| 82 | + <a href="#intro">Introduction</a> |
| 83 | + <a href="#setup">Setup</a> |
| 84 | + <h3>Core Concepts</h3> |
| 85 | + <a href="#concept1">Concept 1</a> |
| 86 | + <a href="#concept2">Concept 2</a> |
| 87 | + <h3>Advanced</h3> |
| 88 | + <a href="#advanced1">Advanced 1</a> |
| 89 | + <a href="#advanced2">Advanced 2</a> |
| 90 | +</div> |
| 91 | + |
| 92 | +<!-- Main Content Area --> |
| 93 | +<div class="main-content" id="mainContent"> |
| 94 | + <button class="darkmode-btn" onclick="toggleDarkMode()">Toggle Dark Mode</button> |
| 95 | + |
| 96 | + <h1 id="intro">Java Data types</h1> |
| 97 | + <p>As explained in the previous chapter, a variable in Java must be a specified data type:</p> |
| 98 | + <p>In Java there are different types of variables. Each type has a specific purpose and behavior.</p> |
| 99 | + <script src="//onlinegdb.com/embed/js/lGbi9p256?theme=light"></script> |
| 100 | + |
| 101 | + <h3>Primitive Data Types</h3> |
| 102 | + <P>Data types are divided into two groups:<P> |
| 103 | +<ul> |
| 104 | + <li>Primitive Data Types: - includes byte, short, int, long, float, double, boolean and char</li> |
| 105 | + <li>Non-Primitive Data Types: - includes strings, classes, interfaces, and arrays</li> |
| 106 | +</ul> |
| 107 | + |
| 108 | +<table> |
| 109 | + <tr> |
| 110 | + <th>Data Type</th> |
| 111 | + <th>Description</th> |
| 112 | + <th>Max value</th> |
| 113 | + <th>Min value</th> |
| 114 | + <th>Example</th> |
| 115 | + </tr> |
| 116 | + <tr> |
| 117 | + <td>byte</td> |
| 118 | + <td>8-bit signed integer</td> |
| 119 | + <td><code>127</code></td> |
| 120 | + <td><code>-128</code></td> |
| 121 | + <td><code>byte b = 100;</code></td> |
| 122 | + </tr> |
| 123 | + <tr> |
| 124 | + <td>short</td> |
| 125 | + <td>16-bit signed integer</td> |
| 126 | + <td><code>32767</code></td> |
| 127 | + <td><code>-32768</code></td> |
| 128 | + <td><code>short s = 10000;</code></td> |
| 129 | + </tr> |
| 130 | + <tr> |
| 131 | + <td>int</td> |
| 132 | + <td>32-bit signed integer</td> |
| 133 | + <td><code>2147483647</code></td> |
| 134 | + <td><code>-2147483648</code></td> |
| 135 | + <td><code>int i = 100000;</code></td> |
| 136 | + </tr> |
| 137 | + <tr> |
| 138 | + <td>long</td> |
| 139 | + <td>64-bit signed integer</td> |
| 140 | + <td><code>9223372036854775807L</code></td> |
| 141 | + <td><code>-9223372036854775808L</code></td> |
| 142 | + <td><code>long l = 100000L;</code></td> |
| 143 | + </tr> |
| 144 | + <tr> |
| 145 | + <td>float</td> |
| 146 | + <td>32-bit floating point (IEEE 754)</td> |
| 147 | + <td><code>≈ 3.4028235e38</code></td> |
| 148 | + <td><code>≈ -3.4028235e38</code></td> |
| 149 | + <td><code>float f = 3.14f;</code></td> |
| 150 | + </tr> |
| 151 | + <tr> |
| 152 | + <td>double</td> |
| 153 | + <td>64-bit floating point (IEEE 754)</td> |
| 154 | + <td><code>≈ 1.7976931348623157e308</code></td> |
| 155 | + <td><code>≈ -1.7976931348623157e308</code></td> |
| 156 | + <td><code>double d = 3.14159;</code></td> |
| 157 | + </tr> |
| 158 | + <tr> |
| 159 | + <td>boolean</td> |
| 160 | + <td>Logical type with two values</td> |
| 161 | + <td colspan="2"><code>true or false</code></td> |
| 162 | + <td><code>boolean flag = true;</code></td> |
| 163 | + </tr> |
| 164 | + <tr> |
| 165 | + <td>char</td> |
| 166 | + <td>16-bit Unicode character</td> |
| 167 | + <td><code>'\uffff' (65535)</code></td> |
| 168 | + <td><code>'\u0000' (0)</code></td> |
| 169 | + <td><code>char c = 'A';</code></td> |
| 170 | + </tr> |
| 171 | +</table> |
| 172 | + |
| 173 | +<h3> You cannot change Data types</h3> |
| 174 | +<p>In Java, once a variable is declared with a specific data type, it cannot be |
| 175 | + <script src="//onlinegdb.com/embed/js/FPEuJueWA?theme=light"></script> |
| 176 | + |
| 177 | + |
| 178 | + <!-- Navigation Buttons at the Bottom --> |
| 179 | +<div style="display:flex; justify-content:space-between; margin-top:40px;"> |
| 180 | + <button class="w3-button w3-red" onclick="window.location.href='/Programming/tutorals/Java/JavaTutorials3.html'">Previous Lesson</button> |
| 181 | + <button class="w3-button w3-red" onclick="window.location.href='/Programming/tutorals/Java/JavaTutorials5.html'">Next Lesson</button> |
| 182 | +</div> |
| 183 | + |
| 184 | +</div> |
| 185 | + |
| 186 | +<script> |
| 187 | +const content = document.getElementById('mainContent'); |
| 188 | + |
| 189 | +// Apply saved preference or system preference on load |
| 190 | +function applyPreference() { |
| 191 | + const saved = localStorage.getItem('darkmode'); |
| 192 | + if (saved === 'true') { |
| 193 | + content.classList.add('darkmode'); |
| 194 | + } else if (saved === 'false') { |
| 195 | + content.classList.remove('darkmode'); |
| 196 | + } else { |
| 197 | + // Follow system preference if no saved value |
| 198 | + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { |
| 199 | + content.classList.add('darkmode'); |
| 200 | + } |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +window.onload = applyPreference; |
| 205 | + |
| 206 | +// Toggle dark/light mode and save preference |
| 207 | +function toggleDarkMode() { |
| 208 | + if (content.classList.contains('darkmode')) { |
| 209 | + content.classList.remove('darkmode'); |
| 210 | + localStorage.setItem('darkmode', 'false'); |
| 211 | + } else { |
| 212 | + content.classList.add('darkmode'); |
| 213 | + localStorage.setItem('darkmode', 'true'); |
| 214 | + } |
| 215 | +} |
| 216 | +</script> |
| 217 | + |
| 218 | +</body> |
| 219 | +</html> |
0 commit comments