I'm working on a geographic information system project, whose products form shapefiles. I am using the Java programming language and a PostGIS database. Is there a way to generate a shapefile from PostGIS or KML using the Java language?
You can use geotools to do such actions. You may find here an example converting a java ResultSet to shapefile. Though the example provided is using an oracle ResultSet but you can easily adjust it to accept postgis ResultSet and generate shapefiles.
generate a shp file from PostGIS
H2GIS can import/export SHP files. You can use the SHPDriverFunction by providing a JDBC connection with PostGIS.You should use this connection wrapper in order to bind JTS geometry object to postgis geometry object.
generate a kml file from PostGIS
A KMLDriverFunction is also available.
Please note that the H2GIS library is under the GPLV3 license. In order to use this your software must be open-source.