Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
I'd say that's where Java shines, even. There are quite a number of large sites out there that have a friendly PHP face (e.g. blah.php all over URLs), but where the actual grunt work is done in Java - business logic, event handling (through JMS), database I/O (through JDBC), etcetera. By splitting PHP and Java you can have PHP-talking web designers concentrate on the look and feel of the site, and Java developers doing all the business integration that's often necessary in the back - by using Java, you gain access to better libraries, better scalability and performance, and often better developers as well.
Is it possible to write something in pure java and what exactly?
Yes, You could do something as simple as opening a text file, parsing it and saving manipulated information in another text file. Furthermore you could batch that job and then even send it via email to someone :)
You can definitely write Java code that does not rely on UI code to function. For instance, I wrote a console-based executable JAR that recursively finds, tags, and marks images in a particular directory on my headless server. You can start by creating a simple class with a "public static void main(String arts)" method and have your debugger execute it.
At my last job, we used Java to do geospatial processing; find the quickest/shortest routes between points A and B, line-of-sight calculations, etc. These results were fed into a GUI component, but it was separate from the geo code.
There's plenty of stuff that Java's good for that doesn't involve the Web or GUIs.