Welcome, to the wonderful world of Computer Science (CS)! This area of study is totally changing the world, and we’re happy that you’ve decided to jump in.
Before you go too far, it’s important that you understand what this course is all about. This course is about solving problems... with code! It's about using a computer and some carefully crafted instructions to perform some amazing and incredible tasks. It's also about finding the best, most efficient way of solving a problem.
Take a look at the image below; this is some programming source code that determines the area of a rectangle with a length of 12 and a width of 15.
Determining the area of a rectangle isn't necessarily an incredible task, but hopefully you can imagine how you could repeat this process in order to have the program determine the area of a million rectangles and then determine the largest, smallest and average areas. This would save a lot of time!
This course focuses on both computer science and computer programming, so let's figure out the difference between the two.
Computer programming involves creating instructions for a computer to follow. It involves writing code that the computer can translate and understand, and it involves making really cool programs and applications for people.
Computer science involves the ideas, concepts and mathematical principles behind computer programming.
Example:
Imagine that you’ve been given six numbers and you’ve been asked to sort them from smallest to largest. The instructions you provide to sort them would constitute computer programming.
Now imagine you decided to analyze six different methods to sort the numbers. You figured out how many steps were involved in each method and you then selected to use the method with the least number of steps. That’s computer science!
Some people describe computer programming as a superpower. So maybe that means that computer science is the magic that makes that superpower possible?
The nice thing is that in this course you will be learning about and applying computer science using computer programming... so you get to do both!
The following interactive provides information related to the occupation of a Computer Programmer. Click on the essential skills to read more about each one.
Before we go on, the following video will provide you with some valuable information about what computer programming and computer science can allow you to do:
Did You Know…
A number of researchers study computer science and make new discoveries every day.
There is actually a Computer Science Best Paper Award that acknowledges important research in the field.
If you’re curious about the topics, take a look at past winners and see if anything interests you.
A computer program is written using a programming language. A number of computer programming languages exist. Some are quite new, while others have been around for a long time.
There are benefits and drawbacks to all computer languages. Some are great for web-based applications, others are great for system software or games or for learning, and still others are great for research and number crunching.
Some people find it very interesting to read about the most popular programming languages. These lists seem to change all of the time. Here are a few examples:
Resources - Popularity of Programming Languages:
Resources - Specific Language:
The creators of this course had to carefully consider which programming language would be the best for this course. It’s a tough decision. They wanted one that would allow you to develop skills quickly, but also be able to move on to other languages later. They also wanted a language that would allow you to be able to design graphical user interfaces (GUIs) and that would run on most computer systems without being too expensive.
So, they decided on… Java!
People often get hung up on the choice of programming language, but the choice of language is actually not that important. What’s most important is developing an understanding of the concepts of computer programming and computer science, and figuring out how to use commands to solve problems. If you can do this, then you can eventually move from language to language quite easily.
In order to program in Java you will need an IDE. An IDE is a piece of software that allows you to write computer programs. Now you have to be very careful here. An IDE is NOT a computer programming language. An IDE is a program that allows you to write programs using a programming language.
The Chicken or the Egg?
Sometimes in class, students will ask the following:
If you need an IDE to create a computer program, but an IDE is a computer program, then how did they create the first IDE?
It's a good question. Can you find the answer online? And while you're at it, can you find out which came first, the chicken or the egg?
In addition to the IDE, you are also going to need the Java development kit. A development kit is a collection of software that can turn your Java code into a program that will run on a computer.
The IDE we are suggesting that you use for Java programming in this course is Netbeans 8.2, but you can actually use other IDEs like Eclipse if you would like. It might be wise to contact your teacher if you’re hoping to use a different IDE.
You can download the Netbeans IDE and the JDK together as a package, and then once they are downloaded you can install the software:
Installation Instructions:
The instructions below take you through the steps of downloading the JDK and IDE on a windows computer, but you can install it on other systems as well.
Did You Know?
The developers of Java created a slogan that emphasizes a major advantage of the Java programming language. The slogan is, “Write Once, Run Anywhere” or WORA. This means that you write your Java program once on a computer, and then that developed program can be run on any computer system, anywhere.
This is unlike many popular programming languages where you have to compile the program slightly differently depending on the computer system that will run the program.
Wait, did you see that? There is a bolded word up there - compile.
It’s a pretty important word. Do you have any idea what that means?
Compile means to take a program that is written in a computer programming language, like Java, and turn it into a machine language code that the computer or device can actually run. Programmers work with a programming language like Java, but the computer itself doesn’t understand these commands. Instead, the program is first translated, put together, and built into machine language. This translating, putting together, and building is called compiling. You will read a little more about this later.
“
I heard somebody once say that if he were given five minutes to chop down the biggest tree in all of the northwest, or pay with his life, he would spend three of those five minutes sharpening his axe; and I think that that's the thing to do.
~ From Proceedings of the 101st Annual Meeting of the New York State Horticultural Society (1856)
The quote above, often wrongly attributed to Abraham Lincoln, drives home the point that in order to do an important job, you have to make sure that you have collected and properly prepared all the tools that you will need. This goes for chopping down a tree, and also for programming.
At this point, it’s important that you have the programming tools necessary (IDE and JDK) and that they are working and ready to go. You also need to make sure you have a computer system and workspace where you can do some amazing work.
It’s now time to write your first few programs in Java.
When you start the Netbeans IDE for the first time, it might look a little intimidating. However, don’t worry! You are only going to use a few of the features, and most of them will become very familiar to you as your work progresses.
The following photo carousel will take you through the steps of creating your first program. You can also view the video below, which takes you through the same steps. Good luck and have fun!
Click File > New Project…
Select Java > Java Application > and then Next.
Provide a project name (no spaces!) and select where you would like your project to be stored. Then click Finish.
You are now ready to add your computer programming code.
Add the code System.out.println ("Hello world!"); to line 18 of your program.
Click Run then choose Run Project.
You should see the output generated in what’s called the console window or output window.
The following video takes you through the above steps for creating your first program:
Did You Know?
The program you just wrote is often times called the “Hello World Program.” It is a bit of a computer programming tradition to make it the first program a person ever writes.
There are actually over 204 variants of the "Hello World Program," and you can read about its history starting with Brian Kernigham’s 1972 book, A Tutorial Introduction to the Language B.
It is now time to create the first program that you will share with your classmates.
Your task is to:
1. Create a new project in Netbeans and name it AboutMeLastName. Please don’t actually use the word Lastname; instead use your actual last name. This will allow your teacher to distinguish between your program and other people’s programs if they are stored together.
2. Using the following line of code, repeated several times:
System.out.println (“Information Goes Here”);
Create a program that answers the following ten questions:
The following image demonstrates what your program should output (but of course the information outputted will be relevant to you):
3. When the program is complete, take a screen capture of your output.
4. Share the screen capture of your output, as well as your project with your classmates.
A screen capture is basically like taking a picture of your screen. There are several ways to do it, but these links show you two methods:
Congratulations! You have now downloaded and installed an IDE and created your first computer program. How cool is that?!
Now it’s time to just look back a bit at exactly how the IDE is turning your Java code into a working program.
The code that programmers write needs to be translated into machine language that the computer can understand. Depending on the programming language, this is done with one of two pieces of software: either a compiler or an interpreter.
Although they do the same job, there are a few differences between a compiler and an interpreter. Look at the chart below:
COMPILER | INTERPRETER |
---|---|
Scans the entire program and translates it as a whole into machine code. | Translates program one line at a time. |
Takes longer to analyze the source code but the overall execution time is comparatively faster. | Takes less time to analyze the source code, but the overall execution time is slower. |
Generates intermediate object code which further requires linking, and hence requires more memory. | No intermediate object code is generated, hence making it more memory efficient. |
Generates an error message only after scanning the whole program, hence debugging is comparatively hard. | Continues translating the program until the first error is met, in which case it stops. This makes fixing the errors easy. |
Programming languages like C, C++ and Java use compilers. | Programming languages like Python and Ruby use interpreters. |
Java is a cool system because it uses a combination of both a compiler and an interpreter. Your Java code is first translated into a middle language called Java bytecode using a compiler. This bytecode is then translated into machine language code by an interpreter. This is what is happening behind the scenes when you click Run Project.
Remember earlier how we talked about WORA (Write Once Run Anywhere)? It’s the compiler-interpreter model that allows Java to implement WORA.
The compiler compiles the Java code into machine independent bytecode that can be used to run on any machine. Then the interpreter turns the bytecode into machine dependent machine code that is built specifically for the machine where the program will run.
This has allowed Java programs to be made for different types of computers, but also for other devices as well. There are many types of devices that run on Java, including parking meters, Blu-ray players, airplane systems and ATMs.
The topic of compilers, interpreters, bytecode and machine code can get a bit tricky, so let’s review a few ideas and make sure you understand the details.
The interactive below will help you become familiar with the components:
Oh yes; there is one last thing! The interpreter that Java uses has a special name. It’s called the Java Virtual Machine (JVM). The JVM is what takes the bytecode and creates machine code for the specific machines:
Did You Know?
Younger and younger students are now taking part in computer programming and computer science activities. Tools such as ScratchJr, Scratch and Apple Playgrounds are allowing young children to develop their skills without having to write actual code.
These tools use “block coding,” which allows students to drag and drop “blocks” of code. The “blocks” are then connected together to create a sequential set of steps for the program to follow. AMAZING!