Blog of Java Programmer

Blog of Java Programmer Contact information, map and directions, contact form, opening hours, services, ratings, photos, videos and announcements from Blog of Java Programmer, Kyiv.

25/08/2021

Sort digits with ArrayList:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Solution {
public static void main(String[] args) throws IOException {
// insert code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

ArrayList mainList = new ArrayList();
for (int i = 0; i < 20; i++) {
mainList.add(Integer.parseInt(reader.readLine()));
}

ArrayList multipleThree = new ArrayList();
ArrayList multipleTwo = new ArrayList();
ArrayList multipleThreeAndTwo = new ArrayList();

for (int i = 0; i < mainList.size(); i++) {
Integer figure = mainList.get(i);

if (figure % 3 == 0 || figure % 2 == 0) {
if (figure % 3 == 0) {
multipleThree.add(figure);
}
if (figure % 2 == 0) {
multipleTwo.add(figure);
}
}else {
multipleThreeAndTwo.add(figure);
}
}

Java coding
29/07/2021

Java coding

Оператор деления по модулю - оператор mod, обозначается символом %.Этот оператор возвращает остаток от деления первого о...
18/07/2021

Оператор деления по модулю - оператор mod, обозначается символом %.
Этот оператор возвращает остаток от деления первого операнда на второй.
Оператор mod "%" в Java работает не только с целыми (такие как: byte/int/short/long),
но и с плавающей точкой (такие как: float/double) числами\типами.

Pattern: Object Poolpublic class PullObjects {    public static void main(String[] args) {        ObjectPool objectPool ...
01/03/2021

Pattern: Object Pool

public class PullObjects {
public static void main(String[] args) {
ObjectPool objectPool = new ObjectPool();
PooledObject pooledObject = objectPool.getPooledObject();
objectPool.releasePooledObject(pooledObject);
}
}

class PooledObject {

}
// басейн
class ObjectPool {
List free = new LinkedList();
List used = new LinkedList();

public PooledObject getPooledObject() {
if (free.isEmpty()) {
PooledObject pooledObject = new PooledObject();
free.add(pooledObject);
return pooledObject;
}else {
PooledObject pooledObject = free.get(0);
used.add(pooledObject);
free.remove(pooledObject);
return pooledObject;
}
}

public void releasePooledObject(PooledObject pooledObject) {
used.remove(pooledObject);
free.add(pooledObject);
}
}

20/02/2021

Код для контроллера блога

package com.fara0n.blog.controllers;

import com.fara0n.blog.models.Post;
import com.fara0n.blog.repo.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.Optional;


public class BlogController {


private PostRepository postRepository;

("/blog")
public String blogMain(Model model) {
Iterable posts = postRepository.findAll();
model.addAttribute("posts", posts);
return "blog-main";
}

("/blog/add")
public String blogAdd(Model model) {
return "blog-add";
}

("/blog/add")
public String blogPostAdd( String title, String anons, String full_text, Model model) {
Post post = new Post(title, anons, full_text);
postRepository.save(post);
return "redirect:/blog";
}

("/blog/{id}")
public String blogDetails((value = "id") long id, Model model) {
if (!postRepository.existsById(id)) {
return "redirect:/blog";
}

Optional post = postRepository.findById(id);
ArrayList res = new ArrayList();
post.ifPresent(res::add);
model.addAttribute("post", res);
return "blog-details";
}

("/blog/{id}/edit")
public String blogEdit((value = "id") long id, Model model) {
if (!postRepository.existsById(id)) {
return "redirect:/blog";
}

Optional post = postRepository.findById(id);
ArrayList res = new ArrayList();
post.ifPresent(res::add);
model.addAttribute("post", res);
return "blog-edit";
}

("/blog/{id}/edit")
public String blogPostUpdate((value = "id") long id, String title, String anons, String full_text, Model model) {
Post post = postRepository.findById(id).orElseThrow();
post.setTitle(title);
post.setAnons(anons);
post.setFull_text(full_text);
postRepository.save(post);
return "redirect:/blog";
}

("/blog/{id}/remove")
public String blogPostDelete((value = "id") long id, Model model) {
Post post = postRepository.findById(id).orElseThrow();
postRepository.delete(post);
return "redirect:/blog";
}
}

14/02/2021

Настройки подключения Spring к базе данных mySQL:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/Имя_базы_данных
spring.datasource.username=root
spring.datasource.password=root
(файл - application.properties)

pom зависимости:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/spring_web_blog
spring.datasource.username=root
spring.datasource.password=root

13/02/2021

Эта страница будет временной площадкой для блога, основной сайт разрабатывается!
Let's continue to discuss about Spring and java Android development!

13/02/2021

My repository is closed:
https://bitbucket.org/dashboard/overview
Contact with me for communication

Log in to Jira, Confluence, and all other Atlassian Cloud products here. Not an Atlassian user? Sign up for free.

Prog life
05/11/2020

Prog life

Address

Kyiv

Website

Alerts

Be the first to know and let us send you an email when Blog of Java Programmer posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Share