Monday 24 November 2014

Beginning Programming
Code to Execute
To repeat what we discussed in the last section, the program containing source code always has extension .java. The Java compiler always generates bytecode with same name and has an extension .class. The class file processed by the JVM and produces output. It is a rule that the source file name must match with the class name inside the file.
Source file
Class name
Byte code
HelloWorld.java
HelloWorld
HelloWorld.class
AddNumbers.java
AddNumbers
AddNumbers.class
Average.java
Average
Average.class
 In a Java application, execution starts with the main method. We have already used this method and will understand it better later in the course. You must have heard that Java is "platform independent". What does this mean? This means that you can write Java code on some system, say a Windows machine, and compile it. Then you can take the classfile generated and run it on any other system (Linux, Unix, MAC, or another Windows) and the code will run!
Beginning Programming
Creating and Running Java Application
We have been learning the basic concepts of Java and running code fragments from the text area. However, to actually develop and run a Java application, we need do something more. We must install the necessary software
  • JDK or Java Development Kit, which is software that can be used to develop Java based software. The JDK consists of software including Java Runtime Environment (JRE), Java compiler (javac), debugger, additional support software needed to write Java applications.
  • The Java Runtime Environment (JRE) is required to execute Java code. It consists of the Java Virtual Machine (JVM) plus standard classes and libraries needed to execute the code. The emulation capability of the JVM  allows execution of Java code in a platform independent way using the java command.
The typical execution cycle for a Java application, say to print Hello World is pictured below
A Java application must have the extension .java - this is a language rule. Upon compiling, it gets converted to a class file also known as bytecode. The JVM executes the class file using the java command.
Beginning Programming
Methods
We saw that methods allow us to define behaviour of objects - in this section we take a closer look at methods. In our first program, we wrote our code inside the main method. The main method is a special method in a Java application and the one where execution of a Java program starts. In object oriented programming, it is good practice to write methods to implement the business logic. Methods allow us to break a complex task into simpler ones, with methods providing the implementation of the simpler ones. Since a method must implement logic, it needs input (usually, but not necessarily) and it produces output. The inputs to a method are supplied by itsparameters or arguments and the output is reflected in its return value. This is the syntax to declare a method in Java
[access] returnType methodName([arguments…]) {
//method body
}
For example to write a method that prints "HelloWorld", instead of writing the code in the main method,
we can create a method called printString that takes a String as argument and will print the argument.
This method returns nothing, so its return type is void.
void printString(String str){
System.out.println(str);
}
The advantage of this approach is that by changing the value passed as the argument, 
I can print any message I want. This is just a basic introduction to methods, we will see more about them
by and by.
Beginning Programming
Object Oriented Programming 
We write computer programs to solve problems and there are several programming paradigms. Object oriented programming is a popular, widely used and common one. Java is an object oriented programming language. In object oriented programming, we solve a problem by defining objects that interact with each other. This is an intuitive way to model real world problems since we see objects all around in the real world - cars, stars, flowers, rooms etc. An object oriented language therefore provides us with a mechanism to
  1. Define the behavior and properties of objects we want to define
  2. Set up objects of each kind and put them to work
Most object oriented languages including Java allow programmers to create classes to address the first point. A class is a template or blueprint to create objects. It  lets us define state and behavior for objects and allows us to create objects of that class.
  • State is defined by internal data - in Object Oriented terminology these are referred to as fields or attributes
  • Behaviour is determined by methods that we write to implement logic
  • New objects can be created using constructors
Java allows us to write code to create classes and define fields, methods and constructors.

Beginning Programming 
Lexical Components Of a Program
We have seen that a Java application resides in a class and at a minimum has a main method. The  method has statements that can be executed and produce the results we want. Let us now look at a few lexical conventions of Java. Our HelloWorld program uses some reserved words - public, class, static, void are some reserved words used here. This means that they have a specific meaning for the compiler and cannot be used for other purposes in the program. You can look up the complete list of reserved words in http://download.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
statement is the smallest unit that can be executed.
System.out.println("This is a statement"); //is a statement.
A statement must be terminated with a semi-colon. A block in a program is group of statements. Blocks are delimited by { }. Comments are informative statements written in a program and are ignored by the compiler. They are meant for people to understand the program. Here is the HelloWorld application interspersed with comments. You can run this program and see that the comments do not affect the execution of the program.
public class HelloWorld { //single line comment, start of block 1
/* An example of a multi-line comment.
 It spans two lines*/
public static void main(String[] args) {//single line comment, start of block 2
System.out.println("Hello World!"); //statement
  }//single line comment, end of block 2
}//single line comment, end of block 1The Java compiler is very strict about syntax, and any code with syntax errors will not even compile. 
A class definition must be within a block (delimited by { and } ). So must a method definition. 
Beginning Programming
Structure of a Programming 
Java is an object oriented programming language, so any program that you write must be inside a class. To quickly get started with running Java applications, there are three basic steps
1. Create a class
public class HelloWorld {

}
2. Create a main method inside the class
public class HelloWorld {
public static void main(String[ ] args) {
}}
3. Write the code for the logic
public class HelloWorld {
/* A program to display the message "Hello World" on standard output */
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
The code above is a complete program to print the message "Hello World". Copy paste the code into scratch pad and run it.

Beginning Programming

Introduction

In this course you will learn how to solve problems by writing computer programs using the Java programming language. Like natural languages, programming languages also have their grammar (syntax) and rules of usage. You will become familiar with the syntax and comfortable with problem solving by practicing in the scratch pad area. Let us get started by printing the message "Welcome to Java!" on the console. Type the following in the scratch pad and run it
System.out.println("Welcome to Java!");

The message Welcome to Java! appears on the output window.

System.out.println("Welcome to Java!"); is a Java statement. Write a  statement to print "Java is easy" and try it out on the scratch pad. System.out.print() is another command that can be used to print to the console, use it to print the message "Java is fun" on the scratch pad. Do you see the difference between System.out.println and System.out.print? In the latter command, there is no newline after the message you print, so the cursor remains on the same line. Java is case sensitive, so you must preserve the case rules expected. So, try the following in the scratchpad. Correct it to make it work. system.out.println("Case matters!");
Java is case sensitive

Friday 21 November 2014

What Is PHP?

PHP is officially known as PHP: Hypertext Preprocessor. It is a server-side scripting language often written in an HTML context. Unlike an ordinary HTML page, a PHP script is not sent directly to a client by the server; instead, it is parsed by the PHP engine. HTML elements in the script are left alone, but PHP code is interpreted and executed. PHP code in a script can query databases, create images, read and write files, talk to remote servers—the possibilities are endless. The output from PHP code is combined with the HTML in the script and the result sent to the user.

PHP is also installed as a command-line application, making it an excellent tool for scripting on a server. Many system administrators now use PHP for the sort of automation that has been traditionally handled by Perl or shell scripting.

Why Choose PHP?

There are some compelling reasons to work with PHP. For many projects, you will find that the production process is significantly faster than you might expect if you are used to working with other scripting languages. At Corrosive we work with both PHP and Java. We choose PHP when we want to see results quickly without sacrificing stability. As an open-source product, PHP is well supported by a talented production team and a committed user community. Furthermore, PHP can be run on all the major operating systems and with most servers.

Speed of Development

Because PHP allows you to separate HTML code from scripted elements, you will notice a significant decrease in development time on many projects. In many instances, you will be able to separate the coding stage of a project from the design and build stages. Not only can this make life easier for you as a programmer, but it also can remove obstacles that stand in the way of effective and flexible design.

PHP Is Open Source

To many people, open source simply means free, which is, of course, a benefit in itself.

Well-maintained open-source projects offer users additional benefits, though. You benefit from an accessible and committed community that offers a wealth of experience in the subject. Chances are that any problem you encounter in your coding can be answered swiftly and easily with a little research. If that fails, a question sent to a mailing list can yield an intelligent, authoritative response.

You also can be sure that bugs will be addressed as they are found, and that new features will be made available as the need is defined. You will not have to wait for the next commercial release before taking advantage of improvements.

There is no vested interest in a particular server product or operating system. You are free to make choices that suit your needs or those of your clients, secure that your code will run whatever you decide.

Performance

Because of the powerful Zend engine, PHP shows solid performance compared with other server scripting languages, such as ASP, Perl, and Java Servlets, in benchmark tests. To further improve performance, you can acquire a caching tool (Zend Accelerator) from http://www.zend.com/; it stores compiled code in memory, eliminating the overhead of parsing and interpreting source files for every request.

Portability

PHP is designed to run on many operating systems and to cooperate with many servers and databases. You can build for a Unix environment and shift your work to NT without a problem. You can test a project with Personal Web Server and install it on a Unix system running on PHP as an Apache module.

Data in GSM Networks

The Global System for Mobile Communication (GSM) is a multiservice cellular network. It provides not only voice service, but a good set of data services as well. This chapter describes the data services offered by a GSM network. It describes the data services before the advent of GPRS and EDGE.
The GSM data services can be categorized in terms of traffic, signaling, and broadcast channel data services. The GSM standard specifies data services on the traffic channel (TCH), which can be utilized by data applications such as fax and Internet service provider (ISP) connection. This is also referred to as circuit switched (CS) data service. The data service on a signaling channel is known as the point-to-point short message service (SMS). Using SMS, a subscriber sends or receives a short string of text (maximum 126 characters) using a signaling channel. There is another type of SMS service called SMS broadcast, which is the only broadcast channel data service. This service transports data on a specially defined broadcast channel to all the subscribers in a cell. The broadcast data applications, such as traffic reports and weather alerts, were anticipated to use this service, but it didn't get much attention in deployment from cellular service providers.

Installing Remote Desktop connection on non-XP systemsInstalling Remote Desktop connection on non-XP systems

Non-Windows XP systems can also access Windows systems running Windows Remote Desktop. The local system used to access the remote computer must have the remote connectivity client software installed. To install the required Terminal Services components:
  1. Insert a Windows XP Professional CD in the local system’s CD or DVD drive.
  2. From the resulting Welcome To Microsoft Windows XP screen, click Perform Additional Tasks.
  3. Click Setup Remote Desktop Connection from the What Do You Want To Do Screen.
  4. The InstallShield Wizard will open; click Next on the Welcome To The InstallShield Wizard for Remote Desktop Connection.
  5. Read and accept the license agreement and click Next.
  6. Enter the customer name and organization, and specify whether the desktop connection is to be available to all users or only the logged in user and click Next.
  7. Click Install.
  8. Click Finish.
The older Windows system can now open the Remote Desktop Connection menu by clicking Start | Programs | Accessories | Communications | Remote Desktop Connection or by opening a command prompt and typing mstsc.

What is a Firewall?

A firewall is a security device that can be a software program or a dedicated network appliance. The main purpose of a firewall is to separate a secure area from a less secure area and to control communications between the two. Firewalls can perform a variety of other functions, but are chiefly responsible for controlling inbound and outbound communications on anything from a single machine to an entire network.

What is Network Address Translation?

Network Address Translation (NAT) is the process where a network device, usually a firewall, assigns a public address to a computer (or group of computers) inside a private network. The main use of NAT is to limit the number of public IP addresses an organization or company must use, for both economy and security purposes.
The most common form of network translation involves a large private network using addresses in a private range (10.0.0.0 to 10.255.255.255, 172.16.0.0 to 172.31.255.255, or 192.168.0 0 to 192.168.255.255). The private addressing scheme works well for computers that only have to access resources inside the network, like workstations needing access to file servers and printers. Routers inside the private network can route traffic between private addresses with no trouble. However, to access resources outside the network, like the Internet, these computers have to have a public address in order for responses to their requests to return to them. This is where NAT comes into play.
Internet requests that require Network Address Translation (NAT) are quite complex but happen so rapidly that the end user rarely knows it has occurred. A workstation inside a network makes a request to a computer on the Internet. Routers within the network recognize that the request is not for a resource inside the network, so they send the request to the firewall. The firewall sees the request from the computer with the internal IP. It then makes the same request to the Internet using its own public address, and returns the response from the Internet resource to the computer inside the private network. From the perspective of the resource on the Internet, it is sending information to the address of the firewall. From the perspective of the workstation, it appears that communication is directly with the site on the Internet. When NAT is used in this way, all users inside the private network access the Internet have the same public IP address when they use the Internet. That means only one public addresses is needed for hundreds or even thousands of users.
Most modern firewalls are stateful - that is, they are able to set up the connection between the internal workstation and the Internet resource. They can keep track of the details of the connection, like ports, packet order, and the IP addresses involved. This is called keeping track of the state of the connection. In this way, they are able to keep track of the session composed of communication between the workstation and the firewall, and the firewall with the Internet. When the session ends, the firewall discards all of the information about the connection.
There are other uses for Network Address Translation (NAT) beyond simply allowing workstations with internal IP addresses to access the Internet. In large networks, some servers may act as Web servers and require access from the Internet. These servers are assigned public IP addresses on the firewall, allowing the public to access the servers only through that IP address. However, as an additional layer of security, the firewall acts as the intermediary between the outside world and the protected internal network. Additional rules can be added, including which ports can be accessed at that IP address. Using NAT in this way allows network engineers to more efficiently route internal network traffic to the same resources, and allow access to more ports, while restricting access at the firewall. It also allows detailed logging of communications between the network and the outside world.
Additionally, NAT can be used to allow selective access to the outside of the network, too. Workstations or other computers requiring special access outside the network can be assigned specific external IPs using NAT, allowing them to communicate with computers and applications that require a unique public IP address. Again, the firewall acts as the intermediary, and can control the session in both directions, restricting port access and protocols.
NAT is a very important aspect of firewall security. It conserves the number of public addresses used within an organization, and it allows for stricter control of access to resources on both sides of the firewall.