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
31 Replies
JavaBot
JavaBot3mo ago
This post has been reserved for your question.
Hey @Piglet | NEED tone tags!!! Please use /close or the Close 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Piglet | **NEED** tone tags!!
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
Piglet | **NEED** tone tags!!
this is what we've been taught, I just have some trouble w I. & II. cuz im not great at calculations
No description
dan1st
dan1st3mo ago
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 value
Stack 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.
dan1st
dan1st3mo ago
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) {}
dan1st
dan1st3mo ago
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?
Piglet | **NEED** tone tags!!
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 right
dan1st
dan1st3mo ago
Piglet | **NEED** tone tags!!
oh I cant use code
dan1st
dan1st3mo ago
The value 0 is a normal int and Strings are not primitive so a String can be null (which is usually not that good of an idea)
Piglet | **NEED** tone tags!!
its a written exam, might have to write some programs but other than a simple calculator I cant use anything else okay, thanks
dan1st
dan1st3mo ago
Well you can still use Integer.parseInt om your cpde
Piglet | **NEED** tone tags!!
I mean the questions for that are gonna be like: "Convert 110101001 to hexadecimal" and id have to work it out myself
dan1st
dan1st3mo ago
String hexadecimal = "A5";//a string with a number in hexadecimal
int convertedToInt = Integer.parseInt(hexadecimal, 16);//convert the hex (16) string to an int for further processing
String toBinary = Integer.parseInt(convertedToInt, 2);//convert the int to a binary (2) string
String toDecimal = Integer.parseInt(convertedToInt, 10);//convert the int to a decimal (10) string
String hexadecimal = "A5";//a string with a number in hexadecimal
int convertedToInt = Integer.parseInt(hexadecimal, 16);//convert the hex (16) string to an int for further processing
String toBinary = Integer.parseInt(convertedToInt, 2);//convert the int to a binary (2) string
String toDecimal = Integer.parseInt(convertedToInt, 10);//convert the int to a decimal (10) string
oh you mean without code? There are a few techniques for it
Piglet | **NEED** tone tags!!
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
dan1st
dan1st3mo ago
You can convert a binary number to decimal like this: The leftmost bit is 1, then 2, then 4, then 8, etc - you multiply each bit with the corresponding number and add them up For converting decimal to hex, you divide it by 16 and take the remainder. That's the last digit. You continue using the result of the division and repeat For binary<--> hex conversion specifically, it's easier you just split it in groups of 4
dan1st
dan1st3mo ago
and then you convert each group to a decimal number and then that decimal number is the hex digit (ofc use ABCDEF for numbers between 10 and 16)
Piglet | **NEED** tone tags!!
okay I just wanted to check if anyone knew a quicker method but thats what we've been taught so thats resolved ig whats the (String args[]) part of public static void main (String args[]) for?
dan1st
dan1st3mo ago
these are program arguments
Piglet | **NEED** tone tags!!
like ik that its the main method class, but ive seen (String []args) and just now (String p)
dan1st
dan1st3mo ago
For main arguments specifically: You can start a program using java YourMainClass.java/java your.fully.qualified.Main/java -jar yourjar.jar. You can also add additional text after that. So you'd start it with java YourMainClass.java your arguments here/java your.fully.qualified.Main your arguments here/java -jar yourjar.jar your arguments here. In this case, args woulöd have the Strings your, arguments and here And parameters in general: If you declare a method like this:
public static void someMethod(){
//...
}
public static void someMethod(){
//...
}
then you can call it with someMethod(); but if you declare a method like this:
public static void someMethod(String someString){
//...
}
public static void someMethod(String someString){
//...
}
then you can call it with someMethod("Hello World"); (or with any other String) and you can use the passed value in the method:
public static void someMethod(String someString){
System.out.println(someString);
}
public static void someMethod(String someString){
System.out.println(someString);
}
dan1st
dan1st3mo ago
Dev.java: The Destination for Java Developers
Defining Methods - Dev.java
Adding methods to a class definition.
Dev.java: The Destination for Java Developers
Calling Methods and Constructors - Dev.java
How to pass information to a method or a constructor.
Piglet | **NEED** tone tags!!
hm im getting some obsidian file linking deja vu OHHH aliases
dan1st
dan1st3mo ago
Why? ?
Piglet | **NEED** tone tags!!
like if a note is called 'Monkeys' you can add alternative titles or aliases within the note and while linking it in another note both will work as links, like both show up as options and idk that feels kinda similar to this thing, not too much of a similarity since the (String somestring) isnt exactly an alias, but since both someMethod and someMethod("Hello World") works its just enough to remind me of it
No description
No description
No description
Piglet | **NEED** tone tags!!
wierd comparison probably but idk anyw im taking a break
dan1st
dan1st3mo ago
I know obsidian linking but I don't really see the connection If you pass a primitive parameter, it copies the value but objects are references to the same object and if you pass that, you get a new reference to the same object ig that might be what you mean
Piglet | **NEED** tone tags!!
idk my brain just understands shit by trying to figure out if it resembles smth ik already so that can mean the most obscure connections that even I dont really understand
dan1st
dan1st3mo ago
That's perfectly fine as long as you don't make too many assumptions thinking it would work similarly
JavaBot
JavaBot3mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server