• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 18:10
CEST 00:10
KST 07:10
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL59Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event19Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
Program: SC2 / XSplit / OBS Scene Switcher Statistics for vetoed/disliked maps The SCII GOAT: A statistical Evaluation Weekly Cups (June 23-29): Reynor in world title form? PiG Sty Festival #5: Playoffs Preview + Groups Recap
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event RSL: Revival, a new crowdfunded tournament series Korean Starcraft League Week 77 Master Swan Open (Global Bronze-Master 2) [GSL 2025] Code S: Season 2 - Semi Finals & Finals
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
Flash Announces Hiatus From ASL SC uni coach streams logging into betting site BGH Mineral Boosts Tutorial Video Player “Jedi” cheat on CSL Replays question
Tourneys
[Megathread] Daily Proleagues [BSL20] Grand Finals - Sunday 20:00 CET Small VOD Thread 2.0 [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Trading/Investing Thread Things Aren’t Peaceful in Palestine The Games Industry And ATVI
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 546 users

The Big Programming Thread - Page 680

Forum Index > General Forum
Post a Reply
Prev 1 678 679 680 681 682 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Acrofales
Profile Joined August 2010
Spain17970 Posts
November 22 2015 00:39 GMT
#13581
Better to see interfaces as Java's slightly quirky way of dealing with multiple inheritance. It's not wrong what you're saying, but it's a rather dry statement of the definition that doesn't show an understanding of what what the purpose of Interfaces are in Java and what their intended use is.

Interfaces are, quite literally, ways to standardize how to interface with your objects. Other classes can now be written without knowing anything about that object, except that it implements the needed Interface. Just as the user interface abstracts away the nasty details of your program, so does an Interface abstract away from the nasty details of your object.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
November 22 2015 08:29 GMT
#13582
On November 22 2015 09:39 Acrofales wrote:
Better to see interfaces as Java's slightly quirky way of dealing with multiple inheritance. It's not wrong what you're saying, but it's a rather dry statement of the definition that doesn't show an understanding of what what the purpose of Interfaces are in Java and what their intended use is.

Interfaces are, quite literally, ways to standardize how to interface with your objects. Other classes can now be written without knowing anything about that object, except that it implements the needed Interface. Just as the user interface abstracts away the nasty details of your program, so does an Interface abstract away from the nasty details of your object.

It's not multiple inheritance and I certainly wouldn't mention multiple inheritance in the definition of an interface. Interfaces can hardly be called "quirky". On the contrary, I would go as far as calling pure virtual classes in C++ a quirky way of implementing interfaces. Especially if you need to use multiple inheritance to implement multiple interfaces and your compiler doesn't apply the empty base class optimization, which still was common practice last time I read about it.

I find it a good thing that explicit interfaces create a clear separation of implementation and usage.
If you have a good reason to disagree with the above, please tell me. Thank you.
Ropid
Profile Joined March 2009
Germany3557 Posts
Last Edited: 2015-11-22 15:12:11
November 22 2015 15:06 GMT
#13583
Don't worry about how C++ has to use tables with pointers and whatnot: the same happens in Java and there's "interface method tables" to get interfaces to work.

EDIT: Turns out, it's a lot more complicated and not just an index in a table:

There is no simple prefixing scheme in which an interface's methods are displayed at fixed offsets within every class that implements that interface. Instead, in the general (non-monomorphic) case, an assembly-coded stub routine must fetch a list of implemented interfaces from the receiver's InstanceKlass, and walk that list seeking the current target interface.

Once that interface is found (within the receiver's InstanceKlass), things get a little easier, because the interface's methods are arranged in an itable, or "interface method table", a display of methods whose slot structure is the same for every class that implements the interface in question. Therefore, once the interface is found within the receiver's InstanceKlass, an associated offset directs the assembly stub to an itable embedded in the InstanceKlass (just after the vtable, as one might expect). At that point, invocation proceeds as with virtual method calls.


I'd guess that's not done every time. Perhaps the JIT optimizes that away and that whole bunch of stuff happens just once for every spot in the program where a call is?
"My goal is to replace my soul with coffee and become immortal."
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2015-11-22 15:45:31
November 22 2015 15:23 GMT
#13584
Okay, so a string is already an array, yeah?

So when my comp sci class asks me to write a 2 dimensional string array, is that really just a 3 dimensional character array?

(like, I won't write it that way - but that's what it really is?)





edit:
Okay, I am very confused
I am writing in eclipse and I write:

String[][] stringArray = new String[2][2];


stringArray[0][0] = "hello";
stringArray[0][1] = "hallo";
stringArray[1][0] = "hyllo";
stringArray[1][1] = "hullo";



but it refuses to accept this.

It is making me put

stringArray[0][0] = "hello";
stringArray[0][1] = "hallo";
stringArray[1][0] = "hyllo";
stringArray[1][1] = "hullo";

inside braces. So it is making me write



String[][] stringArray = new String[2][2]; {


stringArray[0][0] = "hello";
stringArray[0][1] = "hallo";
stringArray[1][0] = "hyllo";
stringArray[1][1] = "hullo"; }


Why am I having to put that in braces???
Thaniri
Profile Blog Joined March 2011
1264 Posts
November 22 2015 16:33 GMT
#13585
Puttin it within braces lets the code know where the variables within the array are. Say you had two arrays written like this, whos variables belong to who?

At least thats how I understood it, im also a comp sci student and thats just how it's done.
Faust852
Profile Joined February 2012
Luxembourg4004 Posts
Last Edited: 2015-11-22 16:38:18
November 22 2015 16:33 GMT
#13586
+ Show Spoiler +
On November 23 2015 00:23 travis wrote:
Okay, so a string is already an array, yeah?

So when my comp sci class asks me to write a 2 dimensional string array, is that really just a 3 dimensional character array?

(like, I won't write it that way - but that's what it really is?)





edit:
Okay, I am very confused
I am writing in eclipse and I write:

String[][] stringArray = new String[2][2];


stringArray[0][0] = "hello";
stringArray[0][1] = "hallo";
stringArray[1][0] = "hyllo";
stringArray[1][1] = "hullo";



but it refuses to accept this.

It is making me put

stringArray[0][0] = "hello";
stringArray[0][1] = "hallo";
stringArray[1][0] = "hyllo";
stringArray[1][1] = "hullo";

inside braces. So it is making me write



String[][] stringArray = new String[2][2]; {


stringArray[0][0] = "hello";
stringArray[0][1] = "hallo";
stringArray[1][0] = "hyllo";
stringArray[1][1] = "hullo"; }


Why am I having to put that in braces???



	public static void main(String[] args) {

String[][] stringArray = new String[2][2];
stringArray[0][0] = "hello";
stringArray[0][1] = "hallo";
stringArray[1][0] = "hyllo";
stringArray[1][1] = "hullo";

for (int i = 0; i < stringArray.length; i++) {
for (int j = 0; j < stringArray[i].length; j++) {
System.out.println(stringArray[i][j]);
}
}
}


it does work in my Eclipse.

result :
hello
hallo
hyllo
hullo


My guess would be it's making an constructor for this array to complete it because it can't do it directly if it's declared as an instance variable, not sure though, I'm not a java pro.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2015-11-22 16:45:52
November 22 2015 16:45 GMT
#13587
ah ok, it looks like it's not necessary in main but outside of main it is

Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2015-11-22 17:05:53
November 22 2015 17:00 GMT
#13588
String[][] stringArray = new String[2][2] {
stringArray[0][0] = "hello",
stringArray[0][1] = "hallo",
stringArray[1][0] = "hyllo",
stringArray[1][1] = "hullo"};


You should be able to initialize it like this. Not sure where all the extra semicolons are coming from.

It'd be equivalent to declaring an array like
 int[] numbers = new int[10] {1,2,3,4,5,6,7,8,9,0};
I'll always be your shadow and veil your eyes from states of ain soph aur.
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2015-11-22 17:37:51
November 22 2015 17:36 GMT
#13589
On November 22 2015 09:39 Acrofales wrote:
Better to see interfaces as Java's slightly quirky way of dealing with multiple inheritance. It's not wrong what you're saying, but it's a rather dry statement of the definition that doesn't show an understanding of what what the purpose of Interfaces are in Java and what their intended use is.

Interfaces are, quite literally, ways to standardize how to interface with your objects. Other classes can now be written without knowing anything about that object, except that it implements the needed Interface. Just as the user interface abstracts away the nasty details of your program, so does an Interface abstract away from the nasty details of your object.


I'm not sure how it works in Java but in PHP if a class implements certain interface it also becomes an instance of said interface. This is awesome because it lets you create truly modular code by typehinting interface classes instead of what's implementing them, thus allowing you to freely switch between different classes implementing the same interface as parameters.

Also, to combat multiple inheritance, I highly recommend this brief article:

http://ocramius.github.io/blog/when-to-declare-classes-final/

I know for a fact that using final and abstract keywords, as well as interfaces has improved the quality of my code greatly.
Time is precious. Waste it wisely.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-11-22 18:39:15
November 22 2015 17:41 GMT
#13590
On November 23 2015 00:23 travis wrote:
Okay, so a string is already an array, yeah?

So when my comp sci class asks me to write a 2 dimensional string array, is that really just a 3 dimensional character array?

(like, I won't write it that way - but that's what it really is?)


Why am I having to put that in braces???


On November 23 2015 01:45 travis wrote:
ah ok, it looks like it's not necessary in main but outside of main it is



What? No you shoudln't have to put them in braces. The code should work regardless of being in main or not. You're not posting real code because those two should compile fine. If that is real code then something else is wrong.

All you've done in the second piece of code is put those assignments in another scope, which does nothing. There's a semi-colon before your braces so you're not doing array initialization, and that'd be the incorrect syntax for it too.

Don't think of 2D arrays as a grid, or 3D arrays as a cube. A 2D array is simply a list of lists. A 3D array is simply a list of lists of lists. It's silly to relate them to other ideas when they're literally just a list of other lists.

edit: "regardless of being in main or not" ... obviously a gross oversight on my part because my assumption was that if code wasn't in main it was in another function being called by main, which isn't the case here.... totally overlooked the possibility the code was being placed outside of functions... oops
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2015-11-22 17:51:12
November 22 2015 17:50 GMT
#13591
it's real code

http://imgur.com/TYyZO3P

this is the original code

http://imgur.com/E4pZGBP

the error on both says "Syntax error on token ";", { expected after this token
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-11-22 18:07:18
November 22 2015 18:04 GMT
#13592
The problem isn't your code, it's where you're putting them. Damn this will be hard to explain over the Internet...

All of your stringArray stuff is being declared as member variables, which is invalid.

You have a class ewt that has a member variable stringArray and function returnedArray. Those are legal declarations for classes. But stringArray[0][1] = "hello" is an assignment, and that isn't a legal declaration (or a declaration at all). Assignments are only valid inside functions (like main).

Someone else can explain this better because I'm at a loss at explaining this better (not in position to write/post code).
There is no one like you in the universe.
Soan
Profile Blog Joined August 2010
New Zealand194 Posts
Last Edited: 2015-11-22 18:30:31
November 22 2015 18:26 GMT
#13593

package ewtwtetwt;

public class ewt {
public String[][] stringarray = new String[2][2];
}


This is fine and good, you're declaring a new String[][] as part of the class ewt.

If you want to assign values to this array like you are doing, you will need to do it inside a function that is part of that class. Either in the constructor or some other function.


package ewtwtetwt;

public class ewt {
public String[][] stringarray = new String[2][2];

public ewt() {
stringArray[0][0] = "hello";
stringArray[0][1] = "hallo";
stringArray[1][0] = "hyllo";
stringArray[1][1] = "hullo";
}
}


Or you can do it like Blitzkrieg0 said a couple posts above, and initialise it inside curly braces when you declare it.
Housemd
Profile Joined March 2010
United States1407 Posts
November 22 2015 19:34 GMT
#13594
Hey guys, I was wondering you guys could help me out a bit. Basically, I want to make a program that takes a questioner's "keywords" to a certain open-ended question. From there, the responder will write out their answer. The program will check if the answer contains the keywords as put in originally.

So, right now, I've started working on it by taking the response and putting it into a string and taking the keywords and putting them into a string. This is c++ and here is the current code that checks the words in each string. It compiles but I'm not entirely sure if it works 100% and since I don't really have anything to test it on, could someone who knows more than me check if it will work as intended?

bool checkStrings (string str1, string str2){
vector <string> words1, words2;
string temp;
stringstream stringstream1(str1);
while (stringstream1>>temp){
words1.push_back(temp);
}
stringstream stringstream2(str2);
while (stringstream2>>temp){
words2.push_back(temp);
Fantasy is a beast
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
November 22 2015 19:51 GMT
#13595
Why not just use strstr?
Time is precious. Waste it wisely.
Zocat
Profile Joined April 2010
Germany2229 Posts
November 22 2015 19:57 GMT
#13596
On November 23 2015 04:34 Housemd wrote:
It compiles but I'm not entirely sure if it works 100% and since I don't really have anything to test it on, could someone who knows more than me check if it will work as intended?


Then you have to test it yourself. Make up a list of keywords and an answer sentence and see what happens.

What kind of scenarios can happen? The sentence contains all keywords, the sentence contains some keywords, the sentence contains no keywords. (In practice you might also want to check what happens when your input is empty / wrong).
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2015-11-22 20:44:47
November 22 2015 20:36 GMT
#13597
On November 23 2015 03:04 Blisse wrote:
The problem isn't your code, it's where you're putting them. Damn this will be hard to explain over the Internet...

All of your stringArray stuff is being declared as member variables, which is invalid.

You have a class ewt that has a member variable stringArray and function returnedArray. Those are legal declarations for classes. But stringArray[0][1] = "hello" is an assignment, and that isn't a legal declaration (or a declaration at all). Assignments are only valid inside functionsmethods (like main).

Someone else can explain this better because I'm at a loss at explaining this better (not in position to write/post code).


Adding onto this...

Where you placed the code it will never be run. Since it isn't in a method the code will never be executed. You either need to initialize the values when the array is declared (see my previous post). If the values will always be the same then this is how it should be done. Alternately you can make a constructor which will add values to the array when the object is created:

public class ewt {

private String[][] stringArray;

public ewt(String a, String b, String c, String d) {
this.stringArray = new String[2][2];
this.stringArray[0][0] = a;
this.stringArray[0][1] = b;
this.stringArray[1][0] = c;
this.stringArray[1][1] = d;
}
}


If you actually want to add any amount of values then utilizing an Arraylist instead of an array will be helpful so you don't have to worry about size.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Cyx.
Profile Joined November 2010
Canada806 Posts
November 22 2015 22:41 GMT
#13598
On November 23 2015 03:04 Blisse wrote:
The problem isn't your code, it's where you're putting them. Damn this will be hard to explain over the Internet...

All of your stringArray stuff is being declared as member variables, which is invalid.

You have a class ewt that has a member variable stringArray and function returnedArray. Those are legal declarations for classes. But stringArray[0][1] = "hello" is an assignment, and that isn't a legal declaration (or a declaration at all). Assignments are only valid inside functions (like main).

Someone else can explain this better because I'm at a loss at explaining this better (not in position to write/post code).

http://stackoverflow.com/questions/2420389/static-initialization-blocks
http://stackoverflow.com/questions/3987428/what-is-an-initialization-block

Inside a class but outside any method is where you *declare* variables - you can't modify them there. That's what you're trying to do when you say 'stringArray[0][1] = "hello"'.

If you put a block of code within a class but outside a method, ie. surrounded in braces like you did, that's an *initialization block*, which gets run before the class is constructed. You can also prefix the block with 'static' to make it a static initalization block, which gets run once, before *any* instance is constructed.

As an aside, you can also initialize it when you declare it like so:


String [][] stringArray = {
{'hello', 'hallo'},
{'hullo', 'hyllo'}
}
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-11-23 03:58:57
November 23 2015 03:57 GMT
#13599
Cool. Never knew about non-static initialization blocks. So that's how it was able to compile, and somehow able to access the non-static instance of the member variable stringArray. Why does that exist as a feature when you have constructors?

http://stackoverflow.com/questions/3987428/what-is-an-initialization-block
There is no one like you in the universe.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
November 23 2015 05:30 GMT
#13600
This thread has taught me so much the entire time I've been following it. Y'all know your shit.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Prev 1 678 679 680 681 682 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 11h 51m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
JuggernautJason126
ProTech88
Nina 78
NeuroSwarm 0
StarCraft: Brood War
firebathero 239
NaDa 36
Rock 35
LancerX 26
Dota 2
LuMiX1
League of Legends
Grubby3573
Dendi1369
Heroes of the Storm
Liquid`Hasu538
Khaldor269
Other Games
summit1g9604
FrodaN2198
fl0m680
RotterdaM474
Sick60
ViBE28
Organizations
Other Games
BasetradeTV42
StarCraft 2
angryscii 27
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 23 non-featured ]
StarCraft 2
• Berry_CruncH288
• davetesta43
• musti20045 37
• tFFMrPink 19
• OhrlRock 4
• Kozan
• Migwel
• sooper7s
• AfreecaTV YouTube
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• Pr0nogo 8
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota21446
• Ler129
League of Legends
• Doublelift3976
• Jankos2548
Other Games
• imaqtpie1127
• Shiphtur467
• WagamamaTV375
Upcoming Events
RSL Revival
11h 51m
Clem vs Classic
SHIN vs Cure
FEL
13h 51m
WardiTV European League
13h 51m
BSL: ProLeague
19h 51m
Dewalt vs Bonyth
Replay Cast
2 days
Sparkling Tuna Cup
2 days
WardiTV European League
2 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
[ Show More ]
Replay Cast
5 days
RSL Revival
5 days
FEL
5 days
RSL Revival
6 days
FEL
6 days
FEL
6 days
Liquipedia Results

Completed

BSL 2v2 Season 3
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.