You are on page 1of 11

Khwaja Fareed University of Engineering and Information Technology

Department of Computer Engineering

Name: Muhammad Abubakar Registration# : SWEN19111090

Lab 01: Introduction and Installation to NetBeans Java

1: Objective:
 To familiarize with Java and NetBeans
 To learn installation of NetBeans
 Learn to create project and write basic code in Java
2: Java
Java is a high-level programming language originally developed by Sun Microsystems and
released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the
various versions of UNIX. The latest release of the Java Standard Edition is Java SE 8. Java is
guaranteed to be Write Once, Run Anywhere. Java is Platform Independent.
Java programming environment
 Java programming language
specification o Syntax of Java programs
o Defines different constructs and their semantics
 Java byte code: Intermediate representation for Java programs
 Java compiler: Transform Java programs into Java byte code
 Java interpreter: Read programs written in Java byte code and execute them
 Java virtual machine: Runtime system that provides various services to running programs
Java programming environment: Set of libraries that provide services such as GUI, data
structures, etc
Phases of a Java program

Manual Prepared By: Engr. Hussain Khan, Lab Engineer, Department of Computer Engineering
Java Source to Bytecode

Tools you will need to perform this lab are:-


 Linux 7.1 or Windows xp/7/8/10 operating system (We will be using Windows 10)
 Java JDK 8
 Microsoft Notepad/NetBeans/Eclipse or any other editor (We will be using NetBeans)
Installing Java JDK 8
Launch Java JDK 8 and install it on your machine by leaving options on default. Refer to below
figures for installation.
Installing NetBeans

To write your Java programs, you will need a text editor. There are even more sophisticated
IDEs available in the market. We will be using NetBeans in the lab. To install NetBeans you
can refer to following figures,
Creating Project in NetBeans

Create a Java project from File>New Project. Choose Java Application and click Next.

Enter Project Name. Leave everything by default for now. Make sure check box is tick for
“Create Main Class”. It will automatically a default project and java class in it.
And finally, this is your destination in which you are going to code wonders in this Intensive
Programming Lab.
Example 1
public class Practise1 {

public static void main(String[] args) { System.out.println("Hello Java World");


}

Basic Syntax
About Java programs, it is very important to keep in mind the following points.
Case Sensitivity − Java is case sensitive, which means identifier Hello and hello would have
different meaning in Java.
Class Names − For all class names the first letter should be in Upper Case. If several words are
used to form a name of the class, each inner word's first letter should be in Upper Case.
Example: class MyFirstJavaClass
Method Names − All method names should start with a Lower Case letter. If several words are
used to form the name of the method, then each inner word's first letter should be in Upper Case.
Example: public void myMethodName()
Program File Name − Name of the program file should exactly match the class name.
When saving the file, you should save it using the class name (Remember Java is case sensitive)
and append '.java' to the end of the name (if the file name and the class name do not match, your
program will not compile).
But please make a note that in case you do not have a public class present in the file then file
name can be different than class name. It is also not mandatory to have a public class in the
file.
Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as
'MyFirstJavaProgram.java'
public static void main(String args[]) − Java program processing starts from the main() method
which is a mandatory part of every Java program.
System.out.print: Prints information with no next line.
System.out.prinln: Prints a new line after printing information
3. Escape Sequences:-
A character preceded by a backslash (\) is an escape sequence and has a special meaning to the
compiler.

The newline character (\n) has been used frequently in this tutorial in System.out.println()
statements to advance to the next line after the string is printed.
Following table shows the Java escape sequences –

When an escape sequence is encountered in a print statement, the compiler interprets it


accordingly.
Example 2
public class Practise1 {

public static void main(String[] args) { System.out.println("Hello \n World");


}
}

4: Practice Exercise
Q1: Make a new project in NetBeans and run given example.
Q2: Write a Java program to display following output.
package myname;

public class Myname


{
public static void main(String[] args)
{
System.out.println("My Name is Muhammad Abubakar.");
System.out.println("My Registration Number is Swen-19111090.");
System.out.println("I am in Second semester of Software Engineering.");
}

This is the example of Code

You might also like