Try the free version of Progate [Java II]

Continuing from Last time, I will continue to do Progate free lessons.

This time it's Java II. This is free.

Lesson List

Java II

Official lesson

Boolean value / comparison operation

Comparison operator (2)

Logical operator

・ Because it is a basic thing ... omitted

if statement

・ Basically ... I have to put a little on it ...


Where there is a wavy line, it is a "dead code". As the name implies, it is false, so the processing inside the if block is never executed.

Execution result from command prompt image.png

else, else if ・ Java is written as ʻelse if. ~~ It feels better than ʻelsif ... ~~ As pointed out in another article, ʻelse if is not a single conditional branch, It seems that ʻelse and ʻif` are consecutive and they are only written in one line.

if (x == 8) {
} else {
  if (x > 8) {
    System.out.println("Greater than 8");
  } else {
    System.out.println("Less than 8");

//↓ else as shown below{}Just abbreviated

if (x == 8) {
} else if (x > 8) {
    System.out.println("Greater than 8");
  } else {
    System.out.println("Less than 8");

//* I don't have the indentation.

So I understood that it is different from Ruby's ʻelif and Python's ʻelif. The result of the process will be the same.

By the way, for java, it is better to use ʻequals` for string comparison.

var test = new String("test");
System.out.println(test == "test"); //Become false

System.out.println(test.equals("test")); //Become true

== is comparing the reference destination of the stored memory. ① var test = new String ("test") is first stored in memory. ② System.out.println (test ==" test "); "test" `is stored in a place different from ①. Therefore, it is judged to be different.


var test = new String("test");
var test2 = test;
System.out.println(test == test2 ); //Will be true.

This will be true. Because the reference destination is the same.

Also, it's really complicated,

var test = "test";
System.out.println(test == "test"); //Become true

Will be true. Apparently, if you set the literal " test ", it will refer to the same place if it is the same character string. It's complicated ...

For the time being, if you are using ʻequals`, you can make a mistake.

switch statement / switch statement (2)

・ Basic things. casedefaultbreak;

while statement / for statement

・ Java for is also orthodox

for (var i = 0; i < count; i++) {

Form of. If it's a lesson, I get angry when I use var ...

break, continue ・ Break out of the break loop. ・ Continue skip, next element.

Let's use an array

new String[] {"test","bbb"};


{"test", "bbb"};

But it looks like I can go ... I did not know···. C # is probably impossible ...

Overwriting the elements of the array, repeating the array

·nothing special···.

Extended for statement

・ Foreach in C #

var numbers2 = new int[]{1, 2, 3, 4};
for (var number2 : numbers2) {

Comprehensive task

** Exercise **

package jp.test.testproject;

public class ProgateTest {

	public static void main(String[] args) {
	    //Substitute the given array of numbers for the variable numbers
	    int[] numbers = {1, 4, 6, 9, 13, 16};

	    int oddSum = 0;
	    int evenSum = 0;

	    //Use the for statement to find the sum of even and odd numbers in the array numbers
	    for (int number : numbers) {
	      if(number % 2 == 0) {
	        evenSum += number;
	      } else {
	        oddSum += number;

	    System.out.println("The sum of odd numbers is" + oddSum + "is");
	    System.out.println("The sum of even numbers" + evenSum + "is");

result image.png

** Cleared ** image.png


It's terrible ... It's an article with almost no content ... It's too basic, and the introductory editions of other languages that I've done so far are enough.

Next time, I would like to do Python I.

Recommended Posts

Try the free version of Progate [Java II]
Try the free version of Progate [Java I]
[Java version] The story of serialization
[Java] Check the JDK version of the built war file
Switch the version of bundler
[Java] Try editing the elements of the Json string using the library
[Java] Delete the elements of List
The origin of Java lambda expressions
Let's talk about the passing experience of Java SE 8 Programmer II
Switch the version of java installed by SDKMAN when moving directories
Try Hello World with the minimum configuration of Heroku Java spring-boot
Is the version of Elasticsearch you are using compatible with Java 11?
Get the result of POST in Java
Try using || instead of the ternary operator
About the version of Docker's Node.js image
Check the contents of the Java certificate store
Examine the memory usage of Java elements
[Java] Get the day of the specific day of the week
Try using the Stream API in Java
Memo: [Java] Check the contents of the directory
Installation of OMC APM Agent --Java version-
Compare the elements of an array (Java)
Try calling the CORBA service in Java 11+
[day: 5] I summarized the basics of Java
What are the updated features of java 13
Easily measure the size of Java Objects
How to find out the Java version of a compiled class file
Looking back on the basics of Java
How to install the legacy version [Java]
Output of the book "Introduction to Java"
The story of writing Java in Emacs
Check the version of the standard Web software.
[Java] Check the number of occurrences of characters
[Java] [Spring] Test the behavior of the logger
Try using the Wii remote with Java
Easy JSON database experience with Docker ~ Try the latest version of Couchbase Server
Send a notification to slack with the free version of sentry (using lambda)
Check the version of the JDK installed and the version of the JDK enabled
[Java] Handling of JavaBeans in the method chain
The story of making ordinary Othello in Java
[Android] [Java] Manage the state of CheckBox of ListView
About the idea of anonymous classes in Java
The order of Java method modifiers is fixed
Measure the size of a folder in Java
[Java] Get the length of the surrogate pair string
[Java] The confusing part of String and StringBuilder
[Note] Java: Measures the speed of string concatenation
Try calling the CORBA service from Spring (Java)
Manage the version of Ruby itself with rbenv
[Java] Be careful of the key type of Map
Feel the passage of time even in Java
Try using Sourcetrail (win version) in Java code
Set Java version 11 of Docker Minecraft Paper server
Calculate the similarity score of strings with JAVA
Try similar search of Image Search using Java SDK [Search]
Install the latest version of Jenkins on Ubuntu 16
[Java / Kotlin] Resize considering the orientation of the image
I touched on the new features of Java 15
The date time of java8 has been updated
Try using the COTOHA API parsing in Java
[Java] How to get the authority of the folder