Download 1 - Shrek

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Dynamic-link library wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Program optimization wikipedia , lookup

Go (programming language) wikipedia , lookup

Comment (computer programming) wikipedia , lookup

Scala (programming language) wikipedia , lookup

C Sharp syntax wikipedia , lookup

Object-oriented programming wikipedia , lookup

Name mangling wikipedia , lookup

Diff wikipedia , lookup

Library (computing) wikipedia , lookup

C++ wikipedia , lookup

Compiler wikipedia , lookup

Computer file wikipedia , lookup

Java (programming language) wikipedia , lookup

Java performance wikipedia , lookup

Interpreter (computing) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Transcript
1. The LINUX programming environment : source,
object, binary-executable. Editors, compilers, linkers.
Source => Plain Text
Object => produced from source code after compilation.
Binary(executable) => created by the linker.
Compiler => Transforms a code written in an plain text editor to an object.
Linker => After objects are created from source code, it links them together to create an
executable file.(binary file)
-o => a flag used to give a name to your target file( $gcc hello.c –o hello)
* Target file may be the executable file in case of the linker, and the object in case of the
compiler.
Simple compilation of more then 1 file ($gcc hello.c hell.c zbz.c wtf.c –o hello_ultra)
Without –o flag your final binary-executable file will be named as “a.out”
Process of Compilation
1. Pre-Compile –take out comments,expand #define macros,#include libraries
2. Compile – parse the source code and build assembly output.
3. Assemble – take an assembly code and build an object file.
4. Link – build an executable file by linking objects together.
Compiler can be stopped at any stage using flags :
-E => stops after preprocessing stage. Outputs the source code to standard
output.(terminal)
-S => stops after compile stage. Outputs the assembly file for each source file with
extension .s
-c => stops after the assembly stage. Outputs the object file for each source file with
extension .o
2. Scripting in LINUX.
3.The make utility. Makefile.
(Makefile is nothing more then a shell script -personal opinion of the author, which
would be Tihon in this case. The idea which Maziar shares as well.)
The make utility is designed to manage large groups of source files. It automatically
determines which piece of a large program needs to be recompiled and issues the
command to recompile them. The decision is mainly based on “last modified time” of
different sources and objects. The make utility uses a file usually named Makefile or
makefile to represent dependencies between source files.
Makefile consists of command like these:
Rule_name:[list of rule dependencies] [list of file dependencies]
[tab][command]
Ex.1
# our first makefile <= this is a comment
hello: hello.cpp
g++ hello.cpp -o hello
Ex.2
#our second makefile <= another comment
hello: hello.o util.o
g++ hello.o util.o -o hello
hello.o: hello.cpp
g++ -c hello.cpp
util.o:util.h util.cpp
g++ -c util.cpp
clean:
rm *.o hello
# end
explanation of the Ex.2
$ make
1. make executes the first rule it finds, namely hello.
2. hello has dependencies hello.o and util.o. If these files are not present make looks for a
rule that tells it how to construct them. Assume both files are not present.
3. First make looks for a rule to build hello.o, which is found below.
4. This rule depends on hello.cpp which is present, so the command executes and an
object file hello.o is created. (Note the –c flag.)
5. Then make returns to the hello rule and finds that util.o is still not present, so it looks
for a rule to build this file.
6. In the util.o rule we see that it depends on util.h and util.cpp. These are present so the
command is executed and util.o is created.
7. Finally both hello.o and util.o are present so the hello rule executes its command and
links the object files into an executable named hello.
* A point to be said about make utility, is that one of the goals in using it, is to avoid
repeated compilation, so if a file is already converted to Object, it's useless to do it again
if in the time between two consecutive make commands, the file is untouched. Make
avoids this situation by checking last modified time stamps on files.
The final addition to our makefile is the clean rule. This rule removes object files and the
executable.
4. The Java environment (javac,java).
Netbeans/Eclipse
Editors : they generally highlight the Java syntax, indent for you, balance your
parentheses and braces, and let you compile from within the editor.
(TextPad,Emacs,JEdit,NEdit,BBEdit)
IDE: most of them have visual Java development tools, tight integration with the
compiler or application server, and may include tools for debugging, refactoring, version
control, and so forth.(Netbeans/Eclipse)
An IDE usually consists of : 1. a source code editor,2.build automation tools,3.a debugger
Javac - Java programming compiler.
The javac tool reads class and interface definitions, written in the Java programming
language, and compiles them into bytecode class files.
There are 2 ways to pass source code to javac:
1. for a small amount of source files,just list them on the command line
2.for a large amount of source files,put the names in a txt file and pass it as an argument
(makefile)
You should arrange source files in a directory tree that reflects their package tree.
Meaning, you should put the source file related to one program into the same folder.
One characteristic of Java is portability, which means that computer programs written in
the Java language must run similarly on any hardware/operating-system platform. This is
achieved by compiling the Java language code to an intermediate representation called
Java bytecode, instead of directly to platform-specific machine code. Java bytecode
instructions are analogous to machine code, but are intended to be interpreted by a virtual
machine (VM) written specifically for the host hardware. End-users commonly use a Java
Runtime Environment (JRE) installed on their own machine for standalone Java
applications, or in a Web browser for Java applets.
Java source files must be named after the public class they contain,appending the suffix
.java! example HelloWorld.java
This source file will be transformed into bytecode by the java compiler (javac) producing
a HelloWorld.class
Then it can be executed!
5.Applets,using applets in html pages.
Applet is any small application that performs one specific task that runs in a scope of a
larger program,often as a plug-in.(typically java applets – programs written in java that
are included in a web page)
Applets are used to provide interactive features to web applications that cannot be
provided by HTML alone. They can capture mouse input and also have controls like
buttons or check boxes. In response to the user action an applet can change the provided
graphic content. Applets are also used to create online game collections that allow players
to compete against live opponents in real-time.
Examples of Web-based Applets include:
1.QuickTime movies
2.Flash movies
3.Windows Media Player applets(for internet explorer)
…
Applets are written in a language different from the scripting or HTML language that
invokes it. The applet is written in a compiled language, whereas the scripting language
of the container is an interpreted language, hence the greater performance or functionality
of the applet.
Java Applets can provide web applications with interactive features that cannot be
provided by HTML. Since Java's bytecode is platform-independent, Java applets can be
executed by browsers running under many platforms, including Windows, Unix, Mac
OS, and Linux.
<applet code="Bubbles.class" width="350" height="350"> Java applet that draws
animated bubbles.
</applet>
6. IDE services
Integrated Development Environment
IDEs typically present a single program in which all development is done. This program
typically provides many features for authoring, modifying, compiling, deploying and
debugging software. The aim is to abstract the configuration necessary to piece together
command line utilities in a cohesive unit, which theoretically reduces the time to learn a
language, and increases developer productivity.
7.WWW programming environments,LAMPP,XAMPP
LAMPP-Linux /Apache http/Mysql/Php/Pearl
XAMPP-X(cross)/-------------------------------XAMPP is a free and open source cross-platform web server solution stack package,
consisting mainly of the Apache HTTP Server, MySQL database, and interpreters for
scripts written in the PHP and Perl programming languages.
Officially - XAMPP's designers intended it for use only as a development tool, to allow
website designers and programmers to test their work on their own computers without
any access to the Internet.
Reality - XAMPP is sometimes used to actually serve web pages on the World Wide
Web.
8.PHP Scripting
Php scripting somewhat look similar to html code fragments,(in fact php is a web
programing language so it is connected with html)
Examples could be found in a book (Teach Yourself PHP, MySQL, And Apache All-InOne, 3rd Edition (2006) )
So anyways, the part we were looking at in class:
Syntax:
You can define your own functions using the function statement:
function some_function($argument1, $argument2) {
//function code here
}
(1:.2:.3: -> these are just line numbers you don’t type that in your code!!!)
Ex1.
1:
2:
3:
4:
5:
6:
<?php
function bighello() {
echo "<h1>HELLO!</h1>";
}
bighello();
?>
Ex2.
1:
2:
3:
4:
5:
6:
7:
8:
<?php
function printBR($txt) {
echo $txt."<br/>";
}
printBR("This is a line.");
printBR("This is a new line.");
printBR("This is yet another line.");
?>
Ex3. (function with return falue)
1:
2:
3:
4:
5:
6:
7:
8:
<?php
function addNums($firstnum, $secondnum) {
$result = $firstnum + $secondnum;
return $result;
}
echo addNums(3,5);
//will print "8"
?>
Some more basic examples:
(Variable assignment, printing out famous HELLOWORLD and so on….)
Ex1.
<?
print("Hello world!");
?>
// print the letters in-between “ “
Ex2.
<?
$welcome_text = "Hello and welcome to my website.";
print($welcome_text);
?>
//assign a variable
// print the variable
Ex3.
<?
print("<font face=\"Arial\" color\"#FF0000\">Hello and welcome to my
website.</font>");
?>
// in order for PHP to understand that you are using HTML syntax you need to put
backslash (\) before “ ” in order for PHP to ignore them.
This code illustrates how this is done! <font face> is a typical HTML tag!
Ex4. ( as with every programming language there is flow control, so here is one example)
1: <?php
2: $mood = "happy";
3: if ($mood == "happy") {
4: echo "Hooray, I'm in a good mood!";
5: }
6: ?>
9. MySQL www access