ホームページ Java &#&チュートリアル Java プログラマーの開発効率を 2 倍にする可能性がある

Java プログラマーの開発効率を 2 倍にする可能性がある

Sep 06, 2024 pm 04:31 PM

アプリケーションにおけるコンピューティングのジレンマ
開発とフレームワーク、どちらを優先すべきですか?
Java は、アプリケーション開発で最も一般的に使用されるプログラミング言語です。しかし、Java でデータを処理するコードを記述するのは簡単ではありません。たとえば、以下は 2 つのフィールドでグループ化と集計を実行する Java コードです:

Map<Integer, Map<String, Double>> summary = new HashMap<>();
    for (Order order : orders) {
        int year = order.orderDate.getYear();
        String sellerId = order.sellerId;
        double amount = order.amount;
        Map<String, Double> salesMap = summary.get(year);
        if (salesMap == null) {
            salesMap = new HashMap<>();
            summary.put(year, salesMap);
        }
        Double totalAmount = salesMap.get(sellerId);
        if (totalAmount == null) {
            totalAmount = 0.0;
        }
        salesMap.put(sellerId, totalAmount + amount);
    }
    for (Map.Entry<Integer, Map<String, Double>> entry : summary.entrySet()) {
        int year = entry.getKey();
        Map<String, Double> salesMap = entry.getValue();
        System.out.println("Year: " + year);
        for (Map.Entry<String, Double> salesEntry : salesMap.entrySet()) {
            String sellerId = salesEntry.getKey();
            double totalAmount = salesEntry.getValue();
            System.out.println("  Seller ID: " + sellerId + ", Total Amount: " + totalAmount);
        }
    }
ログイン後にコピー

対照的に、対応する SQL ははるかに単純です。計算を終了するには、1 つの GROUP BY 句で十分です。

注文 GROUP BY 年 (注文日)、販売者 ID から年 (注文日)、販売者 ID、合計 (金額) を選択します

確かに、初期のアプリケーションは Java と SQL を連携して動作していました。ビジネス プロセスはアプリケーション側で Java で実装され、データはバックエンド データベースの SQL で処理されました。データベースの制限により、フレームワークの拡張と移行が困難でした。これは現代のアプリケーションにとって非常に不親切でした。さらに、多くの場合、データベースが存在しないか、データベース間の計算が関与している場合、SQL は利用できませんでした。

これを考慮して、その後、多くのアプリケーションが完全に Java ベースのフレームワークを採用し始めました。このフレームワークでは、データベースは単純な読み取りおよび書き込み操作のみを実行し、ビジネス プロセスとデータ処理はアプリケーション側で Java で実装されます (特にマイクロサービスが出現したとき)。このようにして、アプリケーションはデータベースから切り離され、優れたスケーラビリティと移行性が得られます。これにより、前述の Java 開発の複雑さに直面しながらも、フレームワークの利点を得ることができます。

開発かフレームワークという 1 つの側面にのみ焦点を当てることができるようです。 Java フレームワークの利点を享受するには、困難な開発に耐えなければなりません。 SQL を使用するには、フレームワークの欠点を許容する必要があります。これによりジレンマが生じます。

それでは何ができるでしょうか?
Java のデータ処理機能を強化するのはどうでしょうか?これにより、SQL の問題が回避されるだけでなく、Java の欠点も克服されます。

実際、Java Stream/Kotlin/Scala はすべてそうしようとしています。

ストリーム

Java 8 で導入されたストリームには、多くのデータ処理メソッドが追加されました。上記の計算を実装するためのストリーム コードは次のとおりです:

Map<Integer, Map<String, Double>> summary = orders.stream()
            .collect(Collectors.groupingBy(
                    order -> order.orderDate.getYear(),
                    Collectors.groupingBy(
                            order -> order.sellerId,
                            Collectors.summingDouble(order -> order.amount)
                    )
            ));

    summary.forEach((year, salesMap) -> {
        System.out.println("Year: " + year);
        salesMap.forEach((sellerId, totalAmount) -> {
            System.out.println("  Seller ID: " + sellerId + ", Total Amount: " + totalAmount);
        });
    });
ログイン後にコピー

ストリームは確かにコードをある程度簡素化します。しかし全体としては、依然として煩雑であり、SQL よりもはるかに簡潔ではありません。

Kotlin

より強力であると主張していた Kotlin は、さらに改良されました:

val summary = orders
        .groupBy { it.orderDate.year }
        .mapValues { yearGroup ->
            yearGroup.value
                .groupBy { it.sellerId }
                .mapValues { sellerGroup ->
                    sellerGroup.value.sumOf { it.amount }
                }
        }
    summary.forEach { (year, salesMap) ->
        println("Year: $year")
        salesMap.forEach { (sellerId, totalAmount) ->
            println("  Seller ID: $sellerId, Total Amount: $totalAmount")
        }
    }
ログイン後にコピー

Kotlin コードはより単純ですが、改善は限られています。 SQL と比較すると、まだ大きなギャップがあります。

スカラ

次に Scala がありました:

val summary = orders
        .groupBy(order => order.orderDate.getYear)
        .mapValues(yearGroup =>
            yearGroup
                .groupBy(_.sellerId)
                .mapValues(sellerGroup => sellerGroup.map(_.amount).sum)
    )
    summary.foreach { case (year, salesMap) =>
        println(s"Year: $year")
        salesMap.foreach { case (sellerId, totalAmount) =>
            println(s"  Seller ID: $sellerId, Total Amount: $totalAmount")
        }
    }
ログイン後にコピー

Scala は Kotlin よりも少し単純ですが、それでも SQL と比較することはできません。さらに、Scala は重すぎて使いにくいです。

実際、これらのテクノロジーは完璧ではありませんが、正しい道を進んでいます。

コンパイル言語はホットスワップ非対応です
さらに、Java はコンパイル言語であるため、ホット スワップをサポートしていません。コードを変更するには再コンパイルと再デプロイが必要になり、多くの場合サービスの再起動が必要になります。このため、要件の頻繁な変更に直面した場合、エクスペリエンスは最適ではなくなります。対照的に、SQL ではこの点に関して問題はありません。

Something could double the development efficiency of Java programmers
Java 開発は複雑であり、フレームワークにも欠点があります。 SQL はフレームワークの要件を満たすことが困難です。そのジレンマを解決するのは難しい。他に方法はありますか?

究極のソリューション – esProc SPL
esProc SPL は、純粋に Java で開発されたデータ処理言語です。シンプルな開発と柔軟なフレームワークを備えています。

簡潔な構文
上記のグループ化および集計操作の Java 実装を確認してみましょう:

Something could double the development efficiency of Java programmers
Java コードと比較すると、SPL コードははるかに簡潔です:

Orders.groups(year(orderdate),sellerid;sum(amount))
ログイン後にコピー

SQL 実装と同じくらい簡単です:

SELECT year(orderdate),sellerid,sum(amount) FROM orders GROUP BY year(orderDate),sellerid
ログイン後にコピー

実際、SPL コードは、対応する SQL コードよりも単純であることがよくあります。 SPL は、順序ベースの手続き型計算をサポートしているため、複雑な計算の実行に優れています。次の例を考えてみましょう。株式の連続上昇日数の最大値を計算します。 SQL には次のような 3 層のネストされたステートメントが必要ですが、記述することはもちろん、理解することも困難です。

select max(continuousDays)-1
  from (select count(*) continuousDays
    from (select sum(changeSign) over(order by tradeDate) unRiseDays
       from (select tradeDate,
          case when closePrice>lag(closePrice) over(order by tradeDate)
          then 0 else 1 end changeSign
          from stock) )
group by unRiseDays)
ログイン後にコピー

SPL は、わずか 1 行のコードで計算を実装します。これは、Java コードは言うまでもなく、SQL コードよりもはるかに単純です。

stock.sort(tradeDate).group@i(price&lt;price[-1]).max(~.len())
ログイン後にコピー

Comprehensive, independent computing capability
SPL has table sequence – the specialized structured data object, and offers a rich computing class library based on table sequences to handle a variety of computations, including the commonly seen filtering, grouping, sorting, distinct and join, as shown below:

Orders.sort(Amount) // Sorting
Orders.select(Amount*Quantity>3000 && like(Client,"*S*")) // Filtering
Orders.groups(Client; sum(Amount)) // Grouping
Orders.id(Client) // Distinct
join(Orders:o,SellerId ; Employees:e,EId) // Join
……
ログイン後にコピー

More importantly, the SPL computing capability is independent of databases; it can function even without a database, which is unlike the ORM technology that requires translation into SQL for execution.

Efficient and easy to use IDE
Besides concise syntax, SPL also has a comprehensive development environment offering debugging functionalities, such as “Step over” and “Set breakpoint”, and very debugging-friendly WYSIWYG result viewing panel that lets users check result for each step in real time.

Something could double the development efficiency of Java programmers
Support for large-scale data computing
SPL supports processing large-scale data that can or cannot fit into the memory.

In-memory computation:

Something could double the development efficiency of Java programmers
External memory computation:

Something could double the development efficiency of Java programmers
We can see that the SPL code of implementing an external memory computation and that of implementing an in-memory computation is basically the same, without extra computational load.

It is easy to implement parallelism in SPL. We just need to add @m option to the serial computing code. This is far simpler than the corresponding Java method.

Something could double the development efficiency of Java programmers
Seamless integration into Java applications
SPL is developed in Java, so it can work by embedding its JARs in the Java application. And the application executes or invokes the SPL script via the standard JDBC. This makes SPL very lightweight, and it can even run on Android.

Call SPL code through JDBC:

Class.forName("com.esproc.jdbc.InternalDriver");
    con= DriverManager.getConnection("jdbc:esproc:local://");
    st =con.prepareCall("call SplScript(?)");
    st.setObject(1, "A");
    st.execute();
    ResultSet rs = st.getResultSet();
    ResultSetMetaData rsmd = rs.getMetaData();
ログイン後にコピー

As it is lightweight and integration-friendly, SPL can be seamlessly integrated into mainstream Java frameworks, especially suitable for serving as a computing engine within microservice architectures.

Highly open framework
SPL’s great openness enables it to directly connect to various types of data sources and perform real-time mixed computations, making it easy to handle computing scenarios where databases are unavailable or multiple/diverse databases are involved.

Something could double the development efficiency of Java programmers
Regardless of the data source, SPL can read data from it and perform the mixed computation as long as it is accessible. Database and database, RESTful and file, JSON and database, anything is fine.

Databases:

Something could double the development efficiency of Java programmers
RESTful and file:

Something could double the development efficiency of Java programmers
JSON and database:

Something could double the development efficiency of Java programmers
Interpreted execution and hot-swapping
SPL is an interpreted language that inherently supports hot swapping while power remains switched on. Modified code takes effect in real-time without requiring service restarts. This makes SPL well adapt to dynamic data processing requirements.

Something could double the development efficiency of Java programmers
This hot—swapping capability enables independent computing modules with separate management, maintenance and operation, creating more flexible and convenient uses.

SPL can significantly increase Java programmers’ development efficiency while achieving framework advantages. It combines merits of both Java and SQL, and further simplifies code and elevates performance.

SPL open source address

以上がJava プログラマーの開発効率を 2 倍にする可能性があるの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

会社のセキュリティソフトウェアはアプリケーションの実行に失敗していますか?それをトラブルシューティングと解決する方法は? 会社のセキュリティソフトウェアはアプリケーションの実行に失敗していますか?それをトラブルシューティングと解決する方法は? Apr 19, 2025 pm 04:51 PM

一部のアプリケーションが適切に機能しないようにする会社のセキュリティソフトウェアのトラブルシューティングとソリューション。多くの企業は、内部ネットワークセキュリティを確保するためにセキュリティソフトウェアを展開します。 ...

名前を数値に変換してソートを実装し、グループの一貫性を維持するにはどうすればよいですか? 名前を数値に変換してソートを実装し、グループの一貫性を維持するにはどうすればよいですか? Apr 19, 2025 pm 11:30 PM

多くのアプリケーションシナリオでソートを実装するために名前を数値に変換するソリューションでは、ユーザーはグループ、特に1つでソートする必要がある場合があります...

MapsTructを使用したシステムドッキングのフィールドマッピングの問題を簡素化する方法は? MapsTructを使用したシステムドッキングのフィールドマッピングの問題を簡素化する方法は? Apr 19, 2025 pm 06:21 PM

システムドッキングでのフィールドマッピング処理は、システムドッキングを実行する際に難しい問題に遭遇することがよくあります。システムのインターフェイスフィールドを効果的にマッピングする方法A ...

Intellijのアイデアは、ログを出力せずにSpring Bootプロジェクトのポート番号をどのように識別しますか? Intellijのアイデアは、ログを出力せずにSpring Bootプロジェクトのポート番号をどのように識別しますか? Apr 19, 2025 pm 11:45 PM

intellijideaultimatiateバージョンを使用してスプリングを開始します...

エンティティクラス変数名をエレガントに取得して、データベースクエリ条件を構築する方法は? エンティティクラス変数名をエレガントに取得して、データベースクエリ条件を構築する方法は? Apr 19, 2025 pm 11:42 PM

データベース操作にMyBatis-Plusまたはその他のORMフレームワークを使用する場合、エンティティクラスの属性名に基づいてクエリ条件を構築する必要があることがよくあります。あなたが毎回手動で...

Javaオブジェクトを配列に安全に変換する方法は? Javaオブジェクトを配列に安全に変換する方法は? Apr 19, 2025 pm 11:33 PM

Javaオブジェクトと配列の変換:リスクの詳細な議論と鋳造タイプ変換の正しい方法多くのJava初心者は、オブジェクトのアレイへの変換に遭遇します...

eコマースプラットフォームSKUおよびSPUデータベースデザイン:ユーザー定義の属性と原因のない製品の両方を考慮する方法は? eコマースプラットフォームSKUおよびSPUデータベースデザイン:ユーザー定義の属性と原因のない製品の両方を考慮する方法は? Apr 19, 2025 pm 11:27 PM

eコマースプラットフォーム上のSKUおよびSPUテーブルの設計の詳細な説明この記事では、eコマースプラットフォームでのSKUとSPUのデータベース設計の問題、特にユーザー定義の販売を扱う方法について説明します。

Redisキャッシュソリューションを使用して、製品ランキングリストの要件を効率的に実現する方法は? Redisキャッシュソリューションを使用して、製品ランキングリストの要件を効率的に実現する方法は? Apr 19, 2025 pm 11:36 PM

Redisキャッシュソリューションは、製品ランキングリストの要件をどのように実現しますか?開発プロセス中に、多くの場合、ランキングの要件に対処する必要があります。

See all articles