Every week you will be set a number of programming tasks that you are required to complete. The best way to learn a language like Java is to use it, and these exercises get you started on that process. Along the way, you will gain a better understanding of the concepts of imperative and object oriented programming.
The exercises will start off simple, building on the lecture material, but will become progressively more complex each week. They are designed so that the later exercises build on the knowledge you gained from the previous ones. Read the whole of an exercise before starting it to ensure you fully understand what is required.
For the first week, we will start off with some very basic programs to give you an idea of where to start. This includes:
Printing text to the console;
printing default values of primitive data types;
performing simple arithmetic.
We are going to proceed on the assumption that you already know a fair bit about about functions, types and return values from your experience with c. Although there are some differences with Java, these shouldn’t matter too much at this stage.
Lab Task 1
Write an application, HelloWorldApp, which will simply display the greeting "Hello world!" on console. To create this program, you will have to do:
1. Create a source file
2. Compile the source file into a .class file
3. Run the program
Save the code in a file with the name HelloWorldApp.java. To do this in Notepad, first choose the File > Save As menu item. Then, in the Save As dialog box:
Using the Save in combo box, specify the folder (directory) where you'll save your file. In this example, the directory is java on the C drive.
In the File name text field, type "HelloWorldApp.java", including the quotation marks.
From the Save as type combo box, choose Text Documents (*.txt).
In the Encoding combo box, leave the encoding as ANSI.
Output
Hello world!
Lab Task 2
To Review previous Lab Work Write java code that displays the following output.
Output:
Welcome
to
Java
Programming!
Write a Java application that prints default values all primitive data types.
What are primitive data types in Java? Well, you remember us talking about data types and Object Oriented programming right? Well, in Java, primitives are data types and have nothing to do with Object Oriented programming!
In Java, everything “extends” from Objects, except primitive data types. Think of primitives like the building blocks from which programming languages are built.
Output
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
boolean false
For submission please Join class:
https://www.turnitin.com
class: DDP-SP13-BCE-A
class ID : 7666382
Enrollment Password: 12lahore
class: DDP-SP13-BEE-A (Object Oriented Programing)
class ID: 7666402
Enrollment Password: 12lahore