Vous êtes sur la page 1sur 10

Computer Hardware:

The motherboard is the computer's main circuit board. It's a thin plate that holds the CPU,
memory, connectors for the hard drive and optical drives, expansion cards to control the video
and audio, and connections to your computer's ports (such as USB ports). The motherboard

connects directly or indirectly to every part of the computer.


The central processing unit (CPU), also called a processor, is located inside the computer case on
the motherboard. It is sometimes called the brain of the computer, and its job is to carry out
commands. Whenever you press a key, click the mouse, or start an application, you're sending
instructions to the CPU.
The CPU is usually a two-inch ceramic square with a silicon chip located inside. The chip is
usually about the size of a thumbnail. The CPU fits into the motherboard's CPU socket, which is
covered by the heat sink, an object that absorbs heat from the CPU.
A processor's speed is measured in megahertz (MHz), or millions of instructions per second; and
gigahertz (GHz), or billions of instructions per second. A faster processor can execute
instructions more quickly. However, the actual speed of the computer depends on the speed of
many different componentsnot just the processor.

RAM is your system's short-term memory. Whenever your computer performs calculations, it
temporarily stores the data in the RAM until it is needed.
This short-term memory disappears when the computer is turned off. If you're working on a
document, spreadsheet, or other type of file, you'll need to save it to avoid losing it. When you
save a file, the data is written to the hard drive, which acts as long-term storage.
RAM is measured in megabytes (MB) or gigabytes (GB). The more RAM you have, the more
things your computer can do at the same time. If you don't have enough RAM, you may notice
that your computer is sluggish when you have several programs open. Because of this, many

people add extra RAM to their computers to improve performance.


The hard drive is where your software, documents, and other files are stored. The hard drive is
long-term storage, which means the data is still saved even if you turn the computer off or
unplug it.

When you run a program or open a file, the computer copies some of the data from the hard drive
onto the RAM. When you save a file, the data is copied back to the hard drive. The faster the
hard drive, the faster your computer can start up and load programs.

The power supply unit in a computer converts the power from the wall outlet to the type of
power needed by the computer. It sends power through cables to the motherboard and other
components.

Binary
Computer language is based off of binary code, a number system which uses two numbers, 1 and
0, to represent ON and OFF switches respectively. Binary is not something that you will see
repeatedly in code, but it is useful to learn so you can understand the logic behind how
computers work. In this part we will be learning how to convert from decimal to binary and vice
verse.
Decimal, a number system of base 10, is one that we use in everyday life. Binary is of base 2,
which is why we will be working with powers of two in these conversions.
Now, to convert from decimal to binary there are a few different methods, but I'll be showing the
one method that I found the easiest to understand and remember. Let's say you have the number
26 and you want to convert it to binary. First build a table of powers of 2, starting from 20 on the
right and go up till the power of two that is greater than the number you are trying to convert.
Next, evaluate each of these values.
Powers

25

24

23

22

21

20

Values

32

16

Now, you want to see which of these values will add up to your number. Start from the left and
youll see that 32 is greater than 26 so it will not go into 26. This means that 32 will be OFF, or
given the number 0. Next you see the number 16 which goes into 26, thus it will be ON, or given

the number 1. You are left with a remainder of 10 and continuing down the table you see that 8
goes into 10, making it ON. Next you have a 4; however, you only have a remainder of 2. In
effect, 4 is OFF. The next value is a 2, which is exactly the number you need and it is ON. Since
you have reached your decimal value, everything else in the table will be OFF. In this case we
only have one value left, 1, but in other cases we might have more values left. Either way, all of
them will be off since we have reached our value.
Powers

25

24

23

22

21

20

Values

32

16

ON/OFF

Now that you have your ON/OFF switches, read the binary from left to right to get your binary
number. Just like numbers in decimal, a 0 at the beginning of the number can be disregarded, but
0s at the end are important. Thus, 26 converted to binary is 11010.
To convert from binary to decimal, you create a similar table but instead of calculating whether
the switch is ON/OFF, you just add the values corresponding to the ON switches. Say your
binary number is 101001. Create your table:
Powers

25

24

23

22

21

20

Values

32

16

ON/OFF

The values corresponding to your ON switches are 32, 8, and 1. Add these numbers to get your
decimal value: 32+8+1 = 41.
Other ways to convert decimal to binary: http://www.wikihow.com/Convert-from-Decimal-toBinary
Binary to Decimal:
http://www.wikihow.com/Convert-from-Binary-to-Decimal
There are other number systems of other bases such as Hexa, Octal, Base 3, Base 4,
etc...However, since were focusing on Java code and syntax for this program we wont go into
detail on these, but I do recommend looking them up on your own time and exploring how to
convert from one number system to another.
To end this part of the lesson, heres a cool thing I found online:

There are only 10 types of people in the world. Those who understand binary and those who
dont.
(Hint: If you dont get it, 10 is in binary right now. Try converting 10 to decimal)

Java
Finally onto the fun stuff :)
Today were just working on printing statements in Java. Go ahead and open your text editor
(Notepad++ or Sublime) and retype this code into it. If you copy-paste it, the quotation marks
come out a bit different and the text editor reads this as an unknown symbol and thus an error.
Whoops :). Also, make sure to not save your code yet. Theres a specific process for that which
well go over later:
public class Intro{
public static void main(String[] args){
System.out.print(Hello World!);
}
}
The first line of this code public class Intro{ is called a class. This is the frame our entire
code is placed into and the frame is designated by the two curly brackets {}. All code that you
write will be placed within these two curly brackets. There are some exceptions but we will learn
about those later. The next line is public static void main(String[] args){
We will go over the meaning of each of those words later, but for now you should know that this
is called the main method. The main method is the only one that your terminal will look in. If
there is nothing in this method, then your code will not do anything. The stuff in parenthesis
String[] args lets the main method know what values to take in. This translates to An array
of Strings called args. If you wanted, you could change args to anything you want, such as
cookies. However, it is important that the first part stays the same. Generally, programmers do
not bother changing this line because it is not imperative to your code; however, feel free to play
around with it while youre learning. The curly frames on the main method are also important
because, just like the ones for the class, it tells you which lines of code are inside the main
method.
Within the main method we have a line of code that says System.out.print(Hello World!);
System.out.print() tells the computer that we want to print whatever is inside the parenthesis to
the terminal. If we say System.out.println(), this tells the computer that we want to print it on a
new line. Inside the parenthesis we have Hello World!. The quotation marks around the word
tell us and the computer that this is a string. If we do not place quotation marks around the
words, the terminal will throw an error because it does not know what those words represent. At
the end of the line, we have a semicolon. One important thing to know about Java is that a line

will either end with a curly bracket or a semicolon. A curly bracket indicates that the stuff
between the two brackets is inside this new frame. A semicolon indicates the end of the line.
I know that this is all a lot to take in at once, especially since most of it is confusing right now
and unclear. The best thing to do with coding is ask, ask, ask. Learning syntax in coding is easy,
the logic is the hard part. So if something is ever confusing, google it (there are an endless
number of websites that give coding help) or ask someone, in this case us :).
Saving a code
When you save your file, you want to make sure that you give it the EXACT same name as your
class. In this program we named our class Intro. So when you name your file when you save it,
you want to name it Java. Step 2 is to make sure that youre saving it as a .java file. This can be
done by changing the type in the drop down menu, or simply typing .java at the end of your file
name.
Also, make sure that you remember where you save it, whether in Documents, Desktop, or
another folder. To make this explanation general and easy to follow, go ahead and save it into
Documents for now. You can move it around later.
Running code in Terminal
Go ahead and open your terminal (terminal on Mac and Command Prompt on Windows. Or if
you downloaded something else like Git Bash)
The very first step you want to take is to lead your computer to your directory. If you try running
a file, your computer cant search through your entire laptop to find it, especially if there are
multiple files with the same name. So you need to direct your computer to the folder your file is
in. To do this, in your terminal (remember this is separate from your text editor), type in cd and
then the name of the folder your file is in, in this case Documents. Press Enter and your terminal
should look similar to this.

Now your computer knows to look in the Documents folder of your laptop for your file. If you
have your file in another folder in Documents, then you can do the same process again but with
the name of this next folder. For example, lets say my file Intro.java was in the folder Java
Summer Lessons in the folder Documents, then in the terminal I would do
cd Documents
cd Java Summer Lessons
If you want to condense it into one command you can just do:
cd Documents/Java Summer Lessons
One important thing to keep in mind is that you cannot directly go to the second folder. You have
to lead your laptop step by step (just how you cant teach someone to count to 10 without
teaching them how to get to each number before 10)
Now that you have led your laptop to the proper folder, you can compile your code. What
compilation does is it converts your code (written in any language) to assembly language,
something that the computer can read and translate. To compile, follow this syntax in your
terminal (Dont copy that exactly yet)
javac <name>.java
Instead of <name>.java, you put in the actual name of your file, in the case of the first lesson,
Intro. Once you press Enter, your terminal should look like this ( I placed my Intro.java file
within 3 nested folders which is why my cd line looks slightly different)

If nothing has appeared after your compiling line, that means you are in good shape! There are
no syntax errors in your code. However, this may not mean that your code is working the way
you want it to (well see examples of this later). Next you run the program by entering this line:
java Intro
Once you do that, your program should run and output whatever it is supposed to, and your
terminal should look like this:

Hopefully you were able to follow along and your program outputted the correct thing. If not,
check your code and make sure it is exactly the same as what I had above, or check what you
were entering in before. Java is a bit tedious in that your capitalization is important. It does not
read String and string as the same thing. So if anything is capitalized that is not supposed to be, it
will be incorrect. If youre still running errors, or not outputting the right thing, and cant figure
out why, send us a screenshot of your terminal and code and shoot us an email.

Conventions:
Conventions are something that are not necessary in Java but are important for code clarity. Also,
some things in this section arent convention, but very important to Java syntax. There just
wasnt enough to talk about that I wanted to create a separate section outside of conventions for
it :).
Naming:

Naming is a huge deal in any programming language. Whenever you name variables,
methods, files, or classes, you want to name them such that it is easy to understand what the
function does. For example, if you were in the class on Saturday, you may remember that we
named our class Foo (in this lesson, I called it Intro). Foo is a gibberish name which does not tell
us anything about what the class does. Intro, on the other hand, tells us that our program has
something to do with introduction. So, make sure to always name whatever youre applying a
name to something clear and understandable. (Code clarity also involves not making your name
too long. So you wouldnt want to name it something like: First_Class_Summer_Java_Lesson).
Always make sure the name of your class is the same as the name of your file when you save it.
Here are some naming conventions/important things to follow (this is from the book we are
following in the class)

Indentation:

Indentation does not affect how your code runs, it just makes it easier for the reader to
understand what you are doing. So make sure to always indent your code. Everything should be
indented one tab from the section it is within. For example, the code I had written above, the
method is indented one tab from the class it is in and the body of the method is indented one tab
in from the method header.

Vous aimerez peut-être aussi