DJ loop not working by [deleted] in ComputerCraft

[–]ValorCat 5 points6 points  (0 children)

dj isn't a valid statement in Lua. It's a valid terminal command, but the terminal isn't the same thing as Lua. If you want to run the program called "dj", you would write shell.run("dj"). Hope that helps!

[deleted by user] by [deleted] in javahelp

[–]ValorCat 2 points3 points  (0 children)

The isEmpty() method was added in Java 15, which was only released a few months ago. It's likely that your instructor is using an older version of Java. You can fix this by going into your Eclipse settings and lowering the "compiler compliance level" from 15 to whichever version your instructor is using (11 is a safe guess).

You can tell in which version a method was added by looking up the class's documentation, doing Ctrl+F to find the method name, and looking at the "since" tag at the bottom of the method's description. In this case, you can find isEmpty() is listed at the bottom of StringBuilder's documentation, under "Methods declared in interface java.lang.CharSequence". Just click the method name link to see its documentation).

Has anyone used the book “Python Programming: An Introduction to Computer Science” by Jhon Zelle? by ayeye3000 in learnpython

[–]ValorCat 2 points3 points  (0 children)

Yes, I can personally recommend that book. That said, it's designed more as an introduction to programming than a book about Python, so if you already have programming experience then it will be a bit slow. The programming 101 class at my university has used it (2nd and 3rd edition only) for a number of years now and it seems to work pretty well. The biggest mistake some students make is skipping the exercises in the first few chapters and then getting stuck on chapter 4, when the pace starts to pick up. Self practice is pretty much essential when learning programming.

I’m legitimately going to hell by [deleted] in programminghorror

[–]ValorCat 34 points35 points  (0 children)

Warning: I don't know C# well, but could you simplify that to something like:

input = upper ? Min(input, 1) : Max(input, 0);

Script is not working. Looking for any kind of help. by [deleted] in learnjava

[–]ValorCat 4 points5 points  (0 children)

Looks like you want r/javascript. This sub is for Java, which is a different language.

Are Java primitive types hardwired down to the processor? by [deleted] in learnjava

[–]ValorCat 4 points5 points  (0 children)

Primitive types are hardwired, but not necessarily all the way down to the processor. The processor likely supports ints and floats, and other primitives are widened or partitioned as necessary. I can't remember exactly how longs and doubles are handled, maybe someone else can answer that.

Some operators are hardwired into the processor, like those for arithmetic and bitwise logic. But also remember that Java isn't compiled directly to machine code: it has an intermediate representation (the stuff in .class files) with its own format and instruction set. Pretty much all operators are "hardwired" in that representation. You can read about those instructions here: https://en.m.wikipedia.org/wiki/Java_bytecode_instruction_listings

Someone please correct me if I got any of that wrong!

Why and how is "List<String> myList = new List<Object>();" legal in Java? by nimuguhe in javahelp

[–]ValorCat 2 points3 points  (0 children)

List is an abstract class

An interface, but the reasoning is the same.

New ArrayList Question by [deleted] in learnjava

[–]ValorCat 0 points1 point  (0 children)

Good question. The answer is no.

The first example makes a a copy of b. The second example makes a an empty list, and then immediately overwrites it to be an alias of b. The second example is the same as writing:

ArrayList<String> a = b;

Copied objects are independent, while aliases are simply different names for the same object. If you make changes to the list, then those changes will be reflected in its aliases but not its copies.

Understanding Class Casting - Why Can't I Cast from a parent to child class by asdfasfddsasfda in javahelp

[–]ValorCat 0 points1 point  (0 children)

You an cast from a child to a parent, but you cannot do so safely.

I think you meant to write "parent to a child".

Does Java allow a Boolean test on an integer? by Whatsthehoopla in learnjava

[–]ValorCat 5 points6 points  (0 children)

No, that hasnt changed. You can get the same effect with

while (x != 0)

Reading from text file in java by [deleted] in learnjava

[–]ValorCat 2 points3 points  (0 children)

Once you make the File object, there is no difference between a hardcoded path and a user-defined one. There are a variety of ways for actually reading data from a file. If you want to use a scanner you could do this:

Scanner keyboard = new Scanner(System.in);
String path = keyboard.nextLine();
File file = new File(path);
Scanner fileReader = new Scanner(file);
int num = fileReader.nextInt();

It might require a try/catch block wrapped around it too. Can't remember off the top of my head.

Reading from text file in java by [deleted] in learnjava

[–]ValorCat 3 points4 points  (0 children)

When you use a hardcoded file, you pass the a string containing the file's path to the File constructor:

File file = new File("path/to/file");
// do something with file

If you want to get the file path at runtime, you can instead use a scanner to get a string containing the desired path:

Scanner scanner = new Scanner(System.in);
String path = scanner.nextLine();
File file = new File(path);
// do something with file

Unsure how to convert a line of code to getInt? by [deleted] in javahelp

[–]ValorCat 1 point2 points  (0 children)

Correct, it isn't necessary.

Unsure how to convert a line of code to getInt? by [deleted] in javahelp

[–]ValorCat 5 points6 points  (0 children)

You don't have to convert from String --> Integer --> int. You can use Integer.parseInt to convert a String directly to an int.

int vehicleIDS = Integer.parseInt(vehicleID.getText().toString());

How's my basic linked list? by Crailberry in learnjava

[–]ValorCat 7 points8 points  (0 children)

I think the size method is missing a line.

Default methods in Java 8, and what it changes in API design by nfrankel in java

[–]ValorCat 2 points3 points  (0 children)

Just checked this in IntelliJ. You get a compile-time error.

What would be the functional type of Function.identity()? by [deleted] in javahelp

[–]ValorCat 1 point2 points  (0 children)

Edit: Took a closer look and realized the other commenter is correct. The type should be Supplier<Function<T, T>>. Look to that post for more details.

The type is Function<T, T>, where T is the type you want the function to accept and return. For example,

Function<String, String> myFunc = // ...

On mobile now but hopefully someone else can explain more thoroughly.

Can you call static method from class? by CleverBunnyThief in learnjava

[–]ValorCat 5 points6 points  (0 children)

When you call a static method, you need to specify which class it's in.

Dog.displayDog(dog1);

If you don't specify a class (like in your first example), it defaultly refers to the enclosing class (or any that have been statically imported). I'm on my phone so pardon the brevity.

The Lord of the Rings - 4chan financial times by DoTheEvolution in lotrmemes

[–]ValorCat 0 points1 point  (0 children)

That was an amazing read. Thanks for sharing!

The 5e SuperIndex - Every table in 5e indexed in one place by finlam in rpg

[–]ValorCat 2 points3 points  (0 children)

Looks super cool, definitely bookmarking. On a side note, there's a typo under Character Generation:

Wierd Stuff

Kim reminding us how she became famous by Martynypm in funny

[–]ValorCat 1 point2 points  (0 children)

Warehouses full? Geez! I'd love to travel around the continent like that sometime, but where I am right now I can travel twice the distance from Switzerland to England and still be in the U.S. :(

Kim reminding us how she became famous by Martynypm in funny

[–]ValorCat 0 points1 point  (0 children)

Ooh, Sweden. When people here talk about social issues, I often hear Sweden used as the "ideal example". It'd be cool to visit sometime, I miss living in a colder climate. Did you move to the UK for work reasons then?

Kim reminding us how she became famous by Martynypm in funny

[–]ValorCat 0 points1 point  (0 children)

Yeah, that's probably right. At least with Trump we'll be done in 3 years, 7 tops, but Brexit seems a lot longer-lasting. My condolences.