[ cyb / tech / λ / layer ] [ zzz / drg / lit / diy / art ] [ w / rpg / r ] [ q ] [ / ] [ popular / ???? / rules / radio / $$ / news ] [ volafile / uboa / sushi / LainTV / lewd ]

λ - programming

/lam/bda /lam/bda duck
Name
Email
Subject
Comment
File
Password (For file deletion.)

BUY LAINCHAN STICKERS HERE

STREAM » LainTV « STREAM

[Return][Go to bottom]

File: 1436301635053.jpg (32.87 KB, 600x400, java-logo-blue.jpg) ImgOps Exif iqdb

 No.7343

Any and all Java questions and discussion here. Do RTFM when in doubt. If you did RTFM but are still confused or it didn't have enough classes to get things done, this thread is for you.

>RTFM

https://docs.oracle.com/javase/8/docs/

It's a big language that tends to cause a lot of frustration when least expected, while still being one of the most demanded skills in information technology.
>>

 No.7344

Okay lainons, is there any way to prevent changes to Array done in another method from altering the original Array other than copying the damn thing and making changes to that?

>>

 No.7360

>>7344
Nothing short of making the copy yourself and passing that copy to the method. However, there's a better way: http://clojure.org

>>

 No.7397

corporate languages are anti-cyberpunk

>>

 No.8609


>>

 No.8622

>>7397
It is cyberpunk, it's just evil. Sort of like how Google^h^h^h^h^h^hAlphabet and Microsoft are evil, but also cyberpunk.

>>

 No.10023

I've been asked to tutor someone in AP Computer Science and they're learning Java.

I'm familiar but haven't brushed up in a while -- does anyone know a good book I can use to relearn to the point where I can feel comfortable teaching?

>>

 No.10025

Depends on how quickly you wanna catch up. The JLS[Gosling] is pretty good. But if you wanna catch up quickly go to X in Y and find the Java tutorial and just go from there.

>>

 No.10026

>> 10023
Effective Java may also be beneficial to you. It's more a best practices/Design Patterns type of a book.

>>

 No.10027

>>10025
Awesome. I'd actually never heard of Learn X in Y Minutes. It's the exact refresher I need.

>>10026
I'll check into it. Thanks!

>>

 No.10028

Can anyone reco me a JavaFX book?

>>

 No.10064

File: 1443684851187.jpeg (45.44 KB, 1024x768, 1550515452_upset_boss.jpeg) ImgOps iqdb

TFW still using Java 6 because Enterprise

>>

 No.10576

How would I break up a string into smaller parts based off of capitalization. So if the user puts in ClO3 it returns Cl and O3

>>

 No.10577

probably regular expressions.
But try something like :

for(int i = 0; i < str.length; i++){
str.charAt(i);
if(isLowerCase(i))
.......

>>

 No.10578

oops meant for
>>10576

>>

 No.10678

>can't override constructor on anonymous class
I know it's stupid and trivial but goddamn if it doesn't piss me off. Is it because it'd look weird, having a class with no name override its constructor? It's such a pointless limitation.

Anyway writing more Java and working on irl projects makes me understand why it is the way it is for the most part. I still don't like the language as a whole, but I appreciate that its design goals are consistent and understandable, even if they're flawed.

For example, there's a point where you need to stop and realize that having anonymous functions would be a good thing. Option 1: pass a void anonymous function that takes no arguments. Option 2: create an interface specifically for void functions of no arguments, with a single method, then implement that interface wherever you want to use it.

It doesn't help that the syntax for doing trivial things feels verbose, either. The language just seems like it should only be written in some huge IDE that inserts boilerplate automatically.

(Sorry for complaining about the language in its discussion thread)

>>10576
This works, but it's long. I'm only using it because pattern's split method destroys the pattern you supply as a delimiter, which is not what you want.
import java.util.*;

public class SplitCaps {
public static void main(String[] args) {
demo("Hello World");
demo("AbCdEfG");
demo("AbCdEfGh");
}

static void demo(String str) {
for(String s : splitcaps(str)) System.out.println('"' + s + '"');
System.out.println();
}

static ArrayList<String> splitcaps(String input) {
ArrayList<String> res = new ArrayList<String>();
StringBuffer str = new StringBuffer();
char c;
for(int i = 0; i < input.length(); i++) {
c = input.charAt(i);
if (Character.isUpperCase(c) && str.length() != 0) {
res.add(str.toString());
str.delete(0, str.length());
}
str.append(c);
}
if (str.length() != 0) res.add(str.toString());
return res;
}
}

/* program output:
"Hello "
"World"

"Ab"
"Cd"
"Ef"
"G"

"Ab"
"Cd"
"Ef"
"Gh"

*/

>>

 No.10682

Clojure > Scala > poop > Java8

>>

 No.10683

>>10678
Not to bikeshed here but I think it's cleaner to use substring instead.
    static ArrayList<String> splitcaps(String input) {
ArrayList<String> res = new ArrayList<String>();
int last = 0;

for(int i = 0; i < input.length(); i++) {
if (Character.isUpperCase(input.charAt(i)) && last != i) {
res.add(input.substring(last, i));
last = i;
}
}

if (last != input.length()) {
res.add(input.substring(last, input.length()));
}

return res;
}

>>

 No.10685

>>10683
Probably more efficient too

>>

 No.10703

>>10683
>>10678
thanks both of you! very new to java, il have to look more into arrays and lists.

>>

 No.12323

Most of the Java code I've seen is pretty bad.

I always see so many lines dedicated to nothing but satisfying an interface requirement.

Would someone here show me an elegant Java program?

>>

 No.12400

>>12323
The power of Java is that it is a bad language. There are no shortcuts; completing a task that should only take 10 lines might be 100 lines. This apparent cost has a few advantages. The first is that one can spend a day programming Java, producing a great amount of code, without having to do much thinking. That is to say, the code to thought ratio is very low, while in languages like Haskell or Lisp it is very high. Another advantage is readability and debuggability- because of how little is possible within the language, the purpose of code is immediately apparent. Java is actually very readable as a result, though it may seem tedious because it is difficult to write.
tldr there isn't any elegant Java and there can't be any elegant Java

>>

 No.12423

>>12400
>there isn't any elegant Java and there can't be any elegant Java
This was the answer I expected.



Delete Post [ ]
[ cyb / tech / λ / layer ] [ zzz / drg / lit / diy / art ] [ w / rpg / r ] [ q ] [ / ] [ popular / ???? / rules / radio / $$ / news ] [ volafile / uboa / sushi / LainTV / lewd ]