Programming Lab 1 : Introduction to Java


CSCI-UA 9102, Data Structures

 
A. Getting started

In this first part, we will set up your computers to use Java. A first important tool to have whenever you start coding is a good text editor. A good choice is sublime text


A.1. If you are on Windows, follow the instructions below Once you are done with the Java installation, proceed through the following steps to install git: A.2. If you are on Mac, follow the instructions below.
B. A couple more steps..

Now that you are set up with Java and git, you will learn how to get access to the labs through github. If you do not already have one, start by opening a github account. You might also want to check that your git installation was done correctly by typing the following command

$ git --version
C. Exercise 1

In this first part, we will review the basic concepts of Java (including classes and objects, constructors, the main method, strings,…)

Exercise 1.1.

In this first part, we will review the basic concepts of Java (including classes and objects, constructors, the main method, strings,…)

  • Write a short java method that counts the number of vowels in any given string

  • Write a short java method that takes an integer n and returns the sum of the squares of all positive integers less than or equal to n

  • Write a short java method that takes an integer n and returns the sum of the squares of all the odd positive integers less than or equal to n

Exercise 1.2.


  • Write a public class with public constructor but a static variable. Then create several object of this class and modify the variables through the different objects. Print the resulting value after each modification.