# Java programming

> Java course at Gurukul Technicals Institute: the JDK and JVM, data types, loops, arrays, strings, classes, inheritance, interfaces, exceptions, ArrayList…

Programming & Web Development

Object-oriented programming in Java, a language used widely in applications and in college syllabuses.

Suits: Students from class 10 onwards 7 lessons 35 practice questions 5 free ebooks

![Two students writing code together on a laptop and a desktop computer](https://engineergurukul.com/images/photos/coding-students-800.webp)

## At a glance

- **Suits**: Students from class 10 onwards
- **Study book**: 1
- **Lessons**: 7
- **Questions**: 35
- **Free ebooks**: 5

[Ask about fees and batches](https://wa.me/919711699511?text=Hello%20Gurukul%20Technicals%20Institute%2C%20I%20want%20to%20know%20about%20the%20Java%20course%3A%20duration%2C%20fees%2C%20batch%20timings%20and%20the%20nearest%20centre.)

[Call +91 97116 99511](tel:+919711699511)

Duration, fees and batch timings are quoted by the head office or your centre.

About the course

## What the Java course is about

Java is an object-oriented language used widely in applications and in college syllabuses. The study book follows Java 17, starting with how the JDK, JRE and JVM fit together and your first program.

It moves through data types, decisions and loops, arrays and strings, then classes, constructors, inheritance, interfaces and packages, and finishes with exceptions and the ArrayList and HashMap collections.

[All programming & web development courses](https://engineergurukul.com/courses/programming/)

### Who it suits

- Class 11 and 12 students with computer science
- BCA, BSc and engineering students with Java in their syllabus
- Learners who know some C and want object-oriented programming
- Anyone heading towards software development

### What you will practise

Drawn from the lessons of the study books below.

1. Install the JDK and write, compile and run a Java program
2. Use data types, variables, operators, decisions and loops
3. Work with arrays and the String class
4. Write classes with fields, methods and constructors
5. Organise code with inheritance, interfaces and packages
6. Handle exceptions and store data in ArrayList and HashMap

What you will learn

## 7 lessons, 21 exercises

Every lesson of the study book that comes with this course in the student portal, with the key points of each lesson and exercises to try. Your centre gives you the syllabus, the duration and the fee.

Study book

### Java

Learn Java 17 from the ground up: how the JDK, JRE and JVM fit together, data types, control flow, arrays, strings, classes, inheritance, interfaces, packages, exceptions and the ArrayList and HashMap collections.

7 lessons About 23 min of reading 35 practice questions 25 key terms

#### 01 The Java Platform and Your First Program 3 min read · 5 key points · 3 exercises

Key points

- javac compiles .java source into .class bytecode, and the JVM runs the bytecode.
- The JDK contains the JRE, and the JRE contains the JVM.
- The same bytecode runs on any operating system that has a JVM.
- A public class must be saved in a file with exactly the same name.
- In Java 17, execution starts at public static void main(String\[\] args).

Try this

1. Type the Hello program from this lesson with your own name, compile it with javac Hello.java and run it with java Hello, then list the files in the folder to find the Hello.class file that javac created.
2. Rename the class in Hello.java to Greeting without renaming the file, compile it, and copy the error message into your notebook; then fix it so that the file name and the public class name match exactly.
3. Open a command prompt and run java -version and javac -version to note the Java version installed, then write a program that prints your name, your course and today's date (typed in as text) on three lines with println, followed by one line built from two print calls.

#### 02 Data Types, Variables and Operators 4 min read · 5 key points · 3 exercises

Key points

- Java has eight primitive types, and each numeric type has the same size on every platform.
- Whole-number literals are int and decimal literals are double unless you add L or f.
- Narrowing conversions need a cast, which cuts off any fraction.
- Integer division drops the fraction: 10 / 4 is 2.
- Once a String is involved, + joins text from left to right.

Try this

1. Write a program that declares one variable of each of the eight primitive types with a sensible value, such as a long mobile number with the L suffix and a float rate with the f suffix, and prints them all; then remove the f from the float value and note the compiler error.
2. Write a program that works out simple interest on a principal of 1_00_000 rupees at 7.5 percent a year for 3 years using double variables and a final constant for the rate, and prints the interest and the total amount; check that the interest comes to 22500.0.
3. In your notebook, predict what System.out.println prints for 10 / 4, 10 / 4.0, 10 % 4, (int) 9.99, "Sum: " + 2 + 3 and 2 + 3 + " items", then print them all in a program and compare the results with your predictions.

#### 03 Control Flow: Decisions and Loops 3 min read · 5 key points · 3 exercises

Key points

- Scanner reads keyboard input with methods such as nextInt and nextLine.
- An if condition must be a boolean; an int is not accepted.
- A classic switch falls through without break; arrow-style switch expressions do not.
- switch cannot use long, float, double or boolean values.
- do-while always runs its body at least once.

Try this

1. Write a program that reads marks out of 100 with Scanner and prints a grade with an if, else if and else ladder, printing Invalid for any mark below 0 or above 100.
2. Write a program that reads a three-letter day name such as MON or SAT and uses an arrow-style switch expression to store Weekday or Weekend in a String; then rewrite it as a classic switch with break statements and check that both versions give the same answer for all seven days.
3. Write a program that reads whole numbers with nextInt inside a do-while loop until the user enters 0, and then prints how many numbers were entered (not counting the 0), their sum and the largest of them.

#### 04 Arrays and Strings 3 min read · 5 key points · 3 exercises

Key points

- An array has a fixed size, and its elements start at default values such as 0 or null.
- Use array.length (a field) for arrays and str.length() (a method) for strings.
- A bad index throws ArrayIndexOutOfBoundsException.
- Strings are immutable; compare their text with equals, not ==.
- Use StringBuilder to build a string from many pieces.

Try this

1. Store a week's daily sales in an int array, print the total and the daily average using an enhanced for loop, then sort the array with Arrays.sort, print it with Arrays.toString, and print the lowest and highest values from its first and last elements.
2. Write a program that reads a full name with nextLine and prints its length, the name in capital letters, its first character, the position of the first space found with indexOf, and the first name taken out with substring; if indexOf returns -1 because there is no space, print the whole name as the first name instead of calling substring, which would throw an exception.
3. Write a program that reads one word with next(), builds its reverse with a StringBuilder by appending characters from the last index to the first with charAt, and uses equalsIgnoreCase to report whether the word is a palindrome; test it with Malayalam and Delhi.

#### 05 Classes, Objects and Constructors 3 min read · 5 key points · 3 exercises

Key points

- A class defines fields and methods; new creates an object from it.
- Java supplies a default constructor only when a class declares none.
- this.field = parameter copies a constructor parameter into a field of the same name.
- A static field is shared by all objects of the class.
- Assigning an object variable copies the reference, not the object.

Try this

1. Write a class Book with private fields title, author and price, a constructor that uses this to copy its parameters into the fields, and a getter for each field, then create three Book objects in main and print their details.
2. Add a setter setPrice to your Book class that refuses a negative price and prints a message instead, and add a second constructor that takes only a title and calls the first one with this(...), passing Unknown as the author and 0 as the price.
3. Add a private static int counter to Book that goes up by one in the constructor and a static method that returns it, and print it after creating your books; then make two StringBuilder variables refer to the same object, change it through one and print it through the other.

#### 06 Inheritance, Interfaces and Packages 4 min read · 5 key points · 3 exercises

Key points

- extends inherits from one superclass; every class ultimately extends Object.
- In Java 17, super(...) must be the first statement of a subclass constructor.
- Use @Override so the compiler checks that a method really overrides.
- A class can implement many interfaces but extend only one class.
- java.lang is imported automatically; other packages need an import.

Try this

1. Type the Payroll program from this lesson, add a third subclass Intern that is paid a fixed stipend, and add one Intern to the staff array without changing the loop that prints the staff.
2. Write an interface Shape with a method double area(), implement it in classes Circle and Rectangle using @Override (declare each area() public, because interface methods are public and a class cannot make them less accessible), store one of each in a Shape array and print every area in a loop; then misspell area in one class and note what the @Override annotation makes the compiler report.
3. Create a folder named billing containing a public class Invoice whose first line is package billing; and give it one public method and one method with no access modifier; then use Invoice from a class outside the folder with import billing.Invoice; compile both from the folder above billing, and note which of the two methods you can call.

#### 07 Exceptions and Collections 3 min read · 5 key points · 3 exercises

Key points

- Code that may fail goes in try; catch blocks handle specific exception types.
- finally runs whether or not an exception was thrown.
- Checked exceptions such as IOException must be caught or declared with throws.
- ArrayList is a resizable, ordered list that allows duplicates.
- HashMap keys are unique: put with an existing key replaces its value.

Try this

1. Write a program that reads two values as text, converts them with Integer.parseInt and divides the first by the second inside try, with separate catch blocks for NumberFormatException and ArithmeticException and a finally block that prints Done; test it with 20 and 4, 20 and 0, and 20 and abc.
2. Write a method withdraw(double amount) that throws an IllegalArgumentException with a clear message when the amount is zero or negative, call it from main inside try with one valid and one negative amount, and print the message in the catch block with getMessage().
3. Write a shopping-list program that adds five items to an ArrayList of String, removes one, uses contains to check whether Milk is on the list and prints the size; then store each item's price in a HashMap of String to Integer and print the total bill using getOrDefault.

**Glossary: 25 key terms of Java**

- **Abstract class**: A class declared with the keyword abstract that cannot be instantiated and may contain abstract methods without a body, which its concrete subclasses must implement.
- **ArrayList**: A resizable list class in java.util that keeps its elements in insertion order, allows duplicates and grows automatically as items are added.
- **Autoboxing**: Java's automatic conversion of a primitive value such as an int into an object of its wrapper class such as Integer, which lets collections like ArrayList hold numbers; the reverse conversion, from Integer back to int, is called unboxing.
- **Bytecode**: The instructions in a .class file produced by javac, which are not tied to any particular processor and are run by the Java Virtual Machine.
- **Checked exception**: An exception such as IOException that the compiler forces you either to catch or to declare in the method header with throws.
- **Class**: A blueprint that describes the fields an object holds and the methods it provides, from which objects are created with new.
- **Constructor**: A special block of code with the same name as its class and no return type that sets up a new object when it is created with new.
- **Encapsulation**: Keeping a class's fields private and allowing access only through public methods such as getters and setters, so that the class controls every change to its data.
- **final**: A keyword that stops a variable from being assigned a new value once it has one (for an object variable the reference is fixed, though the object itself may still change), stops a method from being overridden, or stops a class from being extended.
- **Garbage collector**: The part of the JVM that automatically frees the memory of objects the program can no longer reach, for example because no variable refers to them any more, which is why Java has no free or delete.
- **HashMap**: A collection class in java.util that stores key and value pairs with unique keys and keeps them in no particular order.
- **Immutable**: Describes an object whose contents cannot change after it is created, such as a String, whose methods return new strings instead of changing the original.
- **Inheritance**: The feature that lets a subclass take on the fields and methods of a superclass using the keyword extends; a Java class can extend only one class.
- **Interface**: A contract listing methods that a class promises to provide, which a class adopts with the keyword implements; one class can implement many interfaces.
- **JDK**: The Java Development Kit, which contains everything needed to run Java programs plus development tools such as the javac compiler, jar and javadoc.
- **JRE**: The Java Runtime Environment, made up of the JVM and the standard class libraries, which is enough to run Java programs but not to compile them; in current versions it usually comes as part of the JDK.
- **JVM**: The Java Virtual Machine, the program that runs bytecode on a particular operating system and manages memory, which lets the same .class file run on Windows, Linux and macOS.
- **Method overriding**: Redefining, in a subclass, a method inherited from its superclass with the same name and parameters, usually marked with @Override so that the compiler checks it.
- **Object**: One instance of a class, created with new, that has its own copy of the class's instance fields.
- **Package**: A named group of related classes, declared with a package statement at the top of each file, whose classes are used from other packages through import.
- **Primitive type**: One of Java's eight built-in basic types, byte, short, int, long, float, double, char and boolean, whose numeric sizes are fixed by the language on every platform.
- **Reference type**: Any type that is not primitive, such as String, arrays and your own classes, whose variables hold a reference to an object or the value null.
- **static**: A keyword marking a field or method that belongs to the class itself rather than to any one object, so a static field is shared by all objects of that class.
- **StringBuilder**: A class that holds a changeable sequence of characters and is used to build a string efficiently from many pieces, for example inside a loop.
- **Unchecked exception**: An exception that is a subclass of RuntimeException, such as NullPointerException or ArithmeticException, which usually signals a bug and need not be caught or declared.

Practice and study material

## Study books and timed practice tests in the student portal

Students sign in to read the study books lesson by lesson, print them, mark lessons as done and test themselves with timed practice tests, every answer explained.

**1** study book **7** lessons **35** practice questions **25** glossary terms

### How the practice tests work

- **Fresh questions each time**

  Up to 20 questions are picked at random from the subject’s question bank.
- **One minute per question**

  A timer counts down. When it reaches zero, your answers are sent automatically.
- **Move around freely**

  Skip a question, flag it, and come back to change your answer before you submit.
- **Learn from every answer**

  At the end you see the right answer and an explanation for each question.
- **Read, print and keep track**

  Each study book has its lessons, key points, exercises and a glossary. Print a lesson, or mark it as done.

[Student login](https://engineergurukul.com/student/login/) Your centre gives you your login when you enrol.

### Try 3 practice questions

Real questions from this course’s question banks. Pick an answer to see the explanation.

1. Java · Question 1

   What does System.out.println("Sum: " + 2 + 3); print?

   **Show the answer**

   **Answer: A. Sum: 23**

   \+ is evaluated left to right; "Sum: " + 2 gives the text "Sum: 2", and adding 3 joins another character to it.
2. Java · Question 2

   Why should strings be compared with equals() rather than ==?

   **Show the answer**

   **Answer: C. == checks whether both variables refer to the same object, while equals() compares the characters**

   Two different String objects can hold the same text, and only equals() compares the text itself.
3. Java · Question 3

   From where can a field with no access modifier (package-private) be accessed?

   **Show the answer**

   **Answer: A. Only from classes in the same package**

   With no modifier, access is limited to the package; protected adds subclasses in other packages, and public opens it to all.

Free ebooks

## 5 free ebooks for this course

Branded PDF books to read on your phone or print: the study books of this course and more. Free for anyone, no sign-in needed.

Programming

### [Java Study Book](https://engineergurukul.com/resources/ebooks/java-study-book/)

The complete study notes, practice questions and glossary for Java

- Beginner
- 29 pages
- 135 KB

[Download PDF: Java Study Book](https://engineergurukul.com/ebooks/java-study-book.pdf) [Details of Java Study Book](https://engineergurukul.com/resources/ebooks/java-study-book/)

Programming

### [Python for Beginners](https://engineergurukul.com/resources/ebooks/python-for-beginners/)

Learn to program with Python 3, one small program at a time

- Beginner
- 28 pages
- 138 KB

[Download PDF: Python for Beginners](https://engineergurukul.com/ebooks/python-for-beginners.pdf) [Details of Python for Beginners](https://engineergurukul.com/resources/ebooks/python-for-beginners/)

Programming

### [Java Practice Programs](https://engineergurukul.com/resources/ebooks/java-practice-programs/)

Core Java concepts with twenty-four programs you can run

- Beginner to intermediate
- 28 pages
- 129 KB

[Download PDF: Java Practice Programs](https://engineergurukul.com/ebooks/java-practice-programs.pdf) [Details of Java Practice Programs](https://engineergurukul.com/resources/ebooks/java-practice-programs/)

Programming

### [Flowcharts, Algorithms and Logic Building](https://engineergurukul.com/resources/ebooks/flowcharts-and-algorithms/)

Think like a programmer before you write any code

- Beginner
- 27 pages
- 120 KB

[Download PDF: Flowcharts, Algorithms and Logic Building](https://engineergurukul.com/ebooks/flowcharts-and-algorithms.pdf) [Details of Flowcharts, Algorithms and Logic Building](https://engineergurukul.com/resources/ebooks/flowcharts-and-algorithms/)

Programming

### [Data Structures Made Simple](https://engineergurukul.com/resources/ebooks/data-structures-basics/)

Arrays, stacks, queues, linked lists, trees and graphs with everyday examples

- Intermediate
- 29 pages
- 118 KB

[Download PDF: Data Structures Made Simple](https://engineergurukul.com/ebooks/data-structures-basics.pdf) [Details of Data Structures Made Simple](https://engineergurukul.com/resources/ebooks/data-structures-basics/)

[Browse all 100 free ebooks](https://engineergurukul.com/resources/ebooks/)

Careers

## Careers this course leads towards

The kind of work these skills are used for. Each guide explains what the job involves, the skills it asks for and how to get started.

### [Software developer](https://engineergurukul.com/resources/careers/software-developer/)

Writing, testing and fixing programs in languages such as C, C++, Java and Python.

### [Web developer](https://engineergurukul.com/resources/careers/web-developer/)

Building and updating websites with HTML, CSS and JavaScript, and connecting them to data.

How admission works

## From your first question to your certificate.

The usual steps, at the head office in Delhi or at an authorised member centre.

- **Who can join**: Students above 12 years of age.
- **Where**: The Delhi head office and authorised member centres.
- **Fees and timings**: Call or WhatsApp +91 97116 99511.

### 1. Ask about the course

Call or WhatsApp the head office, or visit your nearest member centre. Ask for the duration, the fee and the batch timings in writing. Still comparing institutes? Read [how to choose a computer training institute](https://engineergurukul.com/computer-training-institutes/).

### 2. Fill the admission form

Admission forms are supplied by the head office to every centre.

### 3. Learn in class

Attend your batch at the centre, with the course material and study notes, and sign in to the student portal for the study books and practice tests.

### 4. Take the exam

The institute prefers written exams, taken in front of a teacher.

### 5. Receive your certificate

Students who pass get a Gurukul Technicals Institute certificate and marksheet. Employers can [verify it with the head office](https://engineergurukul.com/verify-certificate/).

[Start with a question on WhatsApp](https://wa.me/919711699511?text=Hello%20Gurukul%20Technicals%20Institute%2C%20I%20want%20to%20know%20about%20the%20Java%20course%3A%20duration%2C%20fees%2C%20batch%20timings%20and%20the%20nearest%20centre.)

Related courses

## More programming & web development courses

[Programming & Web Development](https://engineergurukul.com/courses/programming/)

### [C and C++](https://engineergurukul.com/courses/programming/c-cpp/)

The languages most students learn first: variables, loops and functions, and in C++, classes and objects.

2 study books 14 lessons

### [Web design](https://engineergurukul.com/courses/programming/web-design/)

Building web pages with HTML and giving them a layout and style.

1 study book 7 lessons

### [Python](https://engineergurukul.com/courses/programming/python/)

A first programming language with plain, readable code: variables, decisions, loops, lists, functions and small projects.

1 study book 11 lessons

### [JavaScript](https://engineergurukul.com/courses/programming/javascript-web/)

Making a web page respond to clicks and typing: variables, functions, the page structure (the DOM), events and forms.

2 study books 17 lessons

### [WordPress](https://engineergurukul.com/courses/programming/wordpress/)

Building a website without writing code: pages, posts, menus, themes, plugins, images, forms and keeping the site safe and up to date.

2 study books 17 lessons

### [App Inventor](https://engineergurukul.com/courses/programming/app-inventor/)

Making Android apps by snapping blocks together: screens, buttons, text and images, sensors, lists and saving data on the phone.

1 study book 10 lessons

### [IT programme](https://engineergurukul.com/courses/programming/it-diploma/)

Programmes for class 10 pass students, over 6 months or 1 year.

4 study books 28 lessons

Questions

## Questions about the Java course

### Who can join the Java course?

Students above 12 years of age can take admission, at the Delhi head office or at an authorised member centre. The course suits students from class 10 onwards. Tell the head office or your centre what you already know, and they will suggest where to start.

### How long is the course and what is the fee?

Duration, fees and batch timings depend on the course and the centre. Ask the head office or your nearest member centre, and get the details in writing before you pay.

### Where are the classes?

At the head office in Delhi (A-10, Chief Commissioner Colony, opposite Rana Pratap Bagh) and at authorised member centres. Call or WhatsApp the head office to find the nearest centre.

### What do I need to use the study books and practice tests?

A phone or a computer with an internet connection, and the login your centre gives you at enrolment. The student portal opens in an ordinary web browser, so there is nothing to install. [Student login](https://engineergurukul.com/student/login/).

### How do the practice tests work?

Sign in to the student portal and choose a subject. Each test picks up to 20 questions at random from that subject’s question bank and gives you one minute per question, with a timer that sends your answers automatically when it reaches zero. You can skip a question, flag it and come back before you submit, and at the end you see the right answer and an explanation for every question. This course has 35 practice questions across 1 subject, and you can take the tests as often as you like.

### Is there an exam and a certificate?

Yes. The institute prefers written exams, taken in front of a teacher. Students who pass receive a Gurukul Technicals Institute certificate and marksheet.

### How is a Gurukul Technicals Institute certificate verified?

On the [verify certificate page](https://engineergurukul.com/verify-certificate/), anyone can enter a certificate number and check it against the institute’s online register, which covers certificates issued through the portal. For older certificates, or if there is any doubt, send a copy to the head office by email or WhatsApp; the reply comes within 2 working days. For a certificate from a free course elsewhere, [how to judge a free certificate offer](https://engineergurukul.com/free-courses-with-free-certificate/) shows what to check.

### Are the ebooks on this page really free?

Yes. The 5 ebooks for this course are free PDF downloads for anyone, whether or not you join. The whole library has 100 free ebooks: [browse them all](https://engineergurukul.com/resources/ebooks/).

Still have a question? [Chat on WhatsApp](https://wa.me/919711699511?text=Hello%20Gurukul%20Technicals%20Institute%2C%20I%20want%20to%20know%20about%20the%20Java%20course%3A%20duration%2C%20fees%2C%20batch%20timings%20and%20the%20nearest%20centre.)

## Ready to start the Java course?

Ask the head office for the duration, the fee, the batch timings and your nearest member centre.

[WhatsApp +91 97116 99511](https://wa.me/919711699511?text=Hello%20Gurukul%20Technicals%20Institute%2C%20I%20want%20to%20know%20about%20the%20Java%20course%3A%20duration%2C%20fees%2C%20batch%20timings%20and%20the%20nearest%20centre.) [Call +91 97116 99511](tel:+919711699511)

---

Canonical URL: https://engineergurukul.com/courses/programming/java/
