Ask Programiz - Human Support for Coding Beginners
Explore questions from fellow beginners answered by our human experts. Have some doubts about coding fundamentals? Enroll in our course and get personalized help right within your lessons.

Hi Az! That’s a great question, and I really like your mindset of trying to understand why things behave the way they do. This approach is very important when learning programming, keep it up.
To answer your question, in Java, the data types of the operands used in an operation determine how the calculation is performed.
In this code:
class Main {
public static void main(String[] args) {
int number = 12;
int result = number / 8;
System.out.println(result);
}
}
Both number and 8 are of type int. Because of this, Java performs integer division.
Integer division removes the decimal part, so 12 / 8 is evaluated as 1, which is why the output is 1.
Even if you store the result in a double, the calculation still happens using integers:
int number = 12;
double result = number / 8;
System.out.println(result); // prints 1.0
Here, the division produces 1 first, and then Java converts it to 1.0 when assigning it to the double.
To get a decimal result like 1.5, at least one operand must be a double before the division and data type of variable used as result should be double too:
class Main {
public static void main(String[] args) {
int number = 12;
double result = number / 8.0;
System.out.println(result); // 1.5
}
}
Here, 8.0 is a double, so Java uses floating-point division and preserves the decimal value.
Hope that helps. Feel free to reply here or in any other topics if you have doubts.

Hello Pratik, really nice question.
charAt() is a method in Java that lets you grab a single character from a string. You just give it the position you want, and it hands you back the character at that spot.
Java starts counting from zero, so:
the first character is at index 0
the second is at index 1
and so on
For example:
String text = "Hello";
char c = text.charAt(1); // 'e'
If you try an index that doesn’t exist, Java throws an error because the string doesn't go that far.
You’ll use charAt() a lot when you loop through a string and check each character, like when counting vowels.
If you have further questions, I'm here to help.

Hi quiet,
You're absolutely right .
In Java, Math.random() returns a value from 0.0 (inclusive) to 1.0 (exclusive). So:
Math.random() * 10 // gives a value from 0.0 to less than 10.0
Math.random() * 10 + 1 // gives a value from 1.0 to less than 11.0
So the correct range for Math.random() * 10 + 1 is 1.0 (inclusive) to less than 11.0 (exclusive).
If you have more questions, I am here to help.

Hi Miki,
Great question — this is a common source of confusion in Java.
==checks if two variables point to the exact same object in memory. It doesn’t care about the content — just the reference..equals()checks if the content of two strings is the same, even if they’re different objects.
Example:
String a = new String("hello");
String b = new String("hello");
System.out.println(a == b); // false — different objects
System.out.println(a.equals(b)); // true — same content
So whenever you want to compare the actual text in two strings, always use .equals().
If you have more questions, I am here to help.


Hi Yeah, great question.
In Java, input.nextLine() is used to read an entire line of text entered by the user — including spaces — up until they press ENTER. This makes it ideal when you're asking for inputs like full names, addresses, or any sentence.
Here's how it works:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter your full name:");
String fullName = input.nextLine();
System.out.println("Hello, " + fullName);
}
}
If the user types John Doe, the output will be:
Hello, John Doe
Now, how is it different from nextInt() or next()?
nextInt()only reads the integer.next()reads a single word (stops at a space).nextLine()reads the entire line, including any spaces, until ENTER is pressed.
This also means that if you use nextInt() followed by nextLine(), you may get unexpected behavior because nextInt() doesn't consume the newline character. That’s something to watch out for.
If you have more questions, I am here to help.

Hey there! Great question, and it's a common one when starting with Java!
Yes, Java does indeed have a type called double. Here's a straightforward explanation:
Types of Numbers in Java:
- Integers:
-
Whole numbers without decimals (e.g.,
5,-11,0). -
Floating-Point Numbers:
- Allow representation of numbers with decimals.
- There are two types in Java:
- Float: Uses 4 bytes (single precision)
- Double: Uses 8 bytes (double precision)
So, what is a double?
- double is a data type used for floating-point numbers with double precision.
- It can handle larger numbers and provide more precision than float.
- Here's how you might use it:
public class Main {
public static void main(String[] args) {
double myDouble = 3.14159;
System.out.println(myDouble); // This will print: 3.14159
}
}
In your lesson, when you refer to floating-point numbers, it's often using the double type due to its precision and flexibility.
Feel free to try running the example above, and let me know if you have any questions or need more clarity! Happy coding! 🌟

Hi Vunnam Sowmya,
Case-sensitive means uppercase and lowercase letters are treated as different.
So "Java" and "java" are not the same, because J and j are different characters.
If you have more questions, I am here to help 😊

Hi there! It's understandable to wonder why we need different quotation marks for characters and strings in Java.
In Java, single quotes are used to represent a single character, while double quotes are used for strings that can include multiple characters. Let's break it down simply:
A character represents just one letter, digit, or symbol - like
'A','8', or'!'. Using single quotes tells Java that you refer to exactly one character.A string can be any collection of letters, digits, or symbols, even just one! So, something like
"Hello, World!"or even"A"or"8"is considered a string because it's seen as a list of characters.
The reason we have to use single quotes for characters is to help the Java compiler distinguish between a single character and a string. Without this distinction, it would be tough for Java to understand what data type you're working with.
Remember: Characters and strings are distinct data types in Java. Therefore, we use single quotes for characters and double quotes for strings so that Java can distinguish between the two.
Hope this helps clear things up! Feel free to ask if you have any more questions or need further clarification.

Hi Harish Hansda,
No, Java class names cannot contain spaces. A class name must be a single identifier.
If you want multiple words, write them together using CamelCase, like this:
class MyFirstClass {
}
If you have more questions, I am here to help 😊

Hi Yichao,
In Java, length for an array is a field (a value stored in the array), not a method. That is why you write it without parentheses:
int[] nums = {1, 2, 3};
System.out.println(nums.length); // 3
Parentheses are only used for methods. For example, strings use a method:
String s = "abc";
System.out.println(s.length()); // 3
So the simple rule is: arrays use length, strings use length().
If you have more questions, I am here to help 😊
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
