prepping for an exam, new to java & might need help understanding some stuff
im just gonna put in questions here as I study
ill probably not ask a whole ass program explanation unless its fully indecipherable to me
ill bold whatever is the tldr version if you dont want extra context
30 Replies
⌛
This post has been reserved for your question.
Hey @Piglet | NEED tone tags!!! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
firstly, whats a null literal 😭
ik it represents like no value but the text says "null is used to initialize an object of a class ... and may denote non-availability of a character in a String"
secondly, ill need to do conversions from/to decimal, binary, hexadecimal and octal numbers but if anyone happens to know a method thats easy for any of that pls lmk
this is what we've been taught, I just have some trouble w I. & II. cuz im not great at calculations
null is a special value to indicate that there is no object. https://stackoverflow.com/a/19654040/10871900
The null literal is the text
null
that refers to that valueStack Overflow
What is the difference between null, 0 and nothing?
What is the difference between null, 0 and nothing?
I cannot find a question addressing all three of these.
For example:
If I am getting input from a string and parsing it to int.
return Integer.
So every reference variable (so variables that are not primitives like boolean, char, short, int, long, float, double can be null meaning "no value associated with it"
and you can explicitly set a variable to
null
using yourVariable = null;
or check whether a variable is null using if(yourVariable == null) {}
Stack Overflow
What is null in Java?
What is null?
Is null an instance of anything?
What set does null belong to?
How is it represented in the memory?
okay so like, its ONLY for non-primitive datatypes, but if I wanted to do pretty much the same thing w a primitive data type, smth like
int example = 0
or String ex2 = ""
works rightInteger.parseInt
and Integer.toString
, both support a radix specifying the base (e.g. 2 for binary, 10 for decimal, 16 for hexadecimal)
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Integer.html#parseInt(java.lang.String,int)
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Integer.html#toString(int,int)oh I cant use code
The value
0
is a normal int and String
s are not primitive so a String
can be null
(which is usually not that good of an idea)its a written exam, might have to write some programs but other than a simple calculator I cant use anything else
okay, thanks
Well you can still use
Integer.parseInt
om your cpdeI mean the questions for that are gonna be like:
"Convert 110101001 to hexadecimal" and id have to work it out myself
oh you mean without code?
There are a few techniques for it
for program questions theyre like "A Piglatin word is the part of the word after the first vowel, the part before, added with an 'ay'" and I'd have to use like substring and loop commands to get that output
yup