C C++ and Java Program in Linux and Lamp Server Installation

C C++ and Java Program in Linux and Lamp Server Installation

7.How to install GCC (C/C++) Compiler in Linux Create a sample C program then compile and execute the code.
bz@PC:~$ sudo apt install gcc
bz@PC:~$ sudo apt install build-essential
bz@PC:~$ gcc –version
C Program
Write the following code using any text editor and save the file with the extension ‘.c’.
#include <stdio.h>
int main()
printf(“Learning C in Linux Kernal”);
To compile and execute the code. The source file name is first.c and executable filename is first here.
$ gcc first.c -o first
$ ./first
Learning C in Linux Kernal
#include <stdio.h>
int main()
char name[100];
int age;
printf(“Enter your Name: “);
printf(“Enter your Age: “);
printf(“Hello, %s,You are %d years old”, name, age);
#include <stdio.h>
int main(int argc,char* argv[]){
printf(“Total number of Arguments = %d\n”,argc);
printf(“Argument No. 1 = %s\n”,argv[0]);
printf(“Argument No. 2 = %s\n”,argv[1]);
printf(“Argument No. 3 = %s\n”,argv[2]);
8. Create a sample C++ program then compile and execute the code.
Write the following code using any text editor and save the file with the extension ‘.cpp’
bz@PC:~$ sudo nano hello.cpp

#include <iostream>
using namespace std;
int main()
cout<<“Hello World!” <<endl;
return 0;

bz@PC:~$ g++ hello.cpp
user@PC:~$ ./a.out
Hello World!
bz@PC:~$ g++ hello.cpp -o hello
Hello World!
#include <bits/stdc++.h>
using namespace std;
class Gyancs
// Access specifier
// Data Members
string csname;
// Member Functions()
void printname()
cout<< “Csname is: “<<csname;
int main() {
// Declare an object of class Gyancs
Gyancs obj1;
// accessing data member
obj1.csname = “Open Source”;
// accessing member function
Csname is: Open Source

9. How to install Java in Linux Creating a sample java Program.

bz@PC:~$ sudo apt install openjdk-8-jdk
bz@PC:~$ sudo nano /etc/environment


Java Programming in Linux
Write the following code using any text editor and save the file with the extension ‘.java’
bz@PC:~$ sudo nano Simple.java
class Simple{
public static void main(String args[]){
System.out.println(“Hello Java”);
bz@PC:~$ javac Simple.java
bz@PC:~$ java Simple
Hello Java
bz@PC:~$ sudo nano Student.java
public class Student {
public static void main(String[] args) {
int x=10;
int y=12;
if(x+y> 20)
System.out.println(“x+y is Greater Than 20”);

bz@PC:~$ javac Student.java
user@PC:~$ java Student
x+y is Greater Than 20
10.How To Install Linux, Apache, MySQL, PHP (LAMP)
Step 1: Install Apache
bz@PC:~$ sudo apt-get update
bz@PC:~$ sudo apt-get install apache2
Step 2: Install MySQL
bz@PC:~$ sudo apt-get install mysql-server
Finish up by running the MySQL set up script:
bz@PC:~$ sudo /usr/bin/mysql_secure_installation

Press y|Y for Yes, any other key for No: yes

There are three levels of password validation policy:

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
The prompt will ask you for your current root password.
Type it in.0
Enter current password for root (enter for none):

OK, successfully used password, moving on…
Step 3: Install PHP
bz@PC:~$ sudo apt-get install php
may also be useful to add php to the directory index, to serve the relevant php index files:
bz@PC:~$ sudo nano /etc/apache2/mods-enabled/dir.conf
Add index.php to the beginning of index files. The page should now look like this:
DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm

Note: Green place is add index.php, Strikethrough is remove it there.

PHP Modules
bz@PC:~$ apt-cache search php
Step 4: RESULTS — See PHP on your Server
To set this up, first create a new file:
bz@PC:~$ sudo nano /var/www/html/info.php
Add in the following line:
Then Save and Exit.
Restart apache so that all of the changes take effect:
bz@PC:~$ sudo service apache2 restart
How to Find your Server’s IP address
bz@PC:~$ sudo ifconfig
The address you want to visit will be:

Start the Command-line tool MySql and select a database:

bz@PC:~$sudo mysql -u root -p
[sudo] password for user:
Enter password:


bz@PC:~$sudo mysql -u root
[sudo] password for user:

mysql>use mysql;
mysql>show tables;

To create and populate the example table, use these statements:
mysql>CREATE TABLE item (
PRIMARYKEY(article, dealer));
mysql>DESCRIBE item;

After issuing the statements, the table should have the following contents:

mysql>SELECT*FROM item ORDERBY article;

| article | dealer | price |
|       1 | A      |  3.45 |
|       1 | B      |  3.99 |
|       2 | A      | 10.99 |
|       3 | B      |  1.45 |
|       3 | C      |  1.69 |
|       3 | D      |  1.25 |
|       4 | D      | 19.95 |

Theory Question:

  1. What is the difference between Linux and Unix?
  2. What are the Features of the Linux Operating System?
  3. What is Linux Kernel?
  4. How many types of Shells are there in Linux? explain.
  5. Explain File Permissions types in Linux?
  6. What are the symbolic links?
  7. Explain about chmod command?
  8. Where is password file located in Linux and how can you improve the security of password file?
  9. How do you create a new user account and set the password for a user from a shell prompt in Linux?
  10. What are the different types of Kernels? Explain

Open Source Software Lab Manual

About me