How do I build simple search page using ZK and Spring Boot?

In this example we are going to build a simple search page using ZK framework and Spring Boot. We are going to use the latest available version of Spring Boot (3.0.0) and ZK Framework (9.6.0.2). So without taking more time let’s start by creating a new spring boot project with the following pom.xml. You can create the initial project using your IDE or spring initializr.

Create a Spring Boot project and add the following dependencies:

  • zkspringboot-starter
  • zkplus
  • spring-boot-devtools
  • spring-boot-starter-data-jpa
  • mysql-connector-j
  • lombok

The pom.xml File

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>org.kodejava</groupId>
    <artifactId>kodejava-zk-search</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>kodejava-zk-search</name>
    <description>kodejava-zk-search</description>

    <properties>
        <java.version>17</java.version>
        <zkspringboot.version>3.0.0</zkspringboot.version>
        <zk.version.jakarta>9.6.0.2-jakarta</zk.version.jakarta>
        <zk.version>9.6.0.2</zk.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.zkoss.zkspringboot</groupId>
            <artifactId>zkspringboot-starter</artifactId>
            <type>pom</type>
            <version>${zkspringboot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.zkoss.zk</groupId>
            <artifactId>zkplus</artifactId>
            <version>${zk.version.jakarta}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>ZK CE</id>
            <name>ZK CE Repository</name>
            <url>https://mavensync.zkoss.org/maven2</url>
        </repository>
        <repository>
            <id>ZK EVAL</id>
            <name>ZK Evaluation Repository</name>
            <url>https://mavensync.zkoss.org/eval</url>
        </repository>
    </repositories>

</project>

application.properties File

This properties file configure ZK application homepage and the prefix where the zul files are located. We also configure the datasource to our application database.

zk.homepage=label
zk.zul-view-resolver-prefix=/zul
zk.resource-uri=/zkres

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/musicdb
spring.datasource.username=root
spring.datasource.password=

spring.jpa.properties.hibernate.hbm2ddl.auto=create

Label.java Entity Definition

An entity that represent out record label with just two property of id and name. Getters and setters are generated by Lombok library, it also generated to equals() and hashcode() method, and also the toString() method.

package org.kodejava.zk.entity;

import jakarta.persistence.*;
import lombok.Data;

@Data
@Entity
public class Label {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
}

The LabelRepository.java definition.

Create the LabelRepository which extends the JpaRepository and JpaSpecificationExecutor interfaces.

package org.kodejava.zk.repository;

import org.kodejava.zk.entity.Label;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

@Repository
public interface LabelRepository extends JpaRepository<Label, Long>, JpaSpecificationExecutor<Label> {
}

AbstractSearchController.java a base search controller.

A base class that we can use to implements all the search page in an application. Basically it provides the method to search our application data. It defines a couple of abstract method that need to be implemented by the search controller classes such as what repository to use and the specification for searching the data. We can also define the default sort column and the direction of the data sorting.

package org.kodejava.zk.controller;

import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Listbox;

@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public abstract class AbstractSearchController<T> extends SelectorComposer<Component> {
    @Wire
    protected Listbox listbox;

    public abstract JpaSpecificationExecutor<T> getRepository();

    public abstract Specification<T> getSpecification();

    public abstract String getCacheKey();

    protected String getDefaultSortColumn() {
        return "id";
    }

    protected Sort.Direction getDefaultSortDirection() {
        return Sort.Direction.ASC;
    }

    protected boolean getMultiple() {
        return false;
    }

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        search();
    }

    @Listen("onClick=#searchButton")
    public void search() {
        listbox.setVisible(true);
        SearchListModel<T> model = new SearchListModel<>(getRepository(), getSpecification(), getCacheKey());
        model.setMultiple(getMultiple());
        model.setDefaultSortColumn(getDefaultSortColumn());
        model.setDefaultSortDirection(getDefaultSortDirection());
        listbox.setModel(model);
        listbox.setActivePage(0);
    }

    @Listen("onOK=#searchForm")
    public void onEnterPressed(Event event) {
        search();
    }

    public int getPageSize() {
        return SearchListModel.PAGE_SIZE;
    }
}

SearchListModel.java

An implementation of ListModel, this class will query the database using the provided repository and specification. It read data page-by-page and cache it so when we navigating the Listbox page it doesn’t read the data that have already been cached.

package org.kodejava.zk.controller;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.FieldComparator;
import org.zkoss.zul.ListModelList;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

public class SearchListModel<T> extends ListModelList<T> {
    public static final int PAGE_SIZE = 5;
    private final JpaSpecificationExecutor<T> repository;
    private final String cacheKey;
    private long totalElements;

    private Comparator<T> comparator;
    private boolean ascending = false;
    private final Specification<T> specification;
    private Sort.Direction defaultSortDirection = Sort.Direction.ASC;
    private String defaultSortColumn = "id";

    public SearchListModel(JpaSpecificationExecutor<T> repository, Specification<T> specification, String cacheKey) {
        this.repository = repository;
        this.specification = specification;
        this.cacheKey = cacheKey;
        this.totalElements = repository.count(specification);
    }

    @Override
    public T getElementAt(int index) {
        Map<Integer, T> cache = getCache();

        T target = cache.get(index);
        if (target == null) {
            Sort sort = Sort.by(getDefaultSortDirection(), getDefaultSortColumn());
            if (comparator != null) {
                FieldComparator fieldComparator = (FieldComparator) comparator;
                String orderBy = fieldComparator.getRawOrderBy();
                sort = Sort.by(ascending ? Sort.Direction.ASC : Sort.Direction.DESC, orderBy);
            }
            Page<T> pageResult = repository.findAll(specification, PageRequest.of(getPage(index), PAGE_SIZE, sort));
            totalElements = pageResult.getTotalElements();
            int indexKey = index;
            for (T t : pageResult.toList()) {
                cache.put(indexKey, t);
                indexKey++;
            }
        } else {
            return target;
        }

        target = cache.get(index);
        if (target == null) {
            throw new RuntimeException("element at " + index + " cannot be found in the database.");
        } else {
            return target;
        }
    }

    @Override
    public int getSize() {
        return (int) totalElements;
    }

    @Override
    public void sort(Comparator<T> comparator, boolean ascending) {
        super.sort(comparator, ascending);
        this.comparator = comparator;
        this.ascending = ascending;
    }

    @SuppressWarnings("unchecked")
    private Map<Integer, T> getCache() {
        Execution execution = Executions.getCurrent();
        Map<Integer, T> cache = (Map<Integer, T>) execution.getAttribute(cacheKey);
        if (cache == null) {
            cache = new HashMap<>();
            execution.setAttribute(cacheKey, cache);
        }
        return cache;
    }

    private int getPage(int index) {
        if (index != 0) {
            return index / PAGE_SIZE;
        }
        return index;
    }

    public Sort.Direction getDefaultSortDirection() {
        return defaultSortDirection;
    }

    public void setDefaultSortDirection(Sort.Direction defaultSortDirection) {
        this.defaultSortDirection = defaultSortDirection;
    }

    public String getDefaultSortColumn() {
        return defaultSortColumn;
    }

    public void setDefaultSortColumn(String defaultSortColumn) {
        this.defaultSortColumn = defaultSortColumn;
    }
}

LabelSearchController.java

Our label search page controller which extends from AbstractSearchController class. We provide the LabelRepository and the Specification to filter the data.

package org.kodejava.zk.controller;

import jakarta.persistence.criteria.Predicate;
import org.kodejava.zk.entity.Label;
import org.kodejava.zk.repository.LabelRepository;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zul.Textbox;

import java.util.ArrayList;
import java.util.List;

@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class LabelSearchController extends AbstractSearchController<Label> {
    @WireVariable
    private LabelRepository labelRepository;

    @Wire
    private Textbox labelNameTextbox;

    @Override
    public JpaSpecificationExecutor<Label> getRepository() {
        return labelRepository;
    }

    @Override
    public Specification<Label> getSpecification() {
        return (root, query, criteriaBuilder) -> {
            List<Predicate> predicates = new ArrayList<>();
            String labelName = labelNameTextbox.getValue();
            if (!labelName.isBlank()) {
                predicates.add(criteriaBuilder.like(root.get("name"), "%" + labelName + "%"));
            }
            return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
        };
    }

    @Override
    public String getCacheKey() {
        return "LABEL_CACHE_KEY";
    }
}

label-search.zul – Label Search Page in ZUL

The search page with a label name Textfield to search by label name. The Listbox will display the data with pagination.

<zk>
    <window id="labelSearchWin" zclass="none" border="none" visible="true"
            apply="org.kodejava.zk.controller.LabelSearchController" width="100%">

        <grid id="searchForm">
            <columns>
                <column width="200px"/>
                <column/>
            </columns>
            <rows>
                <row>
                    <label value="Label Name"/>
                    <textbox id="labelNameTextbox" width="450px" maxlength="50"/>
                </row>
            </rows>
        </grid>

        <separator/>

        <hlayout>
            <button id="searchButton" label="Search"/>
        </hlayout>

        <separator/>

        <vlayout>
            <listbox id="listbox" mold="paging" pageSize="${labelSearchWin$composer.pageSize}" visible="false">
                <listhead>
                    <listheader label="No" hflex="min"/>
                    <listheader label="Label Name" sort="auto(name)"/>
                    <listheader label="Action" hflex="min"/>
                </listhead>
                <template name="model">
                    <listitem>
                        <listcell label="${forEachStatus.index + 1}" hflex="min"/>
                        <listcell label="${each.name}"/>
                        <listcell hflex="min">
                            <hlayout>
                                <button label="Edit" forward="onClick=listbox.onEdit(${each})" tooltiptext="Edit Data"/>
                            </hlayout>
                        </listcell>
                    </listitem>
                </template>
            </listbox>
        </vlayout>
    </window>
</zk>

Running the application and access it at localhost:8080 will give you a screen like the screenshot at the beginning of this post.

The complete source code can be found in the following GitHub repository kodejava-zk-search.

10 Best Career Options for Java Developers in 2023


Pexels

The programming world is changing, and opportunities await aspiring coders. With robust support from major technology giants and an ever-expanding job market, now is the time to start your career as a Java developer.

Whether you’re a professional looking to break into the field or a beginner with no experience who wants to get a java developer job with no experience, we’ve rounded up ten exciting options that are sure to put you on your way to success. From mobile app development to software engineering, this article explores the best career options for you in 2023!

Will Java Developers Still Be in Demand in 2023?

If the ever-increasing number of job posts—specifically for Java developers at Jooble is anything to go by, Java developers will have no shortage of job offers in 2023. Also, as an open-source language, Java is widely used for enterprise development, mobile applications, web applications, and artificial intelligence projects.

In addition, its inventor – Oracle –has regularly added new features to the language over the last two decades. This has allowed Java developers to stay ahead of the curve when it comes to coding skills.

Moreover, as technology advances, more organizations are turning to Java developers to meet their needs. For example, many businesses are transitioning their entire infrastructure from monolithic services and adopting microservices architectures.

This trend requires skilled Java developers who understand how microservices work and can develop them effectively. The same goes for AI-driven systems that rely heavily on Java development expertise.

All things considered, it means there will still be plenty of demand for talented Java developers in 2023 and beyond. Here are ten of the best career options for Java developers in 2023:

1. DevOps Engineer

A DevOps Engineer is a software engineer who works collaboratively with development and operations teams. They ensure that digital projects are delivered quickly, efficiently, and without errors.

They are responsible for deploying software, maintaining application stability, and automating workflows. Essentially, they are the bridge between development and operations teams, ensuring communication flows within an organization.

Becoming a DevOps Engineer requires knowledge of programming languages like Java, and scripting languages like Ruby or Python. It also requires an understanding of automation tools like Jenkins or Chef; source code management platforms like Git, and cloud-based solutions such as Amazon Web Services or Microsoft Azure.

Becoming a DevOps Engineer could be a great choice for Java developers looking for the best career options in 2023. This is because there is an increasing demand for this role in organizations worldwide.

2. Artificial Intelligence Engineer

Artificial Intelligence (AI) is a rapidly growing field. As a result, companies are looking for developers with expertise in AI technologies to help them stay competitive.

AI Engineers are responsible for creating intelligent systems that can perform tasks independently and operate with human-like accuracy and speed. Becoming an AI Engineer requires knowledge of Java, Python, R programming language, Natural Language Processing (NLP), Machine Learning algorithms, and more. For Java developers in 2023, this could be a great option, as AI technologies will only increase in the coming years.

3. Solution Architect

A Solution Architect is a technical leader who designs and implements software solutions to solve business problems. They create high-level designs that integrate various systems, applications, and services, maximizing efficiency and scalability.

To become one, you’ll need to understand software engineering fundamentals such as object-oriented programming (OOP) and system design concepts like architecture patterns and frameworks. Additionally, you’ll need to be well-versed in the latest technologies and trends in the industry, such as Kubernetes and microservices.

To become a Solution Architect, the best approach is to start by gaining experience with coding; then pursue additional training focused on system architecture principles and design patterns. Having some relevant certifications will also give you an edge over other candidates applying for positions.

4. Data Scientist

Data Scientists manage, analyze, and interpret data to extract valuable insights. They use various technologies and methods such as big data analytics, machine learning algorithms, natural language processing (NLP), statistical analysis, etc.

Becoming a successful Data Scientist requires good knowledge of programming languages like Java along with strong mathematical and statistical skills. You’ll also need to be well-versed in databases, machine learning tools, data visualization frameworks, and modern algorithms such as deep learning neural networks. Data Scientists are in high demand these days due to organizations’ ever-increasing use of data-driven decisions.

5. Scrum Master

A Scrum Master is a role that is essential for software development teams that employ agile methodology. A Scrum Master is responsible for organizing and managing a team’s workflow during the phases of development.

They’re responsible for ensuring that tasks and deadlines are met. They also facilitate conversations around potential roadblocks or issues.

For Java developers looking to become a Scrum Master in 2023, it is essential to understand the fundamentals of agile software development, such as its core tenets and techniques, before attempting to take on the role. Being fluent with related frameworks, like Extreme Programming and Lean Development, can also be beneficial. It would also help to have good communication and interpersonal skills and knowledge of your team members’ strengths and weaknesses to manage their assigned tasks effectively.

6. Mobile Developer

Mobile Developers specialize in creating applications for mobile devices such as smartphones and tablets. They use coding languages like Java, HTML5, and CSS3 to create user interfaces and write code that interacts with an application’s backend systems.

In 2023, the demand for Mobile Developers is projected to increase exponentially. Mobile applications will become increasingly crucial for businesses as more organizations move their processes and services online.

To become a successful Mobile Developer in 2023, you’ll need to understand software development and mobile design basics. Additionally, understanding modern trends such as augmented reality (AR) can also be beneficial.

7. Project Manager

Project Managers are responsible for overseeing the development process from start to finish. They work closely with teams of software developers, UX/UI designers, marketers, and other professionals to ensure that each project is completed on time and within budget.

Project managers need strong communication skills and an understanding of software development processes. They should be familiar with popular project management tools like JIRA and Trello.

8. Database Administrator

Database Administrators are responsible for creating, maintaining, and securing databases. They use programming languages like Java to develop database applications.

In 2023, Database Administrators will need to be experts in a wide range of technologies such as SQL, NoSQL, OLTP/OLAP systems, and cloud computing platforms. Additionally, knowledge of related areas such as machine learning and big data can also be beneficial.

9. Security Analyst

Security Analysts are responsible for protecting networks and systems from cyber threats such as malware, viruses, and unauthorized access. They use programming languages like Java to develop security protocols, monitor networks for suspicious activities, investigate incidents and analyze system vulnerabilities.

To succeed in this role in 2023, Security Analysts need to understand cyber-security best practices thoroughly. They should also be knowledgeable about the latest threats and technologies, such as biometrics, artificial intelligence (AI), and blockchain.

10. Cloud Solutions Architect

Cloud Solutions Architects design and implement cloud-based systems for businesses. They need to understand the fundamentals of cloud computing, including infrastructure as a service (IaaS), platform as a service (PaaS), and software as a service (SaaS).

In 2023, Cloud Solutions Architects should have experience with popular cloud computing providers such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform. Additionally, they should know the principles of DevOps, microservices, and containerization.

In summation, these are the ten best career options for Java Developers in 2023. With a good understanding of software development principles and the latest technologies, you can pursue any of these roles and excel in them. Good luck!

How do I calculate days between two dates excluding weekends and holidays?

The code snippet below shows you a simple way to calculate days between two dates excluding weekends and holidays. As an example, you can use this function for calculating work days. The snippet utilize the java.time API and the Stream API to calculate the value.

What we do in the code below can be described as the following:

  • Create a list of holidays. The dates might be read from a database or a file.
  • Define filter Predicate for holidays.
  • Define filter Predicate for weekends.
  • These predicates will be use for filtering the days between two dates.
  • Define the startDate and the endDate to be calculated.
  • Using Stream.iterate() we iterate the dates, filter it based on the defined predicates.
  • Finally, we get the result as list.
  • The actual days between is the size of the list, workDays.size().
package org.kodejava.datetime;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class DaysBetweenDates {
    public static void main(String[] args) {
        List<LocalDate> holidays = new ArrayList<>();
        holidays.add(LocalDate.of(2022, Month.DECEMBER, 26));
        holidays.add(LocalDate.of(2023, Month.JANUARY, 2));

        Predicate<LocalDate> isHoliday = holidays::contains;
        Predicate<LocalDate> isWeekend = date -> date.getDayOfWeek() == DayOfWeek.SATURDAY
                || date.getDayOfWeek() == DayOfWeek.SUNDAY;

        LocalDate startDate = LocalDate.of(2022, Month.DECEMBER, 23);
        LocalDate endDate = LocalDate.of(2023, Month.JANUARY, 3);
        System.out.println("Start date = " + startDate);
        System.out.println("End date   = " + endDate);

        // Days between startDate inclusive and endDate exclusive
        long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
        System.out.println("Days between = " + daysBetween);

        List<LocalDate> workDays = Stream.iterate(startDate, date -> date.plusDays(1))
                .limit(daysBetween)
                .filter(isHoliday.or(isWeekend).negate())
                .toList();

        long actualDaysBetween = workDays.size();
        System.out.println("Actual days between = " + actualDaysBetween);
    }
}

Running the code snippet above give us the following result:

Start date = 2022-12-23
End date   = 2023-01-03
Days between = 11
Actual days between = 5

How do I discover the quarter of a given date?

The following code snippet shows you a various way to get the quarter of a given date. Some methods that we use below are:

  • Using the new java.time API of Java 8 IsoFields.QUARTER_OF_YEAR.
  • Using Java 8 DateTimeFormatter pattern of Q or q. The length of “q” give us a different result.
  • Using java.util.Date.
  • Using java.util.Calendar.
  • Get the quarter from an array of string.

Let’s see the code snippet in action.

package org.kodejava.datetime;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.IsoFields;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DateQuarter {
    public static void main(String[] args) {
        // Using Java 8
        LocalDate now = LocalDate.now();
        int quarter = now.get(IsoFields.QUARTER_OF_YEAR);
        System.out.println("quarter  = " + quarter);

        // Using DateTimeFormatter Q / q, set the Locale to get value
        // in local format
        String quarter1 = LocalDate.of(2023, 8, 17)
                .format(DateTimeFormatter.ofPattern("q", Locale.US));
        String quarter2 = LocalDate.of(2023, 8, 17)
                .format(DateTimeFormatter.ofPattern("qq", Locale.US));
        String quarter3 = LocalDate.of(2023, 8, 17)
                .format(DateTimeFormatter.ofPattern("qqq", Locale.US));
        String quarter4 = LocalDate.of(2023, 8, 17)
                .format(DateTimeFormatter.ofPattern("qqqq", Locale.US));
        System.out.println("quarter1 = " + quarter1);
        System.out.println("quarter2 = " + quarter2);
        System.out.println("quarter3 = " + quarter3);
        System.out.println("quarter4 = " + quarter4);

        // Using older version of Java
        Date today = new Date();
        quarter = (today.getMonth() / 3) + 1;
        System.out.println("quarter = " + quarter);

        // Using java.util.Calendar object. For certain date
        // we can set the calendar date using setTime() method.
        Calendar calendar = Calendar.getInstance();
        quarter = (calendar.get(Calendar.MONTH) / 3) + 1;
        System.out.println("quarter = " + quarter);

        // Custom the quarter as text
        String[] quarters = new String[]{"Q1", "Q2", "Q3", "Q4"};
        String quarterString = quarters[quarter - 1];
        System.out.println("quarterString = " + quarterString);
    }
}

And here are the result of the code snippet above:

quarter  = 1
quarter1 = 3
quarter2 = 03
quarter3 = Q3
quarter4 = 3rd quarter
quarter = 1
quarter = 1
quarterString = Q1

How do I export MySQL database schema into markdown format?

The following code example demonstrate how to export MySQL database schema into markdown table format. We get the table structure information by executing MySQL’s DESCRIBE statement.

The steps we do in the code snippet below:

  • Connect to the database.
  • We obtain the list of table name from the database / schema.
  • Executes DESCRIBE statement for each table name.
  • Read table structure information such as field, type, null, key, default and extra.
  • Write the information into markdown table format and save it into table.md.

And here are the complete code snippet.

package org.kodejava.jdbc;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class DescribeMySQLToMarkDown {
    private static final String URL = "jdbc:mysql://localhost/kodejava";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "";

    public static void main(String[] args) {
        String tableQuery = """
                select table_name
                from information_schema.tables
                where table_schema = 'kodejava'
                  and table_type = 'BASE TABLE'
                order by table_name;
                """;

        try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
            Statement stmt = connection.createStatement();
            ResultSet resultSet = stmt.executeQuery(tableQuery);
            List<String> tables = new ArrayList<>();
            while (resultSet.next()) {
                tables.add(resultSet.getString("table_name"));
            }

            System.out.println(tables.size() + " tables found.");

            try (BufferedWriter writer = new BufferedWriter(new FileWriter("table.md"))) {
                for (String table : tables) {
                    System.out.println("Processing table: " + table);
                    Statement statement = connection.createStatement();
                    ResultSet descResult = statement.executeQuery("DESCRIBE " + table);

                    writer.write(String.format("Table Name: **%s**%n%n", table));
                    writer.write("| Field Name | Data Type | Null | Key | Default | Extra |\n");
                    writer.write("|:---|:---|:---|:---|:---|:---|\n");
                    while (descResult.next()) {
                        String field = descResult.getString("field");
                        String type = descResult.getString("type");
                        String nullInfo = descResult.getString("null");
                        String key = descResult.getString("key");
                        String defaultInfo = descResult.getString("default");
                        String extra = descResult.getString("extra");
                        String line = String.format("| %s | %s | %s | %s | %s | %s |%n",
                                field, type, nullInfo, key, defaultInfo, extra);
                        writer.write(line);
                    }
                    writer.write("\n<br/>\n<br/>\n");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

This code snippet will produce something like below. I have tidy up the markdown for a better presentation.

Table Name: **books**

| Field Name | Data Type       | Null | Key | Default | Extra          |
|:-----------|:----------------|:-----|:----|:--------|:---------------|
| id         | bigint unsigned | NO   | PRI | null    | auto_increment |
| isbn       | varchar(30)     | NO   |     | null    |                |

<br/>
<br/>

Maven dependencies

<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>8.0.32</version>
</dependency>

Maven Central

Frameworks in Java

Do you know some frameworks of Java? Have you ever thought about the frameworks available in the Java programming language? Let’s experience & know briefly about the frameworks of Java.

But before we start discussing the types of frameworks in Java & what is frameworks for Java, let us come to know what is a framework called in normal life.

The framework is a type of template by which we can reduce our work. This means the frame of the previous work is ready. You just need to modernize it. Then you can prepare a new thing.

Finding it is quite difficult to understand. Let us take one example to clear the idea.

Suppose, yesterday you prepared a panner dish for your parents. But after taking the dinner, you find out that there is a large amount of gravy left in the pot. But there is not any panner left in the pot. The dish was so well-prepared.

So what will you do in such cases? Do you throw the remaining gravy off the dish?

No! you have decided to preserve the gravy. And the next morning, you modernize the gravy & prepared a new dish having chicken from that gravy.

This is the proper example of a framework. The gravy of the panner dish was your framework. You just modernize it, added chicken to the dish & prepared a new dish. This same thing happens in frameworks for Java.

What Is Frameworks

The framework is the predefined snippet of the code. It is very difficult to complete an application program by any developer. That is why in the framework a series of classes & functions are developed according to the necessity of the developers. Developers just need to put their written codes there. The remaining things will be completed by the framework. There are different frameworks are present for different programming languages.

Like frameworks of Java, there are JavaScript frameworks also. JavaScript framework performs the same operation. It is like the gravy of the dish which we have stated above. Just we need to add codes in the frameworks. As we have added chicken to the gravy in the above example.

Frameworks Of Java

We used to write our codes in the Java programming language by simple Java programs. But those simple Java programs will not be needed in the companies. The companies will not pay for developing a calculator in Java programming language. There we need to develop a large size of code. Developing such codes is very difficult. For that purpose, there are frameworks of Java.

These frameworks work as the model. We need to design the model on our own. We have to complete the model structure in such a way that it will fulfill the necessity of the company. Frameworks of Java are like the structure of a building. We need to build the walls; we need to decorate to live in them. If you want to get homework help Java then you can contact and pay for coding homework help.

Types Of Frameworks In Java

There are many types of frameworks in Java. According to the need of the developer, they can choose the desired framework. As per the necessity of the developer, they can choose the proper framework. Choosing an improper framework creates problems while developing the application. Here, we are going to make a list of the frameworks which play an important role in every life of Java developers.

1. Spring Frameworks Of Java

The Spring framework of Java is essential. Any Java application can develop with the help of Spring. Sometimes there may be a problem related to coupling. Due to tight coupling, there may be some issues in different classes in Java. Spring helps to create loose coupling. This change in one class, will not affect the other class.

2. Hibernate Frameworks Of Java

Sometimes there may be a problem related to the database usage by Java. The JDBC application sometimes creates difficulties while developing a table at the object level of the database. These developers need to use Hibernate. The query language used by Hibernate is known as the Hibernate Query Language (HQL). The object-level relationship can be easily made up by the Hibernate.

3. Struts Frameworks Of Java

Struts is completely an open-source platform. Anybody can download & use it for free. It helps to develop a convenient application. It helps to view the model through the easy process & user interaction. There is an XML file that helps to generate & gather the result of the analysis in a better way.

4. Dropwizard Frameworks Of Java

Dropwizard is another type of framework in Java. It is a wizard. It helps to complete the application by configuring it. It helps to complete the application by logging, configuring & changing the metrics of the application. It takes libraries to form the Java ecosystem & provides a single framework interface.

5. Grail Frameworks Of Java

It is the most important type of framework in Java. It is appropriate for beginners. Beginners who want to learn the frameworks of Java, first need to know the Grail. But it is not able to run with Java programming language. It runs with the Groovy language. Groovy language is similar to the Java programming language. But it has more features than Java. Also, it is very easy. That is why it is advisable to start the journey of the Frameworks of Java with Grail.

Conclusion

As we saw the frameworks of Java are very important. It is advisable to clear the basic concept of Java programming language in a good manner. It is a very important first step.

Frameworks for Java are the building boxes for developing applications related to the Java programming language.

EduBirdie Code Writing Services for Students – Review

We can all agree that computer programming significantly influenced the way our lives look today. There are so many things we use and rely on that would not exist without code writing. The whole online realm would still be an advanced idea. The term source code stands for the layers of knowledge, creativity, and constant effort to make products better in every sense of the word. Most of us, consumers, can’t even conceptualize this building process. We use it without knowing how to make a program or what it takes to reach the final product. For that reason, the slight mystic aura around people who mastered code making is more than well deserved.

Code writing as a profession

To reach a high level of professionalism students who choose this career have to put a lot of work and time into it. This is where EduBirdie and other services can make a huge difference by providing experienced insight. Programming is the set of many tech-related activities that surpasses the simple term “writing code”. In the beginning, the learning curve might go down due to the number of programming languages with Java, C++, PHP, and Python being the most popular ones. There are numerous functions, procedures, concepts, and variables to adopt and apply.

Photo by Christina Morillo

According to programmers, learning how to write code is not the most difficult ever. Once the first phase passes and the logic behind programming have been fully comprehended things will get much easier. In their opinion, the two most important factors are finding the right sources to learn from and a good mentor. A college degree is equally important as practical knowledge, experience, and a smartly built portfolio.

Learning computer programming with EduBirdie

With code writing college assignments even the most confident students can get stuck with the problem that they just can’t find the solution for. Online is the first place new generations are going, to find reliable professional help. Unfortunately, not every online service is trustworthy and responsible. Same as for any other business, the smart thing would be to check edubirdie reviews, users’ ratings, and other useful sources to learn about the level of service quality and customer satisfaction. EduBirdie exists since 2015 so there is plenty of positive feedback that positions them as experts in providing this type of service. For any student that seeks assistance with code writing assignments maintaining communication with customer service and code writer in person are among the most praised qualities. In terms of educational values, EduBirdie can provide reliable sources of knowledge and experience. Simultaneously, its code writers play the mentoring role by offering examples and possible solutions to the assignment issues.

Review of EduBirdie code writing service

Let’s start with the ratings on the review websites. The scores always maintain between 4.6 and 5 stars and place it among the three most popular services. The rating is based on several thousand users’ reviews.

Probably the most painful fact, EduBirdie is not the cheapest option on the market. Also, unlike most writing services it has a bidding pricing system that can be confusing, especially for first-time users. However, this also means that this service is capable of hiring experts and high-profile professional code writers.

EduBirdie claims that all the work is unique and original, and offers revision as an option. Furthermore, a student can pick the same code writer for different assignments and extend the learning journey under the same guidance. Another positive thing is the opportunity for students to release their deposit once the quality of the work meets the requirements.

While browsing through the reviews we couldn’t find any complaint about confidentiality or delivery schedule. The only objection that was repeated in the older reviews is the lack of discounts. Judging by the latest first order promotional code, EduBirdie reacted to these comments and is actively changing the discount policy.

A significant number of positive reviews are addressed to customer service. It seems that EduBirdie is seriously determined to be online available 24/7, highly responsive to calls, and supportive in resolving potential issues.

Conclusion

The number of customers seeking assistance speaks loud enough about their legitimacy and professionalism. Since the quality of the work depends on the skills of the particular code writer, the system might resemble a lottery. Due to only a few negative reviews, it’s safe to assume that EduBirdie chooses its code writers with great care.

Best Programming Languages For Business Majors to Learn

Photo by Sebastiaan ter Burg/Flickr

Do you want to learn a programming language that can help you in your business career? If so, you’re in luck! In this blog post, we will discuss the best programming languages for business majors to learn. They are versatile and can be used in a variety of business applications. So, whether you are looking to develop a website or create a custom application, they will serve you well!

1. What are the best programming languages for business majors to learn?

If you’re a business major who is interested in learning to code, you may be wondering which programming codes are the most useful for your future career. While there is no definitive answer to this question, there are a few that tend to be particularly popular among business professionals.

For example, Python is often used for data analysis and machine learning, while Java is a popular choice for building web applications. SQL is also a valuable language for working with databases, and HTML/CSS can be useful for creating engaging websites.

Ultimately, the best language for you to learn will depend on your specific goals and interests. However, these four languages are a good place to start if you’re looking to make your mark in the business world.

Friendly tip: Don’t be afraid of programming!

If you’re not sure where to start when it comes to learning programming, read more business essay samples to get started quicker. Many businesses require some programming knowledge, and even if you’re not looking to become a programmer, learning the basics can give you a leg up in your career. Business essay samples can show you how other businesses have used programming to their advantage, and how you can too. With a little of research, you’ll be able to find plenty of resources that can help you learn more about how programming can fit into your business career. Don’t be afraid to ask for help from those who know more than you do – after all, that’s why they’re called experts!

2. Why are they versatile for business applications?

There are many reasons why Java, Python and Ruby are such versatile programming languages for business applications. For one thing, all three languages are relatively easy to learn, which makes them ideal for businesses that want to train new employees quickly. Also, all three of them are widely used, which means that there is a large pool of experienced developers to choose from.

Also, each language has a well-established ecosystem of libraries and frameworks, which makes it easy to develop complex business applications. In short, Java, Python and Ruby are all excellent choices for businesses that need versatile and reliable programming languages.

3. How can you get started learning?

Let’s face it, everyone wants to be a programmer these days. Programmers are the new rock stars, and learning to code is seen as the key to success. But where do you start? There are dozens of programming languages out there, and it can be daunting to try to learn them all. The good news is that you don’t need to know every single language to be a successful programmer. In fact, most programmers only specialize in one or two languages. So how do you choose which of them to learn?

A good place to start is by looking at the most popular languages. According to the TIOBE Index, the top three right now are Java, C, and Python, as explained above. These are all great languages to learn, and they will give you a solid foundation for building your career.

Of course, there is no wrong answer when it comes to choosing a language. The important thing is that you find a language that you enjoy working with and that you can see yourself using in your future career. Whichever language you choose, there are plenty of resources available to help you get started.

There are online courses, books, and even programs that can help you get started coding in no time. Just remember to take your time and enjoy the process. Learning to code can be a fun and rewarding experience, so don’t stress about getting everything perfect from the start. Soon enough you’ll be writing code like a pro!

Conclusion

Programming codes is a necessary tool for business majors. These skills provide the ability to streamline processes, create engaging websites, and more importantly give you a leg up in your career. The best language for you to learn will depend on your specific goals and interests. However, these four languages are a good place to start if you’re looking to get into programming.

With a little of research, you’ll be able to find plenty of resources that can help you learn more about how programming can fit into your business career. So what are you waiting for? Get started today and see how programming can help you take your career to the next level!

What Kinds of Math are Used in Programming

Programming is an interactive process, and at times, it can be tedious. Sometimes it can come down to an equation. With the help of math, programming becomes a more manageable task and more interactive, turning down what would have been huge research projects into a few data inputs.

Laptop with code and plant in coffee shop

Image Source

In this article, we will explore the different kinds of math that are used in programming. They are mathematical operations, geometry, and calculus.

Maths students often find the subject intimidating, but it is an important subject to learn to be a successful programmer. You can make use of some math assignment help. Some math that college students need to know for programming are basic algebra, geometry, trigonometry, and calculus. Suppose you are interested in programming and would like to include mathematics in your studies. In that case, you should consider taking courses such as Calculus I and II or Statistics and Probability.

Binary Mathematics

The field of programming relies heavily on binary mathematics, making it one of the most significant subfields of mathematics.

Binary mathematics also serves as the industry’s central focus. As a result, this subfield of mathematics is the one to focus on to become proficient in programming. To represent each number in a computer’s code, binary code, which uses the binary number system rather than the more commonplace decimal system, is utilized.

The process of coding can be made easier with the use of binary code, which is also necessary for the low-level instructions required for hardware programming. You will need to be familiar with the hexadecimal numbering system to do certain actions, such as changing the color of an item. In addition to this, the traditional arithmetic operations of addition, subtraction, multiplication, and division are used inside the realm of binary mathematics.

Algebra

Students need to be proficient in college algebra to move on to more advanced levels of mathematics because it is one of the foundational mathematics subjects. Beyond the most fundamental arithmetical operations, algebra is one of the most established branches of mathematical study.

The emphasis is placed on graphs and equations, as well as the ability to solve equations with variables that are not known. Programming computers requires an understanding of algebra to create algorithms and software that can operate with mathematical functions. In addition to this, it participates in the design of programs for numerical programs.

Statistics

A branch of mathematics known as statistics education concludes data sets by employing quantified models, representations, and summaries. The discipline of computer science is similar to many others in that statistical analysis can serve a wide variety of functions, which is also true in many other fields.

Researchers can deduce conclusions about underlying trends and make predictions about future behavior and trends through the use of statistics, which allows for the analysis of data. The analysis of regression, the mean, variance, analysis of variance, skewness, and kurtosis are all examples of metrics that are utilized in statistics.

The field of computer science employs statistics in the process of regression analysis, as well as in data mining, information extraction, traffic modeling, voice recognition, sense of direction and image processing, and artificial intelligence. Statistics is also used in the study of images.

Calculus

Calculus is the study of change through time by calculating the derivatives and integrals of functions. Calculus, as a consequence of this, is often split into two subfields that are complementary to one another: differential calculus and integral calculus.

The study of rates of change when a quantity is known is the focus of differential calculus. Integral calculus, on the other hand, focuses on studying quantities even when a rate of change is already known.

Calculus is useful in computer science, just as in other disciplines, particularly when working with problems involving rates of change. Calculus is utilized in the field of computer science for the creation of graphs and other visualizations, the programming of applications, the development of ways to answer statistical questions, applications that facilitate problem-solving, simulations, and the design and analysis of algorithms.

Discrete Mathematics

Discrete mathematics is a prerequisite for any computer science degree because it is the heavyweight of the computer science math fields. When we talk about discrete mathematics, we’re talking about things that can be represented in a finite number of ways utilizing techniques such as logic, numbers, graphs, and probability. Discrete mathematics is crucial to all aspects of computer science.

Conclusion

The kind of math you have to master all depends on the type of programming language or framework you are interested in.

Different programming languages or frameworks require different levels of knowledge, so it is crucial to know what type of math you need before starting the class and enrolling in the course.

Coding Camp or College: What is the Right Choice for Skills Improvement?

With the way the world is going, the tech industry is flourishing and every day we wake up to see that some cool innovation has been invented and this only makes you thirst for more of the digital age.

Maybe you’re fresh out of high school, and you’re wondering what the best way to gain the skills needed to break into tech is, do I go to college or a coding camp?

For a long time, the way to go would be to go to college for a computer science degree, or a related degree and then work your way into getting a master’s degree or a Ph.D. These days, however, several alternative programs are being created to help train young people in their various preferred tech fields.

This begs the question, which of them is right for me? Do I go to a coding camp or to college to improve my skills? If you’re wrestling with these thoughts, not to worry! We’re here to help. In this article, we would shed some light on what you need to know to make an informed decision.

College vs. Coding camp: how do I choose?

These are the two main options everyone with an interest in tech considers first. Comparing the two of them is like comparing apples to oranges – each quite different, but has its benefits. The best way to compare would be to weigh them with some important factors such as;

Curriculum

In college, the degree to major in is Computer Science (CS). The curriculum of CS provides an adequate knowledge of computers that covers operating systems, the how’s and why’s. It also provides the soft skills needed to manage people and communicate better in the tech industry. Some CS degree programs include the following; operating system design, programming java, and C++, advanced mathematics, algorithms, and computer science theory. If you have little to no knowledge of these programs, you may want to consider college.

Coding camp, on the other hand, provides the in-depth knowledge of algorithms used in developer-scale apps and the general foundation needed for programming. The focus of coding camps is on tools for developers, coding languages, and practical applications. The curriculum of the coding camp includes; GitHub, JavaScript, Ruby, APIs, Python, etc. Another important deciding factor is your learning style. Do you learn better by taking lectures with a set curriculum and predictable interactive lessons? Then a CS degree in college may be your best bet. However, If you prefer hands-on, practical learning then coding boot camp may be more suitable for you.

Time Factor

The ultimate goal of college is to turn you into a reliable adult. You will have a lot of options to explore and learn about yourself in the process. In college, you get a well-rounded curriculum that includes everything from projects to assignments. The workload may be too much, and you sometimes need to visit Writix.com to get help with your studies. However, college prepares you for your next phase in life. The con is that a computer science degree takes about four years to complete and a master’s degree of about two years. While coding boot camps may take between 2-6 months for completion.

Time factor aside, the curricula of boot camps are limited compared to that of a computer science degree. For in-depth knowledge about foundational computer science concepts and scopes, a degree program in college will be more appropriate.

Cost

In terms of cost, coding camps are considerably cheaper than colleges. The cost of most coding camps ranges between $10000-15000, while tuition at top colleges with CS programs costs about three-four times that amount. The Massachusetts Institute for Technology (MIT) costs $60,000-70,000 per year, with cheaper colleges costing under $30,000 per year.

Personal Career goal

Another important factor to consider is your personal career goal(s). You need to think long term. In 10-0 years from now, where do you see yourself? If you want to work as a software engineer in multi-million dollar companies like Google or Amazon, you will need a CS degree. However, if you are planning to launch a startup or become a part of one, then coding boot camps may be a suitable option for you.

In essence, the only person that can decide if coding boot camp or college is the best option to develop your skills is YOU! Consider the factors above carefully before making a decision.