First time flyer. Flying alone. 7:00 a.m Flight from Boston, landing at 8:27 am. Both Flights United, and both bought on same itinerary. My flight is at 9:08 going to Sarasota, Fl. I assume I will be at the Same terminal, but I don't really have any idea.
I give this 50/50 chance at best, especially this time of year. 40 minutes is tight even in the best of circumstances but Newark has lots of traffic, lots of delays and is prone to weather issues (as is Boston for that matter). The United terminals are huge, so it can easily be a 10 minute hike between gates. I never had to go through security while connecting, so I doubt that'll be an issue.
Get the United app installed on your phone: that's the quickest way of checking what gate your connection is departing and on whether it's on time or not. You can do this while your still taxiing after landing. If it's super tight you can sometimes beg the other passengers or the flight attendants to let you get off first. If your stuck in the back of the plane, that's going to be a problem.
I would call United ask for a change, perhaps an earlier flight out of Boston. 40 minutes in a massive airport like EWR seems unreasonable.
And don't check any bags!
United has two terminals at Newark, A & C. Your flights are both likely but not guaranteed to land at/depart from C. Even if you do have to transfer, there's a shuttle that does not require you to go through security again.
The good news is that if United sold you that connection as a single ticket, it's a legal layover. So even if you do miss the connecting flight, they'll put you on the next available flight for free.
I've had short layovers going to Beijing from orlando with a connection in EWR. Both flights are in terminal C with United. You can google both flight numbers (with departing and arriving airports) to see their terminal schedule for the year -- this is 2019's schedule for one of my flights: https://info.flightmapper.net/flight/United_Airlines_UA_617