Skip to content

Commit 6cbc135

Browse files
committed
Add java Lessons about Numeric Integer Variables in Java
1 parent 01a7789 commit 6cbc135

2 files changed

Lines changed: 149 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*****************************************************************************
2+
* PROJECT: Java-101 Comprehensive Programming Course
3+
* MODULE: Introduction to Java Fundamentals
4+
* LESSON: 1.3.1 - Integer Numeric Data Types
5+
*
6+
* AUTHOR: Dr. Saad Laouadi, Ph.D.
7+
* created: April 2025
8+
*
9+
* Copyright © 2025 Dr. Saad Laouadi. All Rights Reserved.
10+
* See LICENSE file for complete terms.
11+
*****************************************************************************/
12+
13+
public class NumericIntegerTypes {
14+
public static void main(String[] args) {
15+
displayBanner('=', 50);
16+
System.out.println(" Integer Numeric Types in Java ");
17+
displayBanner('=', 50);
18+
19+
// Integer numeric data types
20+
byte byteVar = 127; // 8-bit signed integer
21+
short shortVar = 32767; // 16-bit signed integer
22+
int intVar = 2147483647; // 32-bit signed integer
23+
long longVar = 9223372036854775807L; // 64-bit signed integer
24+
25+
// Print out the integer type values and their ranges
26+
System.out.println("Integer Numeric Data Types:");
27+
28+
System.out.println("\nbyte:");
29+
System.out.println("\tValue: " + byteVar);
30+
System.out.println("\tSize: 8 bits (1 byte)");
31+
System.out.println("\tRange: -128 to 127");
32+
System.out.println("\tUse: Memory-sensitive data, file I/O operations");
33+
34+
System.out.println("\nshort:");
35+
System.out.println("\tValue: " + shortVar);
36+
System.out.println("\tSize: 16 bits (2 bytes)");
37+
System.out.println("\tRange: -32,768 to 32,767");
38+
System.out.println("\tUse: Memory conservation when range is sufficient");
39+
40+
System.out.println("\nint:");
41+
System.out.println("\tValue: " + intVar);
42+
System.out.println("\tSize: 32 bits (4 bytes)");
43+
System.out.println("\tRange: -2,147,483,648 to 2,147,483,647");
44+
System.out.println("\tUse: Default integer type for most calculations");
45+
46+
System.out.println("\nlong:");
47+
System.out.println("\tValue: " + longVar);
48+
System.out.println("\tSize: 64 bits (8 bytes)");
49+
System.out.println("\tRange: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807");
50+
System.out.println("\tUse: Very large numbers, timestamps, unique IDs");
51+
System.out.println("\tNote: The 'L' suffix is required for long literals");
52+
53+
displayBanner('=', 50);
54+
}
55+
56+
public static void displayBanner(char c, int length) {
57+
for (int i = 0; i < length; i++) {
58+
System.out.print(c);
59+
}
60+
System.out.println();
61+
}
62+
63+
// Numeric Integer Examples
64+
public static void numiericIntegerVariablesUsage(){
65+
66+
// Examples of using integer types
67+
System.out.println("\nExamples of Integer Operations:");
68+
int sum = 25 + 50;
69+
System.out.println("\tAddition: 25 + 50 = " + sum);
70+
71+
int difference = 100 - 30;
72+
System.out.println("\tSubtraction: 100 - 30 = " + difference);
73+
74+
int product = 5 * 6;
75+
System.out.println("\tMultiplication: 5 * 6 = " + product);
76+
77+
int quotient = 20 / 4;
78+
System.out.println("\tDivision: 20 / 4 = " + quotient);
79+
80+
int remainder = 17 % 5;
81+
System.out.println("\tRemainder (modulus): 17 % 5 = " + remainder);
82+
}
83+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*****************************************************************************
2+
* PROJECT: Java-101 Comprehensive Programming Course
3+
* MODULE: Introduction to Java Fundamentals
4+
* LESSON: 1.3.2 - Numeric Integer Data Types
5+
*
6+
* AUTHOR: Dr. Saad Laouadi, Ph.D.
7+
* CREATED: March 2025
8+
*
9+
* Copyright © 2025 Dr. Saad Laouadi. All Rights Reserved.
10+
* See LICENSE file for complete terms.
11+
*****************************************************************************/
12+
13+
public class NumericIntegerTypesInfo {
14+
public static void main (String[] args){
15+
16+
displayBanner('-', 60);
17+
System.out.println(" NUMERIC INTEGER VARIABLES ");
18+
displayBanner('-', 60);
19+
20+
// Create variables of each integer type
21+
byte byteVar = 127;
22+
short shortVar = 32767;
23+
int intVar = 2147483647;
24+
long longVar = 9223372036854775807L;
25+
26+
// Display information about byte
27+
System.out.println("BYTE:");
28+
System.out.println("\tSize in memory: " + Byte.BYTES + " bytes (" + (Byte.BYTES * 8) + " bits)");
29+
System.out.println("\tMinimum value: " + Byte.MIN_VALUE);
30+
System.out.println("\tMaximum value: " + Byte.MAX_VALUE);
31+
System.out.println("\tExample value: " + byteVar);
32+
System.out.println();
33+
34+
// Display information about short
35+
System.out.println("SHORT:");
36+
System.out.println("\tSize in memory: " + Short.BYTES + " bytes (" + (Short.BYTES * 8) + " bits)");
37+
System.out.println("\tMinimum value: " + Short.MIN_VALUE);
38+
System.out.println("\tMaximum value: " + Short.MAX_VALUE);
39+
System.out.println("\tExample value: " + shortVar);
40+
System.out.println();
41+
42+
// Display information about int
43+
System.out.println("INT:");
44+
System.out.println("\tSize in memory: " + Integer.BYTES + " bytes (" + (Integer.BYTES * 8) + " bits)");
45+
System.out.println("\tMinimum value: " + Integer.MIN_VALUE);
46+
System.out.println("\tMaximum value: " + Integer.MAX_VALUE);
47+
System.out.println("\tExample value: " + intVar);
48+
System.out.println();
49+
50+
// Display information about long
51+
System.out.println("LONG:");
52+
System.out.println("\tSize in memory: " + Long.BYTES + " bytes (" + (Long.BYTES * 8) + " bits)");
53+
System.out.println("\tMinimum value: " + Long.MIN_VALUE);
54+
System.out.println("\tMaximum value: " + Long.MAX_VALUE);
55+
System.out.println("\tExample value: " + longVar);
56+
57+
displayBanner('-', 60);
58+
59+
}
60+
public static void displayBanner(char c, int length) {
61+
for (int i = 0; i < length; i++) {
62+
System.out.print(c);
63+
}
64+
System.out.println();
65+
}
66+
}

0 commit comments

Comments
 (0)