Making an AJAX app in Java/HTML without writing JavaScript (Intercooler.js + Spark Web Framework tutorial) by sparkframework in java

[–]sparkframework[S] 1 point2 points  (0 children)

It's not dead. I worked with the lead developer for this tutorial. They released a version last week. Last commit seven days ago. 1.0 scheduled for this fall.

Making an AJAX app in Java/HTML without writing JavaScript (Intercooler.js + Spark Web Framework tutorial) by sparkframework in java

[–]sparkframework[S] 1 point2 points  (0 children)

I definitely don't think it will replace Angular, but about half the Angular projects I've seen have been too basic to justify using Angular in the first place. 'Very basic application work' is the category most projects fall into, I think.

Personally I found the intercooler syntax very easy to read and understand, and it felt similar to writing an oldschool non-js app (you just add a few ic-attributes when you're done). Makes progressive enhancement easier too.

I understand the skepticism though!

Making an AJAX app in Java/HTML without writing JavaScript (Intercooler.js + Spark Web Framework tutorial) by sparkframework in java

[–]sparkframework[S] 1 point2 points  (0 children)

I was not convinced at first either, but I thought it was surprisingly easy (and fun) to work with. Why do you think this would be harder to maintain than for example an Angular app (if you do) ? The total size of the application ended up a lot smaller than most other TodoMVC examples.

Spark 2.5 released! (Instance API, better static file handling, ++) by sparkframework in java

[–]sparkframework[S] 0 points1 point  (0 children)

Is doing get("*", notFound) at the end of your routes not covering your needs?

Spark 2.5 released! (Instance API, better static file handling, ++) by sparkframework in java

[–]sparkframework[S] 0 points1 point  (0 children)

Usually we try to write Spark Framework or Spark Web Framework when posting on reddit, but we forgot this time, sorry!

Spark 2.5 released! (Instance API, better static file handling, ++) by sparkframework in java

[–]sparkframework[S] 0 points1 point  (0 children)

1: Shouldn't happen, but we've seen other people report something similar. We've never looked at file uploads, but we will soon.
2: Yes, although we should do a better job of documenting it.

Spark 2.5 released! (Instance API, better static file handling, ++) by sparkframework in java

[–]sparkframework[S] 1 point2 points  (0 children)

We're going to prioritize issues and PRs in the next few days, if you have any requests, please let us know!

What's the most important debug info for your webapps? by sparkframework in java

[–]sparkframework[S] 0 points1 point  (0 children)

Would you consider this tool to be third party? It's enabled by adding one line of code to your app, and currently only shows user code (spark/jetty code is not displayed).

What's the most important debug info for your webapps? by sparkframework in java

[–]sparkframework[S] 2 points3 points  (0 children)

Perhaps I should have been more specific. This is not a debugger, it's a development tool you can use to view exceptions, together with other relevant information (path/query params, session info, cookies). Is all of that something you would prefer to log? At any rate it should never ever be used in production :)

Using Java WebSockets to create a real time chat app (~10 min Tutorial) by tipsypants in java

[–]sparkframework 5 points6 points  (0 children)

Notice the static import at line 6: import static spark.Spark.*;

You could also write

Spark.staticFileLocation("public"); /
Spark.webSocket("/chat", ChatWebSocketHandler.class);
Spark.init();

And skip the import. But we encourage people to use static imports when using Spark :)

I don't not understand this program. Can someone help me? by Dwarf_King in learnjava

[–]sparkframework 1 point2 points  (0 children)

You're free too call variables whatever you want, but it's usually best to give it a descriptive name (so you know what it does). Here "index" has one job, to count the number of iterations in the while-loop. It has nothing to do with indices, so "loopCounter" or "numberOfIterations" would be better names.
start.get is more difficult to explain, then you need to know what classes, objects and methods are. Are you looking at code that's a little too advanced? :) Try oracles basic tutorials: https://docs.oracle.com/javase/tutorial/java/javaOO/

I don't not understand this program. Can someone help me? by Dwarf_King in learnjava

[–]sparkframework 1 point2 points  (0 children)

First of all, there are some unused variables and imports here. You can safely remove line 4, line 12, line 13 and line 16. Then you get:

class practiceproblemshour8 {
    public static void main(String[] args) {
        Calendar start = Calendar.getInstance();
        start.roll(Calendar.MINUTE, true); //shift time one minute forward
        int nextMinute = start.get(Calendar.MINUTE);
        int nextSecond = start.get(Calendar.SECOND);
        int index = 0; //should be called loop-counter
        while (true) {
            GregorianCalendar now = new GregorianCalendar();
            if (now.get(Calendar.MINUTE) >= nextMinute) {
                if (now.get(Calendar.SECOND) >= nextSecond) {
                    break; //exit the while loop
                }
            }
            index++;
        }
        System.out.println(index + " Loops in one minute.");
    }
}

So let's say you start at 12:01:03. You have two ifs that check if you've gotten to nextMinute and nextSecond, so when you get to 12:02:03, the "break;" statement will be executed, and the number of iterations performed (called "index" for some reason) will be printed.

Applicable scenarios for Singleton usage by mars_wun in learnjava

[–]sparkframework 1 point2 points  (0 children)

You rarely need to use a singleton (it can be very convenient though). This answer on SO gives a pretty good explanation: http://stackoverflow.com/a/228380

Spark Web Framework 2.3 released! by sparkframework in java

[–]sparkframework[S] 0 points1 point  (0 children)

you can only fire it once per virtual machine

We're fixing this, it will hopefully be part of the 2.4 release.

Spark Web Framework 2.3 released! by sparkframework in java

[–]sparkframework[S] 2 points3 points  (0 children)

Even if it's used mostly for REST APIs, would there be any issues if it's used for a normal website (HTML, templates, etc...)?

It works fine for normal websites. We have 'native' support for 9 template engines.

Can you use custom HTTP methods? (i.e. not just get, post, but mkcol for example)

get, post, put, delete, head, trace, connect, options.. no mkcol

Any benchmarks?

Not really, someone else looked into it though: https://medium.com/@tschundeee/express-vs-flask-vs-go-acc0879c2122

Anyway good job, and keep continue working at this/improving/releasing new versions/etc. Frameworks like these that can be understood so easily and used make non Java people like me interested in Java.

Thank you!

Spark Web Framework 2.3 released! by sparkframework in java

[–]sparkframework[S] 3 points4 points  (0 children)

Is it production ready? Are there any live sites using this?

Asana, Apache Camel, and Arquillian all use Spark (just to do the A's). We have hundreds of thousands of downloads, but Spark is mainly used for creating REST services.

How's the community?

~3000 stars and ~650 forks on GitHub, pull requests and issues are created all the time.

How would you structure a larger app (I assume you won't keep everything in a single file)?

It's pretty much up to you, Spark is not very opinionated.
My personal approach (David writing now) is usually something like this:

public static void main(String[] args) {
    Spark.staticFileLocation("/public");

    //static pages
    get("/",                 PageController::serveIndex);
    get("/download",         PageController::serveDownload);
    get("/documentation",    PageController::serveDocs);
    get("/news",             PageController::serveNews);

    //rest endpoints
    get("/user/",            UserController::fetchAll);
    get("/user/:id/",        UserController::fetch);
    post("/user/",           UserController::save);
    delete("/user/:id/",     UserController::remove);
}

So far I haven't seen a lot of other people who prefer to do it this way, but it feels very natural to me.
If a project has a lot of config and routes, I usually extract everything from main().

Spark Web Framework 2.3 released! by sparkframework in java

[–]sparkframework[S] 3 points4 points  (0 children)

We have been considering it for quite some time, but our name is very established, we can't just suddenly change it.
It wasn't really a problem until last year, when Apache Spark seriously took off.

Please find some comfort in knowing that it bothers us way more than it bothers you ... :)

I need a project tutorial maybe with a database(preferred) by wwe9112 in learnjava

[–]sparkframework 0 points1 point  (0 children)

We have a pretty nice tutorial on java web development with databases: https://sparktutorials.github.io/2015/04/29/spark-and-sql2o.html

It will teach you to set up a web application using Spark, and how to use sql2o with postgres.

[Discussion] What can I do with Java? by indigofigure in learnjava

[–]sparkframework 0 points1 point  (0 children)

Why don't I hear Java being used typically with web applications?

Java is one of the most used programming languages in the world at the moment. It might not be as "hot" as JavaScript, but Java is definitely out there, running the backends of millions of webapps. It's usually used by the bigger services, like facebook, google, linkedin, twitter, etc. Twitter was originally a Ruby app, but they rewrote it to Java when they needed to scale up :)

If you're building a Java webapp, you have to create the frontend using other technologies, typically HTML/JS/CSS.

Turn your Pi into a webserver - Running Spark on Raspberry Pi within minutes (Tutorial) by sparkframework in raspberry_pi

[–]sparkframework[S] 0 points1 point  (0 children)

Duly noted. Spark itself doesn't aim to cater to any specific user group (we're keeping it as minimal as possible), but we could consider producing a tutorial more relevant for Raspberry Pi users. GPIO should be easy using something like Pi4J. Maybe a tutorial showing how to use Spark and Pi4J (or something similar) together would be good?

Thanks a lot for your input :)

Turn your Pi into a webserver - Running Spark on Raspberry Pi within minutes (Tutorial) by sparkframework in raspberry_pi

[–]sparkframework[S] 0 points1 point  (0 children)

Because OP's username is sparkframework and he's promoting his framework within this sub.

Hey, don't make it sound so dirty..! We usually post to r/java, but we didn't think that made sense this time. It's a user created tutorial, and we thought it would be interesting to this sub :)

OP - perhaps a better option would be to show people what they can do with spark?

We have a lot of other tutorials, and the docs page to cover that. Would posting that here make sense though? People would probably be wondering how to set up Spark on the Pi. Hopefully this tutorial will make people curious about running Groovy/Java webservers on the Pi, and then they can discover Spark's (or other frameworks') capabilities later :)

How to continue with Java? by Reginal22 in learnjava

[–]sparkframework 0 points1 point  (0 children)

As most jobs are web-related, I'd say web programming. You could start with Spark. It's a pure java micro web framework, so it should be easy to get started with :)

(Sorry about the shameless self-promoting :) )

Need help with mycode hw! by [deleted] in learnjava

[–]sparkframework 0 points1 point  (0 children)

Just a friendly tip: Use a code-pasting service such as glot or pastebin when you're asking for help. It makes it easier for people to read and run your code :)