#Need help with 2D Array

1 messages · Page 2 of 1

sick merlin
#

I think

meager hollow
#

thing is, there is no list of questions u have to pass on an interview. there are no points u get, like in an exam

#

its a gut feeling

#

they ask u questions, supposedly on the whole range of possible topics

#

just to get an idea of ur knowledge spectrum

#

and then they decide based on gut feeling "do we think that this person would be able to do the job?"

sick merlin
#

I've actually also been working on my CCNA so that's gonna take a lot of my time, don't know how much I'll be able to code Java haha

#

Which btw, in your professional opinion

#

What do you think of CCNA?

meager hollow
#

so if i ask in an interview whether u know what a class is or what the private keyword means, and u cant tell that, then its clear to me that u never really wrote any java at all (besides maybe 5 minutes hello world)

sick merlin
#

I think everyone knows what a class is KEKW

meager hollow
#

but if i ask "explain the diff between arraylist and linkedlist" and u cant tell it, thats not a huge bummer. that just means that u never explored the insides of data structures

meager hollow
sick merlin
#

It's trash

#

Why tf would I ever use a linked list

meager hollow
#

yeah so if u would apply to a job where u would have to create ur own data structures / algos, i would reject u then

#

but if thats not the case, i wouldnt care too much

#

cause its just not required

meager hollow
#

but if u would know it, it would add a little plus on my gut feeling that u probably have some experience and are not just a kid who just started coding yesterday

#

so at the end of the day it just adds to the picture/impression people get of u, when they interview u

#

if u apply to a spring based backend job, it would be helpful if u know what spring is and what a database is

#

but for a junior i wouldnt expect too much of knowledge here

#

i would expect a solid java foundation and then maybe a "yeah, i explored spring for 2 weeks and i think im able to understand the code with some assistance"

#

the "solid foundation", people get while doing their 2-3 years studies

sick merlin
#

Does it help that I've done JDBC and PHP with Mysql in the past but don't remember much? 💀

meager hollow
#

or by self-learning/practicing for a similar amount of time

meager hollow
#

if i show u some basic sql, u wouldnt be lost

#
SELECT name FROM persons WHERE age > 25
sick merlin
#

Nope I've done SQL injections

#

So yeah haha

meager hollow
#

see. so thats already more than majority of beginners know

sick merlin
#

Also connecting your JSP page to like JDBC and stuff like that

#

MySQl

meager hollow
#

sounds to me like ur not a beginner but actually have relevant project experience

#

or at least sth in between

sick merlin
#

Like it's just stuff you learn at uni leslie

#

But you tend to forget

#

Like which is bad

#

Obviously

#

I hate that like...I tend to forget stuff, everyone does if you don't review it every other day

meager hollow
#

yeah but it sticks in ur head actually and u can re acquire the full knowledge on demand much much faster

sick merlin
#

Yeah it's ez to go back and review stuff and instantly understand it sure

#

But when you ask me on the spot

#

I might fumble

#

You know what I mean?

meager hollow
#

the good thing about uni is that a degree is essentially, by definition, "having passed the minimum junior requirements"

sick merlin
#

AnD that would make them think I don't know it

meager hollow
#

since the uni takes care to teach all the necessary stuff

#

so for all the students, its fairly easy to get a job. cause they all passed the minimum requirements already

#

maybe add a few side projects on top, so that the CV isnt empty and then ur good to go

#

for people who self-study, its a bit harder, since they have to find the road themselves

#

and spend equivalent time and effort into learning

#

but its doable and at the end of the day, at least for programming, nobody cares how u got that knowledge - as long as u have it

meager hollow
# sick merlin You know what I mean?

yeah but thats okay. thats why u prepare a bit for an interview and if u still get asked sth u dont know ad-hoc, u can always tell them that uve done this in the past and would need a quick refresher first

#

also a reason why i dont mind language switchers too much

#

like, ive had people in java interviews who had 10 years of exp in another language and just learned java for 2 weeks before the interview

#

and then they do simple mistakes

#

like syntax stuff or not knowing the name of a class in java, but knowing it in the other language

#

that just means that they have to google a bit and need more hands on experience. not really an issue in practice

sick merlin
#

Oh yeah and isn't the actual Job different anyway

#

Like the actual job has a different kind of coding

#

You need to learn how to work with the existing company project

#

Which is completely different usually from whatever you know

meager hollow
#

yeah. but thats why i usually concentrate on asking stuff somewhat related to the job

#

like, right now im working as a backend dev on a spring rest api for a webshop

sick merlin
#

That's pretty cool

meager hollow
#

then it would be really cool if someone has actually made a small demo spring webshop project and put that on their CV

#

that would be a huge plus

sick merlin
#

You're a Senior developer I'm assuming

meager hollow
#

by now, yeah

sick merlin
#

And you can help me if you don't mind?

#

I don't know what spring is but still

#

I haven't done a lot of projects so

#

I probably should do some

meager hollow
#

sure. but for a junior i really wouldnt expect more than just following along some simple tutorial

#

a junior needs a solid java foundation, thats all

#

the rest is just bonus

#

with the intermediate developer, i would focus more on code style questions

sick merlin
#

Oh okay and I wanted to ask about APIs in particular

meager hollow
#

like showing them a piece of badly written code and asking for all flaws

sick merlin
#

How do APIs actually work

meager hollow
#

cause the intermediate not only needs the java foundation, but also the library/framework experience + okayish code style

sick merlin
meager hollow
#

yeah dont worry. thats the kind of stuff u care about after u feel comfortable with all the coding already

#

as in "okay im bored. how can i write code better now? so that its more readable and understandable"

#

which directly leads into all the patterns that u can find online

#

such as proxy pattern, builder pattern, whatever ....

sick merlin
#

Yeah I'm not there yet lmao, If I can find the solution to a problem, I'm happy-

meager hollow
#

exactly. and thats really all thats required for a junior

sick merlin
#

I don't care if it's having a Time complexity of O(n^1000)

meager hollow
#

note that in practice its usually more relevant if ur code is readable, than having good performance

#

since performance rarely is a factor ever

#

computers are really powerful, even the bad ones

#

so its about good variable naming, introducing more helper methods, having a good layout of classes, ...

sick merlin
#

I see, well our professor made it seem like Timw and Space complexity, but more so time complexity was a big deal

meager hollow
#

but thats only really relevant once u create projects with more than 10 classes

meager hollow
#

usually, in each project there is like one tiny spot that is supposed to be fast

#

but the remaining 99% dont really matter at all

#

like, who cares if u sort a list of 100 elements in a shitty way if the difference to the fast way is just 2 nanoseconds

sick merlin
#

Ohh I see

meager hollow
#

meanwhile ur reading a file and it takes 1000 the time

#

so "mistakes" dont matter in 99% of ur code

sick merlin
#

Most code that I've seen is just full of stuff thats already present

#

Like you're just using the different methods of the class already implemented by someone

meager hollow
#

yeah and thats a beauty of java. u rarely have to reinvent the wheel

#

everything exists already

sick merlin
#

Yeah that's why I'm starting to prefer Java a lot more

#

It's just very convenient

#

I wasn't liking it last semester but I then I got an A in it leslie and I thought...You know what, maybe this is actually fun

meager hollow
#

ive been in a c++ job with a "no libraries" policy and we wanted to make a simple http request to a rest api. it took us about 6 months to write the code for that

#

meanwhile in java its 2 lines of code...

#

ill never forget that

sick merlin
#

No libraries policy??

#

What

#

Can't they just audit the library if they're so scared??

meager hollow
#

the main reason was that the company did not want to be dependent on someone else

#

as in, imagine that they introduce a bug or go down or stop supporting a new c++ version or ...

#

that could potentially ruin the whole business

#

in theory

#

but then again... letting 4 developers work for 6 months on this bullshit, probably spending 2 million worth of salary...

#

that calculation just doesnt work out lol

sick merlin
#

And what if you guys couldn't come up with it

#

Cause some stuff is genuinely extremely hard without libraries

#

That's kinda dumb, libraries exist for a reason

#

Wtf

meager hollow
#

yeah. so with c++ we had to start at the lowest level. for making our rest api call, we first needed to implement TCP with the windows socket API, then build HTTP on that TCP layer, introduce SSL encryption for HTTPS and then build REST on top of that ...

#

and we obviously only implemented like 30% of the full standard

#

cause the full standard is like crazy complex

#

and we hunted and fixed bugs for a few months lol

sick merlin
#

Socket programming? Wtff

meager hollow
#

and all of that just bc c++, in contrast to java, has no http stuff build-in

#

at least not without library

sick merlin
#

C++ has it, you have to import the http library or I forgot it's name

meager hollow
#

well, i learned a lot about tcp/http/... but business-wise it was kinda stupid ngl

meager hollow
#

and i dont know any serious c++ project who isnt using at least the boost library

#

but heck, we didnt

sick merlin
#

Tcp is a layer 4 protocol which encapsulates data at Layer 5 which is Session Layer with a TCP header or a Layer 4 Header, also called a Segment, which then goes to Layer 3 and then an IPv4 header is added and then it's further encapsulated into an Ethernet frame at Layer 2 in which a Layer 2 trailer and a header is added which also checks for errors in the Physical Layer in its trailer using Cyclic redundancy check in its FCS or frame check sequence

#

Then it's de encapsulated when it is pushed up the other computers OSI stack or TCP/IP suite

meager hollow
#

yeah its just the thing on which HTTP is build on top of

sick merlin
#

And you're telling me you implemented all that with code that's crazy

#

I mean you implemented TCP atleast

meager hollow
#

windows offers TCP sockets, which takes away most of the work

#

but still lot to do unfortunately

sick merlin
#

I've done Network programming in my 3rd semester, I hated it leslie

#

It's so pointless

#

There's not much of a point to it

#

Also the CCNA is very good for learning networks, I feel like I am developing an understanding of Networking that I never had while studying for the exam

#

I highly recommend it

#

For anyone interested in Networking

#

Also I wanted to ask about REST APIs

#

Correct me if I'm wrong but REST APIs are used by different applications to communicate with each other right? The applications that have a different format and such

#

Say I wanted to get some hands on experience with REST APIs

#

How would I go about doing that

#

Like I want to understand what exactly it is

#

It's very popular and everywhere pretty much

meager hollow
#

first of all, it helps to understand that computers can talk to each other via "internet"

sick merlin
#

Yes but we're talking about Applications here right

meager hollow
#

but an application runs on a computer

#

u can send arbitrary bytes to computers

#

the protocol that takes care that those bytes also arrive correctly (and it proper order) is the IP

#

(internet protocol)

#

now, build on top of that are two extra protocols that are mostly in regards to fault tolerance and order

#

TCP and UDP

#

TCP for example sends some packages as copies and over different routes, to ensure that the data arrives

#

so far it was just about "how to send the data", but not about how the data itself should look like

#

so u can now send arbitrary data around

sick merlin
meager hollow
#

now, people created a standard for how the data should look like when u do stuff on the web

#

called HTTP

#

http is a human readable format, as the data u send is just UTF-8 encoded text

sick merlin
#

Yeah but HTTP is unsecure

meager hollow
#

yeah but with HTTPS its just HTTP encrypted

sick merlin
#

Data isn't encrypted so uts not advisable to use Port 80

meager hollow
#

so after decrypting, its still human readable

sick merlin
#

Instead you must use 443

meager hollow
#

point is, its easy to use, cause u can read it

#

so if u for example open ur developer tools in ur browser (F12), u can see the whole traffic and read it

#

easy to work with

#

so thats HTTP

#

now, people build another layer on top of HTTP

sick merlin
#

I mean if you're developing the app then yeah

meager hollow
#

to standardize the way how u would interact with an application

#

and thats REST

sick merlin
#

For that purpose, but when you actually release it, you'd probably release it in HTTPS I guess?

sick merlin
meager hollow
#

for example, when there is a rest server online that saves persons (maybe in a database), then REST would say "if u want to delete one of those persons, then u should send a HTTP DELETE request to thatWebsite/persons/123 with maybe the ID of the person

#

or

#

"if u want to edit the person, send a HTTP UPDATE request to thatWebsite/persons/123 and in the body, have the new data"

sick merlin
#

Hold on, wouldn't that be the job of your Delete.php code?

meager hollow
#

no. thats the thing

sick merlin
#

Or update.php

meager hollow
#

in the past, before REST, people came up with their own ideas of how to work with the data

#

what ur mentioning is one of such self creations

#

but people wanted to standardize that

#

after a few years of pain

#

so they invented REST

sick merlin
#

Well I've personally made these update.php, delete.php pages and done it for a website leslie

#

So that's why I'm confused

meager hollow
#

yeah sure. thats just how it was done before REST

#

there was no actual standard. people did what they thought was reasonable

#

everyone came up with sth else

#

using HTTP the way they thought it would make sense

sick merlin
#

Oh now I understand...so it's a standardized way of...interacting with an application

meager hollow
#

exactly!

#

rest says "design ur api this and that way"

sick merlin
#

REST does everything then?

#

It interacts with the DB

#

It fetches information

meager hollow
#

nah, it just describes how to do the user interface

sick merlin
#

It processes requests

meager hollow
#

everything else u have to code urself

#

like, it says "if u want to offer persons, instead of coming up with ur own ideas, please do the following:

  • for creating new persons: HTTP CREATE website/persons body=person data, as json
  • for deleting a person: HTTP DELETE website/persons/123 no body
  • for editing a person: HTTP UPDATE website/persons/123 body = new data
    ...
#

and it also talks about the return codes ur supposed to send

#

200 OK, 202 CREATED, ...

#

and whatever

#

and REST is also supposed to be "stateless"

sick merlin
#

Those are standard HTTP Server side/client side codes though

#

Like 200, 203, 403

#

You'd be having those anyway

meager hollow
#

that means, if u want to create a person, instead of offering maybe a 2 stage process where one first has to call HTTP GET website/person/getId.php and then HTTP PUT website/person/create.php?id=123, ur supposed to offer one single endpoint that does everything

#

so that u dont have to remember a state

meager hollow
#

REST tells u to follow the standard

#

for example, REST says to use 204 NO CONTENT when u update a person

#

since ur not supposed to send back a response body

#

instead of using 200

#

🤷‍♂️

#

anyways. its really just to have one standard way of doing these apis

sick merlin
#

Like I know the meaning of stateless in the context of a firewall

#

But here, I don't really get it

meager hollow
#

mh. suppose ur at mcdonalds and want to order at one of those order machines

#

u click 5 buttons, building ur basket

#

right?

#

then u pause and go to the restroom

sick merlin
#

Yes

meager hollow
#

now in the meantime

#

what if someone else goes to the machine

#

its still in ur order-process

#

not yet done

#

REST wants to avoid that. REST wants u to have a single interaction

#

u dont clicky click 20 times

#

u click one time only

#

imagine having written down ur full order and everything on a paper beforehand

#

and letting the machine scan it once

#

and imemdiately order

sick merlin
meager hollow
#

cause everything is there on the paper already

#

its about the interaction

#

is the interaction a single "here is everything u need. now go and do it"

#

or is it a

#

"first step : ... okay, now second step: ..., third step: ..."

#

if u want to create a new person, do u do one single http call or do u have to do 5 calls?

sick merlin
#

Just one call I'd imagine

meager hollow
#

if u want to delete a person, do u do one single http call or do u have to move around 2 websites and submit that one form and with the result of that call another website and ...

meager hollow
#

it wants to avoid that u create complex processes that require multiple calls

#

i.e. maintaining a state or session of the interaction

#

in particular, the order shouldnt mention

#

lets say:

meager hollow
#

u shouldnt create a deleteLastOrder.php

#

but a deleteOrder.php?orderId=123

meager hollow
#

but also order, as just shown

#

deleteLastOrder depends on the current interaction state

#

if u call it twice, it changes its meaning

sick merlin
meager hollow
sick merlin
#

And then you can work with it there and it'd appear in the delete.php?orderID= user has entered here

meager hollow
#

also, i was just giving an example

#

forms are just an invention of people who created browsers. HTTP doesnt know any of that, it doesnt care

sick merlin
#

Forms are the main way you carry input over to your backend page though, be it Node.js, PHP, whatever right

meager hollow
#

if u think about actual websites where users click around, yes

sick merlin
#

It's like how you do it

meager hollow
#

but most apis are not used by frontends

sick merlin
#

I haven't worked with an API at all, like I have no experience with them

#

And I'd like to get some tbh because it's hard to understand exactly what you're telling me haha

meager hollow
#

yeah sure. i think it helps to demystify http by writing ur own socket based http server in java once. at least a super bare bones

#

its surprisingly easy

sick merlin
#

Write my own server? That I can then host?

#

Like a Python server in Linux?

meager hollow
#

yes. but i mean really just a java program that, when u run it and someone (like ur browser) connects to it, sends some hello world website

#

so that u can open in ur browser localhost:8080 and it shows ur own example website

#

served by ur java code

#

at which point u can see in java how ur browser talks to it

#

and how HTTP works

sick merlin
#

That's exactly what JSP was right

#

Or not?

meager hollow
#

but jsp is a framework

#

u dont understand how it actually works by using it

sick merlin
#

Well..Yeah I mean

meager hollow
#

jsp was an attempt to make something like php in java

#

its legacy though

sick merlin
#

Did they teach us another Legacy thing and leave it behind

#

That's unbelievable

#

Quite infuriating

meager hollow
#

essentially, everything web related in java got replaced by spring about 20 years ago

#

or well, id say it took a bit to actually replace but u wouldnt see any non spring stuff since 10 years anymore

sick merlin
#

Spring wasn't even mentioned in the CSE1007 Java Programming 4 credit course I did

meager hollow
#

unless in some legacy projects

#

spring essentially lets u write a full rest api, with database and everything in just 10 lines of code or so

#

and it has a solution for everything

sick merlin
#

It was JDBC, Java FX which sucked, JSPs, OOPS, Java applications all that stuff

meager hollow
#

like, imagine u want to add google based user login to ur code

#

sounds complex but spring got u covered with just 2 lines of code or so

#

its the standard for backend stuff

sick merlin
#

That's...so simple

meager hollow
#

but therefore its also quite big and complex

#

and it uses a lot of advanced java stuff

#

it feels like black magic to a lot of beginners

#

in particular to everyone new to dependency injection

sick merlin
#

Just how recursion felt to me

meager hollow
#

yeah

#

its definitely not sth to slap a beginner in the face

#

but its definitely the standard used in majority of java based jobs

sick merlin
#

I'll look into Spring, if it's just 2 lines of code for stuff like that, it's worth looking into

#

What would you recommend, like how to start working with APIs a little and get some experience with them and what they are

#

Which Applications API to sort of start and tamper with, just to see how it works

meager hollow
#

theres this:

#

which is like the example rest api everyone works with for trying out stuff

sick merlin
#

Oh yeah...I know Json is used for configurations and like making data travel I guess

#

But I've never used JSON

meager hollow
#

its just the standard way of representing data in readable text nowadays

#

technically for REST it doesnt matter though

sick merlin
#

And Idk what it actually is, I've configured JSON in like VS Code I guess

meager hollow
#

its just a way of representing ur data in a readable way

sick merlin
#

Okay but why though, why would I need JSON

meager hollow
#

spring supports automatic conversion of java objects to json and vice versa

meager hollow
#

lets say Person p = new Person("John", 20)

#

now u gotta send this from A to B

#

so what do u send

#

u can come up with ur own thing now

#

for example maybe

sick merlin
#

Probably the .java file itself lol

meager hollow
#

Person object[name=John;age=20]

meager hollow
#

not the actual object

sick merlin
#

You can just like send a class that inherits that object I guess

meager hollow
#

but thats still not the actual object

#

its just ur code

sick merlin
#

You'd be able to use the object though

meager hollow
#

okay, another example

#
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a name:");
String name = scanner.nextLine();

System.out.println("Enter an age:");
int age = scanner.nextInt();

Person p = new Person(name, age);

// send that person to our api
api.createPerson(p);
#

now, how would createPerson work?

#

its supposed to send this person data to the rest api

#

u can now come up with ur own shit

#

for example

sick merlin
#

Is api a class that this class inherits or implements or something? What is api.

meager hollow
#

okay. let me put it that way:

#
Socket api = new Socket("http://myWebsite/createPerson");
api.writeBytes(...);
#

now, how do u transmit ur person data to that server?

#

u can only write bytes

#

u got ur p java object. and now?

#

there is no "java object to bytes" thing

#

u have to come up with something now

#

another example. suppose ur java program can write emails

#

and now u want to send this person object "via mail"

#

mail.writeMessage(...);

#

what to put there? it wants a String from u

#

so now u need to figure out how to make ur Person a proper string

#

in a way that the person reading the email can read it

#

and potentially put it back into an object of their language of choice

#

maybe c++

#

so. now u can come up with ur own crazy ideas/formats/standards

sick merlin
#

p.toString() leslie

#

And send it

meager hollow
#

but u have to write toString, otherwise it ends up as Person@A13DF5 only

#

so what do u write in toString

#

should it be John, 20 years old

#

or

#

Person[John, 20]

#

or

#

John=20

#

or daskdqwke132keq23keawskdaksdJohn----20----LOOOOL

sick merlin
#

I mean you can use .join

meager hollow
#

ur not getting the point

sick merlin
#

String.join("", str)

meager hollow
#

its about deciding for a format

#

not how to code it

#

thats trivial

sick merlin
#

Oh okay

meager hollow
#

it should be sth that is:

  • readable by a human
  • easy to work with from code
sick merlin
#

I see what you mean on reading through it

meager hollow
#

lets say u send it as John,20

#

return name + "," + age;

#

now, the receiver could write simple code like:

#
String message = mail.receive();
String[] data = message.split(",");

Person p = new Person(data[0], Integer.parseInt(data[1]);
#

to receive back an object in their favorite language

#

okay so far?

sick merlin
#

Okay you are not splitting the mail with a " " that's my only problem but yes I'm good 😆

meager hollow
#

i used , not space

#

but oaky, we can also go with space

#

then the toString will be name + " " + age;

#

and we can split on space then on receiver side

sick merlin
#

Yess that's just what I like, just add space to everything like normal, like you would in a sentence and it's easy to split a string then you know

meager hollow
#

now, we created our own protocol for sending AND receiving a person object via mail, by temporarily transforming it into text - following some pattern we just invented (data separated by spaces)

#

and that works perfectly fine

#

until...

#

what if the name contains a space?

sick merlin
#

Uhhh

#

Well

meager hollow
#

now we have a problem

#

so we come up with solutions to that problem

#

for example

sick merlin
#

Yes that would be an issue

meager hollow
#

if sth contains a space, we add quotation marks around it, to indicate start and end

#

resulting in

#

"John Smith" 20

#

the receiver side is more complex now

#

but it can be done

#

next problem

#

what if the name contains a quotation mark?

#

solution:

it must be escaped, lets say by writing two ""
resulting in
"John Smi""th" 20

#

congrats. u just invented whats called CSV

sick merlin
#

You're gonna give up at some point I believe, the name could have anything like ^*&%$'

meager hollow
#

yeah but the above idea actually works well

#

its called CSV

sick merlin
meager hollow
#

usually its used with comma or semicolon, but technically it doesnt matter what the delimiter is

#

yes

#

now, next issue

#

what if u have nested objects

#

like, lets say john has a pet

sick merlin
#

What does the excel file format have to do with escaping a string though

meager hollow
#

CSV is a way to represent data properly

#

with all the issues solved

sick merlin
#

Oh I see and it's always in a table?

meager hollow
#

csv has nothing to do with excel

sick merlin
#

A big table with 2 or more columns

meager hollow
#

its just that excel tables naturally make sense to be represented as csv

sick merlin
#

I didn't know that, I thought Csv was an excel file format that's all

meager hollow
#

🙂

#

so, csv is not good for representing nested data

#

which we will see next

#
List<Animal> pets = List.of(new Dog("Bob"), new Cat("Jane"));

Person p = new Person("John", 20, pets);
#

how to represent that with text now

#

in a way that we can understand what it is

#

now it gets complicated

#

so. u can come up with ur own ideas now again

sick merlin
#

We have a list now right

meager hollow
#

yes

#

and the list can contain different types

#

we have to know the types on the other side

sick merlin
#

We could just...convert the List to a String again and then it's just another John

meager hollow
#

so do u want this?

#
John 20 Bob Jane
#

but then, how do we know on the receiver side who is a dog and who a cat

#

or are both cats?

#

or a fish maybe?

sick merlin
#

We could send them a reference like....The text sent to you after the age, rhe first one with an ID of 1 is a dog and the Id of 2 is a cat

#

So we could attach a code or a number along with the Bob and Jane

meager hollow
#

yes

#

okay, next problem

#

what if dogs can optionally contain a birth-name

#

like before they got renamed

sick merlin
#

What would that even look like

meager hollow
#

lets say Bob was originally called Karl

#

we end up with

sick merlin
#

And now you want to change it?

meager hollow
#
John 20 Bob Karl Jane
#

but now we cant differentiate anymore if its 3 animals or 2 animals where one had an original name

#

so we need to start to introduce certain "start and end" markers

#

for example

#
John 20 (Bob Karl) Jane
sick merlin
#

Karl would again get a code of O1 indicating that O means original and 1 means dog that is Bob and to ensure it relates to Bob , we can have an arrow pointing to Karl I guess from Bob

meager hollow
#

okay. im sure i would find more issues with that

#

anyways

#

long story short, at the end of the day, after fixing all "issues", u end up with JSON

sick merlin
#

1Bob -> OKarl or whatever

meager hollow
#

or similar protocols like XML

sick merlin
#

Okay and?

meager hollow
#

so JSON, XML and friends are standardized text formats that solve all those issues

#

so instead of inventing ur own thing

#

u can just use those

sick merlin
#

How though

meager hollow
#
{
  "type": "Person"
  "name": "John",
  "age": 20
  "pets": [
    {
      "type": "Dog"
      "name": "Bob",
      "originalName": "Karl"
    },
    {
      "type": "Cat",
      "name": "Jane"
    }
  ]
}
sick merlin
#

Ohhhhhhh

#

Holy shit that makes so much sense

meager hollow
#

or in xml:

<person>
  <name>John</name>
  <age>20</age>
  <pets>
    <dog>
      <name>Bob</name>
      <originalName>Karl</originalName>
    </dog>
    <cat>
      <name>Jane</name>
    </cat>
  </pets>
</person>
sick merlin
#

Hey you know, maybe you should archive this channel hahaha, so I can keep coming back to read stuff if I have doubts again regarding any of this

meager hollow
#

haha 😄 u can /bookmark it

sick merlin
#

This is a great explanation honestly

meager hollow
#

ur welcome

sick merlin
#

It is crazy how I am now able to really understand the meaning

meager hollow
#

so yeah. the advantage of using JSON or XML instead of ur own thing (which technically would work fine as well) is not only that u dont have to solve all those problems anymore, but u also dont have to write code to make ur object to text and text back to object anymore

#

u can just use a library like Jackson

#

and do

#
String json = jackson.write(p);
#

and

#
Person p = jackson.read(json, Person.class);
sick merlin
#

We've all heard of this stuff like Json and even see it but never used it or never really been properly explained

meager hollow
#

and that above jackson stuff is build-in in spring

#

so u can just do

sick merlin
#

Oh that's so neat

#

Jackson would jsut create a separate JSON file I'm guessing

#

Once you run the program

meager hollow
#
@Update
public User editUser(String id, User newData) {
  userDatabase.update(id, newData);
  return newData;
}
#

and spring will automatically transform everything for u

sick merlin
#

What do you connect Spring to

#

MySQL

#

?

meager hollow
#

it works with any database

sick merlin
#

MongoDB

meager hollow
#

being the industry standard, it supports them all

#

the main point here is that it magically transforms above method into a http endpoint

#

like, with above method, u now can call

#
HTTP UPDATE website/editUser?id=123

{
  "name": "John",
  "age": 20
}
#

sending that body

#

as json

#

and it will automatically understand everything and do it

#

and return back json again

#

by auto transforming the object to json

sick merlin
meager hollow
#

to the frontend who called it

sick merlin
#

Oh that's so neat

#

That's awesome really

meager hollow
#

even though most apis are not meant to be consumed by websites directly, ur browser is actually capable of viewing json nicely as well

#

like, look at this example rest api call

#

which returns json

#

and ur browser should display it nicely browsable

sick merlin
#

How'd you manage to host a dummy website so quickly?

#

What the hell

meager hollow
#

but i indeed can spin up sth really quickly, since i have setup a free DNS record to my machine

sick merlin
#

Nvm you said DNS

#

It's not a server I just realized

meager hollow
#

it is

#

and it has a port

#

if u dont write any port explicitly, it implicitly uses port 80

sick merlin
#

For you to host it on the WWW

#

When you start your own server in like a Linux machine

#

You need to forward that port in order to host your files on the WWW, files that you want to serve to someone maybe on the other side of the world

meager hollow
#

u always have to do port forwarding

#

IP addresses point to ur router, not to a pc

#

so u have to tell the router to which machine in its network it should forward the traffic to

#

like, maybe traffic on port 80 is supposed to go to ur computer

#

and traffic on port 1000 to ur sisters computer

#

and on port 1020 it should be forwarded to ur mobile phone

#

thats what port forwarding means

#

DNS is a service that points a name to a ip address. thats all

#

for example my current ip is 37.201.34.222

#

so u could now type in ur browser 37.201.34.222:80 and it would connect to whatever is currently setup on my router to listen to port 80

#

(which is nothing)

#

but since nobody can remember numbers, u can setup a DNS entry

#

and associate a name with that IP

#

for example duckdns provides that for free

#

resulting in pitaya.duckdns.org to be the same as above IP

sick merlin
meager hollow
#

u do have to do it always

#

imagine ur living in a house that has 5 appartments but only one box for letters

#

and people dont write the names on the letters

#

but just "to this house"

#

nobody would know which letter is for whom

#

port forwarding is the process of putting names on the letters

sick merlin
#

So you can say that for port x you can forward the traffic to 0.0.0.0/0 basically create a default route to the internet

#

Forward it through whatever interface/port you need it to forward out of

meager hollow
#

huh?

#

if someone comes with traffic to ur router, "hey there, i have a request, port 80"

#

ur router has to decide to which of the 10 machines in ur home network to put that traffic to

#

so u go into ur router settings and tell it

#

"hey router, any incoming traffic to port 80, please move that to the my computer. traffic for port 1000 please to my sisters computer and traffic to port 2000 to my mobile phone, thanks"

sick merlin
# meager hollow so u go into ur router settings and tell it

I mean if all the devices are connected to the router and if traffic comes that is intended for a particular device, the router would know which device to forward the traffic to, it would be the device requesting it as it's Destination IP address would probably be listed on the packets coming for them

#

It's on the IPV4 header, the destination and source IP address

#

That is how it's been explained to me

meager hollow
#

the IPs point to routers though

#

not to individual machines

#

the IP of ur machine, the machine of ur sister and ur mobile are all the same, since its the IP of ur router

#

u dont have individual IPs

#

at least to outsiders

#

the router also uses its own independent IP subnet for giving out local addresses for managing its own connected devices

#

but those IPs are not exposed to anyone other than the router itself

#

hence they are called local IP

#

and usually always look like 192.168.0.xxx

sick merlin
#

Apparently

#

I'm not too familiar with WiFi as of yet, cant say for sure

spice wingBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍

sick merlin
#

heyy Zabuzard @meager hollow

#

whats going on??

#

had a question I wanted to ask you, its a bit of a weird one

#
import java.io.*;

public class My_project {
    public static void main(String[] args) {

        String inputFile = "test.txt";
        String outputFile = "output.txt";

        try {

            FileReader fileReader = new FileReader(inputFile);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            FileWriter fileWriter = new FileWriter(outputFile);
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
            String line;

            while ((line = bufferedReader.readLine()) != null) {
                line = line.replaceAll("\\b\\d{1,2}:\\d{2}\\b", "");
                bufferedWriter.write(line);
                bufferedWriter.newLine();
            }

            bufferedReader.close();
            bufferedWriter.close();
            fileReader.close();
            fileWriter.close();

            System.out.println("Timestamps removed and output written to " + outputFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
#

So I was watching Youtube videos and learning and copying some of the transcript content in my notes

#

but the issue I was having was the timestamps and I really wanted to remove them

#

so I thought I'd write a program in Java to solve my problem for me

#

But the issue is, its not quite how I want it to be

#

The output text is something like this

#

it does remove the timestamps but

#

but I dont want the lines to come out like that with like a space in between

#
For example, in this network traffic from PC1 to PC2 usually follows this path.
But what if this connection is cut off? This switch will think: I can’t reach this neighbor anymore.
I’ll clear all entries for this interface from my MAC table, and its other interface will
become the root port. Then, if PC1 wants to send traffic to PC2 again, it will go through the normal process
of flooding until it learns the MAC address on this new interface, and traffic will now follow this path.
That’s just a quick look at how topology changes are handled in rapid STP.
#

This would be the desired output

#

Not sure how I can achieve this

meager hollow
#

get rid of the br.newLine()

#

btw, u should use NIO and not this 20 years old way of doing file io

spice wingBOT
#

File IO in Java should be done preferably with NIO (Java 7+), revolving around the classes Files and Path; and not with the old interface File, BufferedReader, FileReader and similar.

NIO is simple to use. The path to a file is represented using the Path class:

Path path = Path.of("myFile.txt");

All file operations can be found in the Files class:

// Reading
List<String> allLines = Files.readAllLines(path);
// or as a single string
String content = Files.readString(path);
// or with a stream
try (Stream<String> stream = Files.lines(path)) {
  stream.forEach(System.out::println);
}

// Writing
Files.write(path, lines);
// or as a single string
Files.writeString(path, "hello world");
// or with extra options
Files.writeString(path, "hello world",
  StandardOpenOption.WRITE,
  StandardOpenOption.CREATE,
  StandardOpenOption.APPEND);

If you need more control over the process, you can fallback to the old interface, but prefer using the bridge methods from NIO (Files.newBufferedReader, Files.newInputStream, path.toFile() and similar) to benefit from advantages such as correct encoding and better error detection.

Here is a simple example of how to read a file line-wise with the old interface

try (BufferedReader br = Files.newBufferedReader(path)) {
  String line;
  while ((line = br.readLine()) != null) {
    System.out.println(line);
  }
}

it is way more verbose than NIO but it gives more control.

You must not forget to close file handles, even in all exceptional cases. Closing a handle manually is very hard, which is why you should always use try-with-resources for this to let Java automatically close the handle for you:

try (SomeResource resource = ...) {
  ...
} // Automatically closed here, even in exceptional cases
meager hollow
#

a much easier way to do file io

sick merlin
#

This is what happens when you get rid of the Newline

sick merlin
#

So that wasn't the desired output

#

yeah Idk how you can achieve that really

meager hollow
#

then its probably a line that, after the replace, is almost empty but still contains a newline and then u print that

#

hard to guess. please send the input file