Tech Jargon - Decoded
Відкрити в Telegram
Confused by tech terms? Don’t worry, we’ve got you 🤝 We make things simple, one concept at a time. Learn daily Easy & clear Turn Confusion into clarity. #tech #it #softwareengineer #cs #development
Показати більше2 016
Підписники
-124 години
-57 днів
-4030 день
Архів дописів
Unlocking Java: How to declare and use different data types?
public class DataTypes {
public static void main(String[] args) {
int age = 25;
double price = 19.99;
char grade = 'A';
boolean isStudent = true;
String name = "Alice";
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Price: " + price);
System.out.println("Grade: " + grade);
System.out.println("Is student: " + isStudent);
}
}Hello World in Java: Your first step into coding! 🚀
public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); } }Alright, let's dive into the fantastic world of Java Basics & Syntax! 🚀 This is where your coding adventure begins, and it's all about learning the language Java speaks.
🧠 **Understanding the Basics**
Think of Java syntax as the grammar rules for writing code. Just like English needs correct grammar to make sense, Java needs correct syntax for the computer to understand your instructions. Without the right syntax, your code won't run, and you'll get errors! 😫 Don't worry, we'll learn how to avoid those.
Variables are like labeled containers that hold information. Imagine you have a box labeled "age" and you put the number 25 inside. In Java, that's what a variable does! It stores data like numbers, words, or even true/false values.
Data types tell Java what kind of information a variable will hold. Is it a number, a word, or something else? Common data types include:
- `int`: For whole numbers (like 10, -5, 0).
- `double`: For decimal numbers (like 3.14, -2.5).
- `String`: For text (like "Hello World!").
- `boolean`: For true/false values (like `true` or `false`).
💡 **Syntax Fundamentals: A Simple Program**
Here's a super simple Java program to give you a taste of the syntax:
va
public class MyFirstProgram {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Let's break it down:
- `public class MyFirstProgram { ... }` -> This defines a class. Think of a class as a blueprint for creating objects. In this case, we are creating a program.
- `public static void main(String[] args) { ... }` -> This is the main method. It's where your program starts running.
- `System.out.println("Hello, Java!");` -> This line prints the text "Hello, Java!" to the console. `System.out.println()` is your friend for showing output.
✅ **Good Practice:** Always include comments in your code to explain what it does. This makes it easier for you (and others) to understand your code later!
➕ **Operators: Doing Things with Data**
Operators are symbols that perform operations on variables and values. Think of them as verbs in Java. Some common operators are:
- `+`: Addition (e.g., `5 + 3` is 8).
- `-`: Subtraction (e.g., `10 - 4` is 6).
- `*`: Multiplication (e.g., `2 * 6` is 12).
- `/`: Division (e.g., `15 / 3` is 5).
- `=`: Assignment. It assigns a value to a variable (e.g., `int age = 30;`).
⚠️ **Important:** Be careful with division! Dividing integers can sometimes lead to unexpected results because the fractional part is dropped (e.g., `5 / 2` results in 2, not 2.5).
⌨️ **Basic I/O (Input/Output)**
I/O is how your program interacts with the outside world. "Input" is how your program receives information (e.g., from the user), and "Output" is how your program displays information (e.g., on the screen).
To get input from the user, you'll typically use the `Scanner` class. Here's an example:
va
import java.util.Scanner;
public class InputExample {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = input.nextLine();
System.out.println("Hello, " + name + "!");
input.close();
}
}
In this example:
- We import the `Scanner` class.
- We create a `Scanner` object to read input from the console.
- We prompt the user to enter their name.
- We read the user's input using `input.nextLine()`.
- We print a greeting to the user.
- Don't forget to `input.close()` scanner to release resources
This is just the beginning! Keep practicing, experimenting, and you'll become a Java pro in no time! 🚀Hello, Java! 👋 Your First Program Explained!
public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); } }Here's a beginner-friendly explanation of Java Basics & Syntax, designed for a Telegram post:
Welcome to the world of Java! ☕ Let's unlock the fundamentals: Java Basics & Syntax! This is where your coding journey truly begins. We will cover syntax, variables, datatypes, operators and input/output operations.
🧠 **What is Java Syntax?**
Think of syntax as the grammar rules of Java. It dictates how you must write code so the computer understands it. Just like English has rules about sentence structure, Java has rules about how to structure code. Without proper syntax, your code won't run! 😥
- Every Java program is built around classes.
- Statements end with a semicolon (;). This is crucial!
- Java is case-sensitive. `myVariable` is different from `MyVariable`.
✅ **Good Practice:** Keep your code clean and readable. Use indentation to show the structure of your program.
🔑 **Example:**
va
public class MyFirstProgram {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Explanation of the example:
`public class MyFirstProgram` -> This declares a class named `MyFirstProgram`.
`public static void main(String[] args)` -> This is the main method, the entry point of your program.
`System.out.println("Hello, World!");` -> This prints "Hello, World!" to the console.
📦 **Variables and Data Types**
Variables are like containers that hold data. Each variable has a specific *data type*, which determines what kind of data it can store (e.g., numbers, text).
- **Data Types:**
- `int`: Stores whole numbers (e.g., 10, -5, 0).
- `double`: Stores decimal numbers (e.g., 3.14, -2.5).
- `String`: Stores text (e.g., "Hello", "Java").
- `boolean`: Stores true or false values.
💡 **Tip:** Choose the correct data type for your variable to avoid errors and use memory efficiently.
📝 **Declaring Variables:**
`dataType variableName = value;`
Example:
`int age = 25;`
`String name = "Alice";`
`double price = 19.99;`
➕ **Operators**
Operators are symbols that perform operations on variables and values.
- **Arithmetic Operators:** `+` (addition), `-` (subtraction), `*` (multiplication), `/` (division), `%` (modulus - remainder).
- **Assignment Operator:** `=` (assigns a value to a variable).
- **Comparison Operators:** `==` (equal to), `!=` (not equal to), `>` (greater than), `<` (less than), `>=` (greater than or equal to), `<=` (less than or equal to).
- **Logical Operators:** `&&` (AND), `||` (OR), `!` (NOT).
Example:
`int x = 10;`
`int y = 5;`
`int sum = x + y; // sum is now 15`
⌨️ **Basic I/O (Input/Output)**
I/O allows your program to interact with the user.
- **Output:** `System.out.println()` prints text to the console. We've already seen this!
- **Input:** To get input from the user, you'll often use the `Scanner` class.
Example using Scanner:
va
import java.util.Scanner;
public class InputExample {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter your name: ");
String name = input.nextLine();
System.out.println("Hello, " + name + "!");
input.close(); //Good practice to close the scanner
}
}
Explanation:
`import java.util.Scanner;` -> Imports the Scanner class.
`Scanner input = new Scanner(System.in);` -> Creates a Scanner object to read input.
`String name = input.nextLine();` -> Reads a line of text entered by the user.
⚠️ **Warning:** Always remember to close your `Scanner` object after you're done using it (`input.close();`) to prevent resource leaks.
🚀 That's a brief overview of Java Basics & Syntax! Keep practicing, and you'll become a Java pro in no time! Happy coding! 🎉Word Frequency using HashMap
import java.util.HashMap;
import java.util.Map;
public class WordFrequency {
public static void main(String[] args) {
String text = "This is a test. This is only a test.";
Map<String, Integer> wordFrequencies = getWordFrequencies(text);
for (Map.Entry<String, Integer> entry : wordFrequencies.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
public static Map<String, Integer> getWordFrequencies(String text) {
Map<String, Integer> wordFrequencies = new HashMap<>();
String[] words = text.toLowerCase().split("[\\s\\p{Punct}]+");
for (String word : words) {
if (word.isEmpty()) {
continue;
}
wordFrequencies.put(word, wordFrequencies.getOrDefault(word, 0) + 1);
}
return wordFrequencies;
}
}Find Longest Word in Sentence
public class LongestWord {
public static String findLongestWord(String sentence) {
String[] words = sentence.split(" ");
String longestWord = "";
for (String word : words) {
if (word.length() > longestWord.length()) {
longestWord = word;
}
}
return longestWord;
}
public static void main(String[] args) {
String sentence = "This is a sample sentence to find the longest word";
String longest = findLongestWord(sentence);
System.out.println("Longest word: " + longest);
}
}Convert String to Integer (Custom parseInt)
public class StringToInt {
public static int myParseInt(String str) {
if (str == null || str.isEmpty()) {
return 0;
}
int sign = 1;
int result = 0;
int i = 0;
str = str.trim();
if (str.charAt(0) == '+' || str.charAt(0) == '-') {
sign = (str.charAt(0) == '-') ? -1 : 1;
i++;
}
while (i < str.length() && Character.isDigit(str.charAt(i))) {
int digit = str.charAt(i) - '0';
if (result > Integer.MAX_VALUE / 10 || (result == Integer.MAX_VALUE / 10 && digit > Integer.MAX_VALUE % 10)) {
return (sign == 1) ? Integer.MAX_VALUE : Integer.MIN_VALUE;
}
result = result * 10 + digit;
i++;
}
return sign * result;
}
public static void main(String[] args) {
System.out.println(myParseInt("42"));
System.out.println(myParseInt(" -42"));
System.out.println(myParseInt("4193 with words"));
System.out.println(myParseInt("words and 987"));
System.out.println(myParseInt("-91283472332"));
}
}Check for Isomorphic Strings
import java.util.HashMap;
import java.util.Map;
public class IsomorphicStrings {
public static boolean isIsomorphic(String s, String t) {
if (s.length() != t.length()) {
return false;
}
Map<Character, Character> sMap = new HashMap<>();
Map<Character, Character> tMap = new HashMap<>();
for (int i = 0; i < s.length(); i++) {
char sChar = s.charAt(i);
char tChar = t.charAt(i);
if (sMap.containsKey(sChar)) {
if (sMap.get(sChar) != tChar) {
return false;
}
} else {
if (tMap.containsKey(tChar)) {
return false;
}
sMap.put(sChar, tChar);
tMap.put(tChar, sChar);
}
}
return true;
}
public static void main(String[] args) {
String s1 = "egg";
String t1 = "add";
System.out.println(s1 + " and " + t1 + " are isomorphic: " + isIsomorphic(s1, t1));
String s2 = "foo";
String t2 = "bar";
System.out.println(s2 + " and " + t2 + " are isomorphic: " + isIsomorphic(s2, t2));
String s3 = "paper";
String t3 = "title";
System.out.println(s3 + " and " + t3 + " are isomorphic: " + isIsomorphic(s3, t3));
}
}Sort Characters in a String
import java.util.Arrays;
public class StringSorter {
public static String sortString(String inputString) {
char[] charArray = inputString.toCharArray();
Arrays.sort(charArray);
return new String(charArray);
}
public static void main(String[] args) {
String testString = "dcba";
String sortedString = sortString(testString);
System.out.println("Original String: " + testString);
System.out.println("Sorted String: " + sortedString);
}
}Split and Print Words in String
public class StringSplitter {
public static void main(String[] args) {
String str = "This is a sample string";
String[] words = str.split(" ");
for (String word : words) {
System.out.println(word);
}
}
}
Вже доступно! Дослідження Telegram за 2025 — головні інсайти року 
