The other day, at a programming experience meeting held in-house, I had an opportunity to talk about "what is programming" to inexperienced people, so I will summarize what I liked for the next opportunity and what I want to improve for myself. Put.
[Career of people who come to the experience session] People with various backgrounds come to the experience session. ・ I was studying Java when I was in college ~ ・ I'm in the hospitality business and haven't touched my computer very much ~ ・ I was interested in the IT industry while thinking about changing jobs. There were many people from other industries and inexperienced.
[What people who come to the experience meeting are looking for (questions frequently asked at the exchange meeting after the experience meeting, etc.)] ・ Completely inexperienced → Programming seems to be difficult ... → How do you make it? ・ I have no work experience, but I have touched it for a while (university, etc.) → Is this company okay? (Normally feels like a company information session) → What is the job of an engineer like?
Since the levels are different, it is not possible to teach all of them with the same level of feeling.
This time I would like to make a note of how to teach for completely inexperienced people. Let's answer whether this company is okay even after the experience session is over.
First of all, I will talk about programming, programming, and images of programming languages.
Many beginners don't know what a program looks like, so what is a programming language? The condition is not uncommon.
I'm talking about that, so I think it's important to get an image as much as possible.
And try not to use ** difficult words ** as much as possible. As with anything, if you are not good at it, it will be difficult to absorb it, so I will explain it in an easy-to-understand manner. Of course, there are some situations where you have to use it, so it's impossible not to use it at all, but if you use it, it's okay if you also convey the meaning of the word.
Example) The written program cannot be executed without compiling. → In order to execute a program, you have to perform a process called "compilation" that translates the written code into computer language.
I think it's better to chew as much as possible and teach. It is important not to be weak by speaking in the most familiar language possible.
--A rough sketch of what the program does (language types, etc.)
--Program flow (how it works) --Variables --A little bit of simple syntax (if or for)
--Write a simple code in Eclipse and have it executed
A program is an instruction directed at a computer.
When we usually give instructions to people, we usually use language. Japanese people use Japanese, American people use English, and Chinese people use Chinese, but when they support something on a computer, they use the same language. That is the programming language. Instructions written using a programming language are called "programs", and "writing a program" is called "programming".
Many people may find it difficult to say "programming", but there are rules because it is only programming "language". Once you remember the rules, you can read and write like Japanese, so you don't have to think hard.
By the way, do you know how many programming languages there are?
It is said that there are more than 200 types including minor languages including Java introduced in this article. However, it is not the case that all of these are used in daily work. Some functions are easy to realize and some are difficult to realize depending on the language. Please check for details. This section describes the basics of Java.
Now that you understand that programming is about writing [instructions for giving instructions to a computer called a program], let's take a look at the flow from writing a program to executing it. The program compiles and then runs. (But I don't think beginners know how to compile and run it. It's a word I don't use in my daily life ... So, to make it easier to imagine Input (programming) → Machining (compile) → Output (execution) It may be easier to understand if you think in terms of. )
Enter the code in the main method, compile it (process it into words that the computer can understand), and output it to the console. It is a good idea to execute while saying the flow of how the written material is output. Don't forget to explain the location of the console (it will be displayed here)
Sample.java
package sample;
public class Sample {
public static void main(String[] args) {
System.out.println("Hello World!!");
}
}
Output contents
Hello World!!
If you can output "Hello World !!", ask them to write a program that outputs your name to the console. At that time, there are quite a lot of people who do not rewrite "Hello World !!" in System.out.println, but erase everything from the package and rewrite everything, so ask them to change only in System.out.println. Let's be careful. Also, please let me know because there are quite a lot of people who write in full-width characters and get an error. Some people don't know how to put out "or {, so please be kind.
(I think variables are the easiest for beginners to get caught in.) In a nutshell, a variable is a [box to store (store) values]. In Java, variables have a fixed type, and only values of the fixed type can be stored. Here is a brief description of numbers and strings. About the types int and String. This type is called a data type, and you can see what type the value is. int is a number and String is a string.
Numerical values here are integers and do not include decimal numbers. For example, [1], [10], and [100000]. (Decimal numbers are decimal numbers and there are other data types, but they are omitted here. Also, the data type to be used is determined by the number of digits that can be stored in the numerical value, but it will be complicated, so I will omit it here. ) Only numbers can be stored in int type, and numbers can be calculated.
String can be a string. The string is the non-numeric characters, such as ["a"] and ["ABCDE"] ["Hello"]. However, in fact, it can also store numerical values. ["1"] and ["10"] etc. However, if you put a numerical value in the String, you will not be able to calculate like an int. → Numerical value as a character string. (Explanation by how to use)
How to use
[Data type used] [Variable name]=[Value to be stored];
Calculation with int
int num1 = 10;
int num2 = 15;
//Calculated according to the formula
num1 + num2 = 25
Calculation with String
String num1 = "10";
String num2 = "15"
//Characters are connected and displayed
num1 + num2 = "1015"
Once you understand the variables, let's explain the simple syntax. Since the image is important, it is a good idea to explain by taking the things around you as an example. For example, conditional branching Ask them to actually write an example of the explanation, such as "Are you 20 years old or older? Yes or No" when you purchase alcohol or cigarettes at a convenience store.
Basic writing ・ If (If ○○, △△)
if (Condition 1 (○○)) { Processing to be executed if condition 1 (○○) is satisfied (△△) }
・ Else (If ○○, △△, otherwise □□)
if (Condition 1 (○○)) { Processing to be executed if condition 1 (○○) is satisfied (△△) } else { Processing to be executed if condition 1 is not met (□□) }
・ Else if (If ○○, △△, ●●, ▲▲, otherwise □□)
if (Condition 1 (○○)) { Processing to be executed if condition 1 (○○) is satisfied (△△) } else if (Condition 2 (●●)) { Condition 1 (○○) is not satisfied Process to be executed if condition 2 (●●) is satisfied (▲▲) } else { Process to be executed when condition 1 (○○) and condition 2 (●●) are not satisfied (□□) }
if exercises
* First of all, I think it is important for you to write a simple program and try out the feeling of moving it.
It is easy to understand the meaning of the conditional expression if you change the contents of the variable age by yourself and confirm that it is not output to the console if it is other than 100.
// if
//If the age is 100, it outputs "I live for a century".
//Use the variable int age
//answer
int age = 100;
if (age == 100) {
System.out.println("I have lived for a century.");
}
// else
//If the age is 20 years or older, "I can drink" is output, otherwise "I can't drink" is output.
//Use the variable int age
int age = 20;
if (age >= 20) {
System.out.println("You can drink alcohol");
} else {
System.out.println("I can't drink alcohol");
}
//* Also here, change some of the contents of age and have them try changing the output contents.
// else if
//If the test score is 80 points or more, please output "excellent". If the test score is 60 points or more, "OK".
//Use the variable int score(score is 0~Only 100 will be included)
int score = 80;
if (score >= 80) {
System.out.println("Yu");
} else if (score >= 60) {
System.out.println("Yes");
} else {
System.out.println("Impossible");
}
//* Also here, change some of the contents of age and have them try changing the output contents.
For iterative processing "How do I write my name when I print it to the console five times?" If you ask, most people
Output 5 times
System.out.println("My name");
System.out.println("My name");
System.out.println("My name");
System.out.println("My name");
System.out.println("My name");
Will implement it. It's easy to write about 5 times, but it's really annoying when it comes to outputting 100 times. .. .. Iterative processing can be used in such cases. I will proceed with the feeling.
・ For syntax
for ([Initial value]; [Repeat conditional expression]; [Continuous processing];) { // Processing content to be performed when the repeating conditional expression is "true" }
Exercises
//Let's output your name 5 times
for (int i = 1; i<=5; i++) {
System.out.println("Yamada Taro");
}
In for, the process is executed when "i" is "5" or less. "I" is "++" after each process. That is, it increases by 1. If you follow the process in an easy-to-understand manner
First time
//Since i is 1, "Taro Yamada" is output.
for (1 <= 5) {
System.out.println("Yamada Taro");
}
//Output result: Taro Yamada
Second time
// i++And since i is 2, "Taro Yamada" is output.
for (2 <= 5) {
System.out.println("Yamada Taro");
}
//Output result: Taro Yamada
Third time
// i++And since i is 3, "Taro Yamada" is output.
for (3 <= 5) {
System.out.println("Yamada Taro");
}
//Output result: Taro Yamada
4th
// i++And since i is 4, "Taro Yamada" is output.
for (4 <= 5) {
System.out.println("Yamada Taro");
}
//Output result: Taro Yamada
5th time
// i++And since i is 5, "Taro Yamada" is output.
for (5 <= 5) {
System.out.println("Yamada Taro");
}
//Output result: Taro Yamada
6th time
// i++And since i is 6, "my name" is not output.
for (6 <= 5) {
System.out.println("Yamada Taro");
}
//Output result: No output
Roughly explaining like this, programming is easier and more fun than I thought! I think that it will be easier to absorb if you come in from.
Finally, I think it will be easier to get started if you do logic exercises like a puzzle, so I will write only famous problems.
fizzbuzz
// 1~While outputting up to 100 in order
//If it is divisible by 3, use "fizz"
//If it is divisible by 5, use "buzz"
//If it is divisible by both 3 and 5, please output "fizzbuzz"
//Example) 1,2,fizz,4,buzz,fizz,...,14,fizzbuzz,16,......,98,fizz,buzz
//answer
public class Sample {
public static void main(String[] args) {
for (int i = 1; i<=100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.println("fizzbuzz");
} else if (i % 3 == 0) {
System.out.println("fizz");
} else if (i % 5 == 0) {
System.out.println("buzz");
} else {
System.out.println(i);
}
}
}
}
Thank you for reading ^^ ** It's weird here ** or ** It's better to teach like this! ** Please let me know if you have any! I'm also happy with the advice on how to write markdown!
Recommended Posts