A lecture snippet with a mentor as part of the Codegym University course. Sign up for the full course.

"Hi, Amigo."

"Hello, Eleanor Carrey."

"Just call me Ellie. There's no need to be so formal."

"OK, Ellie."

"I believe with my help you'll soon be one of the best. I have a lot of experience training rookies. Stick with me, and everything will be just fine. Well, let's get started."

"There are two major types in Java: String and int. We store strings/text in String, and integers (whole numbers) in int. To declare a new variable, you need to specify its type and name. The name cannot be the same as the names of any other variables and/or functions."

Example 1, code: Description
String s;
A new variable s is declared. It can store text.
int i;
A new variable i, is declared. It can store integers.

"You can assign values to variables when you declare them."

Example 2, code: Description
String s = "Ellie";
Variable s stores the string "Ellie".
int i = 5;
Variable i stores the number 5.

"To assign a new value to a variable, we use the = sign. It is also called the 'assignment operator'. Assignment means to place into a variable a value from another variable or one computed from several variables."

Example 3, code: Description
int a = 5;
Variable a stores the value 5.
int b = 6;
Variable b stores the value 6.
int c = a + b;
Variable c stores the value 11.

"A variable's value can be used to compute a new value that will replace the old one."

Example 4, code: Description
int a = 2;
Now a equals 2
int b = 3;
Now b equals 3
a = a + b;
Now a equals 5
b = b + 1;
Now b equals 4

"You can merge strings with the + sign:"

Example 5, code: Description
String s1 = "Rain";
String s2 = "In";
String s3 = s1 + s2 + "Spain";
Variable s3 stores the string "RainInSpain"

"Sometimes, strings consisting of one or more spaces can come in handy:"

Example 6, code: Description
String s1 = "My favorite movie is";
String s2 = "Route";
int roadNumber = 66;
String text = s1 + " " + s2 + " " + roadNumber;
text stores "My favorite movie is Route 66"

"Let's take a look at how we display text and variables on the screen:"

Introducing ints and Strings - 1
Example 7, code:
System.out.println("A man's gotta do what a man's gotta do");
String s = "A man's gotta do what a man's gotta do";

"By the way, Diego asked me to give you a couple of exercises:"

New Java Syntax,  level 1lesson 4
Kind words for the teacher
Write a program that displays "Ellie is very smart" 5 times. Each time, on a new line. Example output: Ellie is very smart Ellie is very smart Ellie is very smart Ellie is very smart Ellie is very smart
New Java Syntax,  level 1lesson 4
My young friend
It's currently 3126. My friend was born 8 years ago. Write a program that displays my friend's birth year.
New Java Syntax,  level 1lesson 4
Declare variables
Write a program that declares the following variables in the main method: String name, int age, and String city. Note: "Declaring a variable" is the same thing as "creating a variable".