• Java Arrays
  • Java Strings
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Spring Boot
  • Java Exercises - Basic to Advanced Java Practice Set with Solutions

1. Write Hello World Program in Java

2. write a program in java to add two numbers., 3. write a program to swap two numbers, 4. write a java program to convert integer numbers and binary numbers..

  • 5. Write a Program to Find Factorial of a Number in Java
  • 6. Write a Java Program to Add two Complex Numbers

7. Write a Program to Calculate Simple Interest in Java

  • 8. Write a Program to Print the Pascal’s Triangle in Java

9. Write a Program to Find Sum of Fibonacci Series Number

10. write a program to print pyramid number pattern in java., 11. write a java program to print pattern., 12. write a java program to print pattern., 13. java program to print patterns., 14. write a java program to compute the sum of array elements., 15. write a java program to find the largest element in array, 16. write java program to find the tranpose of matrix, 17. java array program for array rotation, 18. java array program to remove duplicate elements from an array, 19. java array program to remove all occurrences of an element in an array, 20. java program to check whether a string is a palindrome, 21. java string program to check anagram, 22. java string program to reverse a string, 23. java string program to remove leading zeros, 24. write a java program for linear search., 25. write a binary search program in java., 26. java program for bubble sort..

  • 27. Write a Program for Insertion Sort in Java

28. Java Program for Selection Sort.

29. java program for merge sort., 30. java program for quicksort., java exercises – basic to advanced java practice programs with solutions.

Looking for Java exercises to test your Java skills, then explore our topic-wise Java practice exercises? Here you will get 25 plus practice problems that help to upscale your Java skills.

As we know Java is one of the most popular languages because of its robust and secure nature. But, programmers often find it difficult to find a platform for Java Practice Online. In this article, we have provided Java Practice Programs. That covers various Java Core Topics that can help users with Java Practice.

So, with ado further take a look at our free Java Exercises to practice and develop your Java programming skills. Our Java programming exercises Practice Questions from all the major topics like loops, object-oriented programming, exception handling, and many more.

Topic Wise Java Exercises List

  • Pattern Programs in Java
  • Array Programs in Java
  • String Programs in Java

Java Practice Problems for Searching Algorithms

Practice problems in java sorting algorithms, more java practice exercises.

Java Exercise

Java Practice Programs

This Java exercise is designed to deepen your understanding and refine your Java coding skills, these programs offer hands-on experience in solving real-world problems, reinforcing key concepts, and mastering Java programming fundamentals. Whether you’re a beginner who looking to build a solid foundation or a professional developer aiming to sharpen your expertise, our Java practice programs provide an invaluable opportunity to sharpen your craft and excel in Java programming language .

The solution to the Problem is mentioned below:

Click Here for the Solution

5. write a program to find factorial of a number in java., 6. write a java program to add two complex numbers., 8. write a program to print the pascal’s triangle in java, java exercise on pattern.

Pattern Exercises in Java

Array Exercises in Java

Array Exercises in Java

String Exercises in Java

Strings Exercises in Java

Time Complexity: O(N) Space Complexity: O(N)
Time Complexity: O(logN) Space Complexity: O(N)

Sorting_in_java

Time Complexity: O(N 2 ) Space Complexity: O(1)

27. Write a Program for Insertion Sort in Java.

Time Complexity: O(N logN) Space Complexity: O(N)
Time Complexity: O(N logN) Space Complexity: O(1)

After completing these Java exercises you are a step closer to becoming an advanced Java programmer. We hope these exercises have helped you understand Java better and you can solve beginner to advanced-level questions on Java programming.

Solving these Java programming exercise questions will not only help you master theory concepts but also grasp their practical applications, which is very useful in job interviews.

Java Array Exercise Java String Exercise Java Collection Exercise Click Here – To Practice Java Online please check our Practice Portal.

Java Exercise – FAQ

1. how to do java projects for beginners.

To do Java projects you need to know the fundamentals of Java programming. Then you need to select the desired Java project you want to work on. Plan and execute the code to finish the project. Some beginner-level Java projects include: Reversing a String Number Guessing Game Creating a Calculator Simple Banking Application Basic Android Application

2. Is Java easy for beginners?

As a programming language, Java is considered moderately easy to learn. It is unique from other languages due to its lengthy syntax. As a beginner, you can learn beginner to advanced Java in 6 to 18 months.

3. Why Java is used?

Java provides many advantages and uses, some of which are: Platform-independent Robust and secure Object-oriented Popular & in-demand Vast ecosystem

Please Login to comment...

Similar reads.

  • Java-Arrays
  • java-basics
  • Java-Data Types
  • Java-Functions
  • Java-Library
  • Java-Object Oriented
  • Java-Output
  • Java-Strings
  • Output of Java Program

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

  • ▼Java Exercises
  • Basic Part-I
  • Basic Part-II
  • Conditional Statement
  • Recursive Methods
  • Java Enum Types
  • Exception Handling
  • Java Inheritance
  • Java Abstract Classes
  • Java Thread
  • Java Multithreading
  • Java Lambda expression
  • Java Generic Method
  • Object-Oriented Programming
  • Java Interface
  • Java Encapsulation
  • Java Polymorphism
  • File Input-Output
  • Regular Expression
  • ▼JavaFx Exercises
  • JavaFx Exercises Home
  • ..More to come..

Java Programming Exercises, Practice, Solution

Java exercises.

Java is the foundation for virtually every type of networked application and is the global standard for developing and delivering embedded and mobile applications, games, Web-based content, and enterprise software. With more than 9 million developers worldwide, Java enables you to efficiently develop, deploy and use exciting applications and services.

The best way we learn anything is by practice and exercise questions. Here you have the opportunity to practice the Java programming language concepts by solving the exercises starting from basic to more complex exercises. A sample solution is provided for each exercise. It is recommended to do these exercises by yourself first before checking the solution.

Hope, these exercises help you to improve your Java programming coding skills. Currently, following sections are available, we are working hard to add more exercises .... Happy Coding!

List of Java Exercises:

  • Basic Exercises Part-I [ 150 Exercises with Solution ]
  • Basic Exercises Part-II [ 99 Exercises with Solution ]
  • Methods [ 23 Exercises with Solution ]
  • Data Types Exercises [ 15 Exercises with Solution ]
  • Java Enum Types Exercises [ 5 Exercises with Solution ]
  • Conditional Statement Exercises [ 32 Exercises with Solution ]
  • Java recursive method Exercises [ 15 Exercises with Solution ]
  • Math [ 27 Exercises with Solution ]
  • Numbers [ 28 Exercises with Solution ]
  • Java Inheritance Exercises [ 9 exercises with solution ]
  • Java Abstract Classes Exercises [ 12 exercises with solution ]
  • Java Interface Exercises [ 11 exercises with solution ]
  • Java Encapsulation Exercises [ 7 exercises with solution ]
  • Java Polymorphism Exercises [ 12 exercises with solution ]
  • Object-Oriented Programming [ 30 Exercises with Solution ]
  • Exercises on handling and managing exceptions in Java [ 7 Exercises with Solution ]
  • Java Lambda expression Exercises [ 25 exercises with solution ]
  • Streams [ 8 Exercises with Solution ]
  • Java Thread Exercises [ 7 exercises with solution ]
  • Java Miltithreading Exercises [ 10 exercises with solution ]
  • Array [ 77 Exercises with Solution ]
  • Stack [ 29 Exercises with Solution ]
  • Collection [ 126 Exercises with Solution ]
  • String [ 107 Exercises with Solution ]
  • Input-Output-File-System [ 18 Exercises with Solution ]
  • Date Time [ 44 Exercises with Solution ]
  • Java Generic Methods [ 7 exercises with solution ]
  • Java Unit Test [ 10 Exercises with Solution ]
  • Search [ 7 Exercises with Solution ]
  • Sorting [ 19 Exercises with Solution ]
  • Regular Expression [ 30 Exercises with Solution ]
  • JavaFX [ 70 Exercises with Solution ]

Note: If you are not habituated with Java programming you can learn from the following :

  • Java Programming Language

More to Come !

Popularity of Programming Language Worldwide, Nov 2023 compared to a year ago:

`
Rank Change Language Share Trend
1 Python 27.99 % +0.0 %
2 Java 15.91 % -0.8%
3 Javascript 9.18 % -0.3%
4 C/C++ 6.76 % +0.2%
5 C# 6.67 % -0.3 %
6 PHP 4.86 % -0.3 %
7 R 4.45% +0.4%
8 TypeScript 2.95 % +0.1%
9 Swift 2.7 % +0.6%
10 Objective-C 2.32% +0.2%
11 Rust1.98% +0.3%
12 Go 1.98% -0.0%
13 Kotlin 1.76 % -0.1%
14 Matlab 1.6 % +0.0%
15 Ada 1.02% +0.2%
16 Ruby 1.0 % -0.1 %
17 Dart 0.99 % +0.1 %
18 Powershell 0.93 % +0.0 %
19 VBA 0.93 % -0.1 %
20 Scala 0.62 % -0.1 %
21 Lua 0.62 % 0.0 %
22 Abap 0.58 % +0.1 %
23 Visual Basic 0.55 % -0.1 %
24 Julia 0.35 % -0.0 %
25 Groovy 0.31 % -0.1 %
26 Perl 0.31 % -0.1 %
27 Haskell 0.27 % -0.0 %
28 Cobol 0.25 % -0.1 %
29 Delphi/Pascal 0.18 % +0.2 %

Source : https://pypl.github.io/PYPL.html

TIOBE Index for November 2023

Nov 2023 Nov 2022 Change Programming Language Ratings Change
1 1 Python 14.16% -3.02%
2 2 C 11.77% -3.31%
3 4 C++ 10.36% -0.39%
4 3 Java 8.35% -3.63%
5 5 C# 7.65% +3.40%
6 7 JavaScript 3.21% +0.47%
7 10 PHP 2.30% +0.61%
8 6 Visual Basic 2.10% -2.01%
9 9 SQL 1.88% +0.07%
10 8 Assembly language 1.35% -0.83%
11 17 Scratch 1.31% +0.43%
12 24 Fortran 1.30% +0.74%
13 11 Go 1.19% +0.05%
14 15 MATLAB 1.15% +0.14%
15 28 Kotlin 1.15% +0.68%
16 14 Delphi/Object Pascal 1.14% +0.07%
17 18 Swift 1.04% +0.17%
18 19 Ruby 0.99% +0.14%
19 12 R 0.93% -0.20%
20 20 Rust 0.91% +0.16%

Source : https://www.tiobe.com/tiobe-index/

List of Exercises with Solutions :

  • HTML CSS Exercises, Practice, Solution
  • JavaScript Exercises, Practice, Solution
  • jQuery Exercises, Practice, Solution
  • jQuery-UI Exercises, Practice, Solution
  • CoffeeScript Exercises, Practice, Solution
  • Twitter Bootstrap Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution
  • C# Sharp Programming Exercises, Practice, Solution
  • PHP Exercises, Practice, Solution
  • Python Exercises, Practice, Solution
  • R Programming Exercises, Practice, Solution
  • Java Exercises, Practice, Solution
  • SQL Exercises, Practice, Solution
  • MySQL Exercises, Practice, Solution
  • PostgreSQL Exercises, Practice, Solution
  • SQLite Exercises, Practice, Solution
  • MongoDB Exercises, Practice, Solution

[ Want to contribute to Java exercises? Send your code (attached with a .zip file) to us at w3resource[at]yahoo[dot]com. Please avoid copyrighted materials.]

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Follow us on Facebook and Twitter for latest update.

  • Weekly Trends and Language Statistics

Lab 14 - Inheritance

Introduction.

Today’s lab will be covering the basics of Inheritance.

What is inheritance? Inheritance is a concept that explains how one class gains the attributes of another, including the inherited class’s methods and variables. This allows us to define more complex classes through the use of more general base classes. It also eliminates redundant code that could appear in multiple similar classes.

So how does this work? Inheritance works by taking existing code and building on top of it, and programmers can define a class to “inherit” existing code from another class by using the keyword “extends” in the class header.

For example, let’s say you have a class named Animal, and you wanted to make a class for Birds. Since Birds and Animals share many of the same base attributes, you could extend the Animal class and add any additional parts needed to the Bird class. Let’s take a look.

class Animal { public String noise; public int age; private String name; public Animal(String noise, int age, String name){ this.noise = noise; this.age = age; this.name = name; } public String getName() { return name; } public void speak(){ System.out.println("My name is " + name); System.out.println("I am " + age + " years old"); System.out.println("I say " + noise); } }
class Bird extends Animal { public double height; public String color; public Bird(String noise, int age, String name, double height, String color){ super(noise, age, name); this.height = height; this.color = color; } public void printBird(){ System.out.printf("Hello! I am %s and I am a %s Bird! %s!", this.getName(), this.color, this.noise); } public void speak(){ super.speak(); System.out.println("I am " + color); System.out.println("I am " + height + " inches tall"); } }

Some terminology

A base class, superclass, and parent class all mean the same thing - the class that is being extended.

A derived class, subclass, and child class also all mean the same thing - the class that is doing the extending.

In the above example the Animal is the class being extended and Bird is the class doing the extending. So in this example we could say:

  • Animal is the parent class
  • Animal is the superclass
  • Animal is the base class

We could also say:

  • Bird is the child class of Animal
  • Bird is the subclass of Animal
  • Bird is the derived class of Animal

Inheriting a Class

When using inheritance, we will be talk in terms of the relation between parent and child classes.

The parent class is the class that is inherited from. In the previous example, Animal is the parent class, as it is the class being extended , as seen when Bird extends Animal. The parent class is often capable of being an object on its own.

For example, you can have an object of type Animal, without it needing to be a Bird. A Bird however has many of the same traits as an Animal, but it needs a few more specific pieces of information to be usable, such as the height and color, things that are less important to the basic Animal.

The child class is the class that is actually inheriting, taking existing properties and methods from an above parent class. This allows the child class the ability to gain certain traits and tools from the parent class without having to copy and paste large chunks of code.

In the previous example, Bird needs some of the traits that Animal has, such as name, age, and noise, however rewriting this code is inefficient. Instead of duplicating code, we use the keyword extends as well as the name of the class we want to extend Animal (thus giving us Bird extends Animal ) which tells the system to bring anything from Animal that can be inherited, such as public class variables and methods.

The keyword super is used to tell the system that you want to use something from the parent class. It is used to call methods from the parent class, and to access the parent class constructor.

In a constructor

When inheriting a class, an additional step must be taken within the constructor.

The FIRST LINE inside the subclass’s constructor should always be a call to the superclass constructor.

This is because we need to invoke the constructor to set all of the information in the parent, in order to use our child class, so we call the parent’s constructor to set all of the needed information. If the parent class has a constructor with no parameters your call will look like this: super(); But if the parent class has a constructor with parameters, the call will look like this: super( *parameter list* );

Using a method

When wanting to use a method inside the superclass, you can use a call such as super.methodName(); . This will call the method in the super class just like calling any other method. This comes in handy when overriding methods. A call to a method using the keyword super specifies that you want to use a method from the superclass, not a method from the class you are currently in.

For example, in the Bird class we can call this.getName() because we have no other getName method, except the one in our parent class. Therefore, the system knows to look in the superclass. BUT, in the speak method, we have to use super.speak() because if we had used the keyword this , we would’ve gotten Bird’s speak method, not Animal’s. Because we have methods of the same name, we must specify the one we want, using the keyword super .

How to Access Information from the Superclass

Now that data has been inherited from the parent class, let’s talk about what you have access to and how to access it. When you inherit from a class you inherit all of the information belonging to that class, however you do not always inherit the right to access it. This may sound a little confusing, so let’s go over it.

Here’s what child classes will always get access to: any public or protected variables or methods.

After inheriting, public information stays public, but protected information now becomes private. For example, something that was protected in the Animal class is now seen as private in the Bird class after inheritence.

Private variables and methods are a slightly different story. Although the child class inherits the information stored in the private methods and variables, it lacks the ability to interact with or modify the information stored in those variables without the use of a getter or setter. Just remember that the keyword private means that no one outside of the class has access to it, not even a child class.

In the Animal/Bird example, Bird gains the ability to freely access and modify the values stored in noise and age. However, it is only able to interact with name through the getName and setName Methods. This is why getters and setters are so important. Getters and setters allow for child classes to interact with private inherited information.

Overriding Methods

When you inherit from a class, along with it comes all of the methods and variables the superclass had, but what if you want to write a method with the same name as one of the superclass’s methods?

Well, you can just override it, by writing a new method with the same name in the subclass. When Java is compiling the code it can tell that the subclass is overriding the method from the superclass and will instead only use the subclass’s version of that method. For example in the Animal/Bird example, Bird overrides the speak() method found in Animal. Overriding a method is especially common with methods such as toString() and equals().

Inheriting from a subclass

It is possible to inherit from a subclass, and in fact all basic inheritance does so. All classes, regardless of whether the intent of them is to create an object or not, inherit from the built-in Java Object Class. Object is the base class that provides a multitude of necessary methods needed for all java classes to function including, toString() and equals(otherObject).

Multiple levels of inheritance are very common, especially when multiple items may have shared core attributes but have specific needs within their own class. When inheriting from a class that is also inheriting from another class, the new subclass gains all of the information stored within both the superclass and the superclass’s superclass, following the same rules as normal inheritance.

We will talk about this more in depth later but for now, draw out an inheritance hierarchy if you are confused about the structure of the inheriting classes. The top class should be the main class that is extended from, and those below it are the subclasses which are extending from it.

instanceof is a special keyword used for comparing objects, such as in the equals method, which compares whether two objects of a specific class are equal. Instead of trying and compare two things that are not of the same type, we first use casting and instanceof to see if two things are comparable.

So, the equals method takes an argument of type Object , which means it can be any type of object, so it is not necessarily the same type as the class calling the equals method. We then have to use instanceof to check if the variable coming in is a valid type to be compared to. We use instanceof to make sure we can safely type cast our other object without errors.

Here is an example equals method, for the Bird class.

This method first checks if the other object is a Bird, and if it’s not a Bird, then we can’t compare it to our Bird object, so we return false. Next, we do a simple comparison between some of the class variables of the two objects. This allows you to specify how closely related two objects need to be in order to be defined as equal.

For example, if you have two Birds with different heights but the same color you could say they are equal. This ability to define the equals method for each class gives a great degree of flexibility.

Now on to the lab!

Here are the lab instructions:

You will be completing a class named Employee that will inherit from the class Person.

  • Finish the extends statement in the Employee class header
  • Write the Employee constructor don’t forget your call to super
  • Create two private class variables: an int id , and a double hourlyPay
  • Since they are both private variables, write getters and setters for both variables: getId, getHourlyPay, setId, setHourlyPay

In the Employee class, complete the getRaise method. This method gives a raise to the user, increasing their total hourly pay by 15%. This method also updates the hourly pay class variable you made as well. Finally return the value of the employee’s new hourlyPay.

Inside the Employee class complete the method payDay. This method calculates how much the employee earned for the week. First calculate their pay, if the employee worked more than 40 hours, then any hour OVER 40 is worth 1.5 times their normal pay, this is considered overtime pay, otherwise their pay is as normal. Return their total pay for the week.

Example: if I worked 45 hours this week, I would get 5 hours of overtime pay and 40 hours of normal pay.

Inside the Employee class, let’s override the toString method.

For the toString method, you will use the same basic output from Person toString method but add two new lines. Using Person toString method as a starting point, the first two lines of our new toString method will look like:

Name: first_name last_name

They are height_feet ’ height_inches “

You will now also add the lines:

They make $ hourly_pay

They have the employee ID id_number

Each line should be followed by a new line, including the last character. The hourly pay should also be formatted with two digits after the decimal place. (Remember String.format()?)

HINT will a call to super help?

Inside the Employee class, we will now override the equals method.

The method will return true if the employees share the same ID AND their last names are the same Otherwise, the two are not the same and the method will return false.

HINT Go back and look at the example given above for instanceof … does that look similar to what we are trying to do?

Java Coding Practice

java lab assignment questions with answers

What kind of Java practice exercises are there?

How to solve these java coding challenges, why codegym is the best platform for your java code practice.

  • Tons of versatile Java coding tasks for learners with any background: from Java Syntax and Core Java topics to Multithreading and Java Collections
  • The support from the CodeGym team and the global community of learners (“Help” section, programming forum, and chat)
  • The modern tool for coding practice: with an automatic check of your solutions, hints on resolving the tasks, and advice on how to improve your coding style

java lab assignment questions with answers

Click on any topic to practice Java online right away

Practice java code online with codegym.

In Java programming, commands are essential instructions that tell the computer what to do. These commands are written in a specific way so the computer can understand and execute them. Every program in Java is a set of commands. At the beginning of your Java programming practice , it’s good to know a few basic principles:

  • In Java, each command ends with a semicolon;
  • A command can't exist on its own: it’s a part of a method, and method is part of a class;
  • Method (procedure, function) is a sequence of commands. Methods define the behavior of an object.

Here is an example of the command:

The command System.out.println("Hello, World!"); tells the computer to display the text inside the quotation marks.

If you want to display a number and not text, then you do not need to put quotation marks. You can simply write the number. Or an arithmetic operation. For example:

Command to display the number 1.

A command in which two numbers are summed and their sum (10) is displayed.

As we discussed in the basic rules, a command cannot exist on its own in Java. It must be within a method, and a method must be within a class. Here is the simplest program that prints the string "Hello, World!".

We have a class called HelloWorld , a method called main() , and the command System.out.println("Hello, World!") . You may not understand everything in the code yet, but that's okay! You'll learn more about it later. The good news is that you can already write your first program with the knowledge you've gained.

Attention! You can add comments in your code. Comments in Java are lines of code that are ignored by the compiler, but you can mark with them your code to make it clear for you and other programmers.

Single-line comments start with two forward slashes (//) and end at the end of the line. In example above we have a comment //here we print the text out

You can read the theory on this topic here , here , and here . But try practicing first!

Explore the Java coding exercises for practicing with commands below. First, read the conditions, scroll down to the Solution box, and type your solution. Then, click Verify (above the Conditions box) to check the correctness of your program.

java lab assignment questions with answers

The two main types in Java are String and int. We store strings/text in String, and integers (whole numbers) in int. We have already used strings and integers in previous examples without explicit declaration, by specifying them directly in the System.out.println() operator.

In the first case “I am a string” is a String in the second case 5 is an integer of type int. However, most often, in order to manipulate data, variables must be declared before being used in the program. To do this, you need to specify the type of the variable and its name. You can also set a variable to a specific value, or you can do this later. Example:

Here we declared a variable called a but didn't give it any value, declared a variable b and gave it the value 5 , declared a string called s and gave it the value Hello, World!

Attention! In Java, the = sign is not an equals sign, but an assignment operator. That is, the variable (you can imagine it as an empty box) is assigned the value that is on the right (you can imagine that this value was put in the empty box).

We created an integer variable named a with the first command and assigned it the value 5 with the second command.

Before moving on to practice, let's look at an example program where we will declare variables and assign values to them:

In the program, we first declared an int variable named a but did not immediately assign it a value. Then we declared an int variable named b and "put" the value 5 in it. Then we declared a string named s and assigned it the value "Hello, World!" After that, we assigned the value 2 to the variable a that we declared earlier, and then we printed the variable a, the sum of the variables a and b, and the variable s to the screen

This program will display the following:

We already know how to print to the console, but how do we read from it? For this, we use the Scanner class. To use Scanner, we first need to create an instance of the class. We can do this with the following code:

Once we have created an instance of Scanner, we can use the next() method to read input from the console or nextInt() if we should read an integer.

The following code reads a number from the console and prints it to the console:

Here we first import a library scanner, then ask a user to enter a number. Later we created a scanner to read the user's input and print the input out.

This code will print the following output in case of user’s input is 5:

More information about the topic you could read here , here , and here .

See the exercises on Types and keyboard input to practice Java coding:

Conditions and If statements in Java allow your program to make decisions. For example, you can use them to check if a user has entered a valid password, or to determine whether a number is even or odd. For this purpose, there’s an 'if/else statement' in Java.

The syntax for an if statement is as follows:

Here could be one or more conditions in if and zero or one condition in else.

Here's a simple example:

In this example, we check if the variable "age" is greater than or equal to 18. If it is, we print "You are an adult." If not, we print "You are a minor."

Here are some Java practice exercises to understand Conditions and If statements:

In Java, a "boolean" is a data type that can have one of two values: true or false. Here's a simple example:

The output of this program is here:

In addition to representing true or false values, booleans in Java can be combined using logical operators. Here, we introduce the logical AND (&&) and logical OR (||) operators.

  • && (AND) returns true if both operands are true. In our example, isBothFunAndEasy is true because Java is fun (isJavaFun is true) and coding is not easy (isCodingEasy is false).
  • || (OR) returns true if at least one operand is true. In our example, isEitherFunOrEasy is true because Java is fun (isJavaFun is true), even though coding is not easy (isCodingEasy is false).
  • The NOT operator (!) is unary, meaning it operates on a single boolean value. It negates the value, so !isCodingEasy is true because it reverses the false value of isCodingEasy.

So the output of this program is:

More information about the topic you could read here , and here .

Here are some Java exercises to practice booleans:

With loops, you can execute any command or a block of commands multiple times. The construction of the while loop is:

Loops are essential in programming to execute a block of code repeatedly. Java provides two commonly used loops: while and for.

1. while Loop: The while loop continues executing a block of code as long as a specified condition is true. Firstly, the condition is checked. While it’s true, the body of the loop (commands) is executed. If the condition is always true, the loop will repeat infinitely, and if the condition is false, the commands in a loop will never be executed.

In this example, the code inside the while loop will run repeatedly as long as count is less than or equal to 5.

2. for Loop: The for loop is used for iterating a specific number of times.

In this for loop, we initialize i to 1, specify the condition i <= 5, and increment i by 1 in each iteration. It will print "Count: 1" to "Count: 5."

Here are some Java coding challenges to practice the loops:

An array in Java is a data structure that allows you to store multiple values of the same type under a single variable name. It acts as a container for elements that can be accessed using an index.

What you should know about arrays in Java:

  • Indexing: Elements in an array are indexed, starting from 0. You can access elements by specifying their index in square brackets after the array name, like myArray[0] to access the first element.
  • Initialization: To use an array, you must declare and initialize it. You specify the array's type and its length. For example, to create an integer array that can hold five values: int[] myArray = new int[5];
  • Populating: After initialization, you can populate the array by assigning values to its elements. All elements should be of the same data type. For instance, myArray[0] = 10; myArray[1] = 20;.
  • Default Values: Arrays are initialized with default values. For objects, this is null, and for primitive types (int, double, boolean, etc.), it's typically 0, 0.0, or false.

In this example, we create an integer array, assign values to its elements, and access an element using indexing.

In Java, methods are like mini-programs within your main program. They are used to perform specific tasks, making your code more organized and manageable. Methods take a set of instructions and encapsulate them under a single name for easy reuse. Here's how you declare a method:

  • public is an access modifier that defines who can use the method. In this case, public means the method can be accessed from anywhere in your program.Read more about modifiers here .
  • static means the method belongs to the class itself, rather than an instance of the class. It's used for the main method, allowing it to run without creating an object.
  • void indicates that the method doesn't return any value. If it did, you would replace void with the data type of the returned value.

In this example, we have a main method (the entry point of the program) and a customMethod that we've defined. The main method calls customMethod, which prints a message. This illustrates how methods help organize and reuse code in Java, making it more efficient and readable.

In this example, we have a main method that calls the add method with two numbers (5 and 3). The add method calculates the sum and returns it. The result is then printed in the main method.

All composite types in Java consist of simpler ones, up until we end up with primitive types. An example of a primitive type is int, while String is a composite type that stores its data as a table of characters (primitive type char). Here are some examples of primitive types in Java:

  • int: Used for storing whole numbers (integers). Example: int age = 25;
  • double: Used for storing numbers with a decimal point. Example: double price = 19.99;
  • char: Used for storing single characters. Example: char grade = 'A';
  • boolean: Used for storing true or false values. Example: boolean isJavaFun = true;
  • String: Used for storing text (a sequence of characters). Example: String greeting = "Hello, World!";

Simple types are grouped into composite types, that are called classes. Example:

We declared a composite type Person and stored the data in a String (name) and int variable for an age of a person. Since composite types include many primitive types, they take up more memory than variables of the primitive types.

See the exercises for a coding practice in Java data types:

String is the most popular class in Java programs. Its objects are stored in a memory in a special way. The structure of this class is rather simple: there’s a character array (char array) inside, that stores all the characters of the string.

String class also has many helper classes to simplify working with strings in Java, and a lot of methods. Here’s what you can do while working with strings: compare them, search for substrings, and create new substrings.

Example of comparing strings using the equals() method.

Also you can check if a string contains a substring using the contains() method.

You can create a new substring from an existing string using the substring() method.

More information about the topic you could read here , here , here , here , and here .

Here are some Java programming exercises to practice the strings:

In Java, objects are instances of classes that you can create to represent and work with real-world entities or concepts. Here's how you can create objects:

First, you need to define a class that describes the properties and behaviors of your object. You can then create an object of that class using the new keyword like this:

It invokes the constructor of a class.If the constructor takes arguments, you can pass them within the parentheses. For example, to create an object of class Person with the name "Jane" and age 25, you would write:

Suppose you want to create a simple Person class with a name property and a sayHello method. Here's how you do it:

In this example, we defined a Person class with a name property and a sayHello method. We then created two Person objects (person1 and person2) and used them to represent individuals with different names.

Here are some coding challenges in Java object creation:

Static classes and methods in Java are used to create members that belong to the class itself, rather than to instances of the class. They can be accessed without creating an object of the class.

Static methods and classes are useful when you want to define utility methods or encapsulate related classes within a larger class without requiring an instance of the outer class. They are often used in various Java libraries and frameworks for organizing and providing utility functions.

You declare them with the static modifier.

Static Methods

A static method is a method that belongs to the class rather than any specific instance. You can call a static method using the class name, without creating an object of that class.

In this example, the add method is static. You can directly call it using Calculator.add(5, 3)

Static Classes

In Java, you can also have static nested classes, which are classes defined within another class and marked as static. These static nested classes can be accessed using the outer class's name.

In this example, Student is a static nested class within the School class. You can access it using School.Student.

More information about the topic you could read here , here , here , and here .

See below the exercises on Static classes and methods in our Java coding practice for beginners:

  • Privacy Policy
  • Programming Blogs

Object Oriented Programming with JAVA – BCSL306A

java lab assignment questions with answers

In this blog post, you will find solutions for the laboratory subject Object Oriented Programming with JAVA (BCSL306A) course work for the III semester of VTU university. The solutions to the lab component are coded in Java . Along with the Java programs for each question I have provided samples of program output as well.

You can find the lab syllabus here.

Now lets focus on the solutions. Click on the appropriate hyperlink to go to your program of choice.

  • Matrix Addition
  • Stack Operations
  • 2D Point Class
  • Inheritance – Shape Class
  • Abstract Class
  • Resizable interface
  • Outer class
  • Custom Exception
  • Runnable Interface
  • Thread Class

java lab assignment questions with answers

Program 01 : Matrix Addition

Develop a JAVA program to add TWO matrices of suitable order N (The value of N should be read from command line arguments).

In this example, the matrices are filled with sequential values for simplicity, but you can modify the fillMatrix method to fill the matrices with any values you prefer.

Program 02 : Stack Operations

Develop a stack class to hold a maximum of 10 integers with suitable methods. Develop a JAVA main method to illustrate Stack operations.

Program 03 : Employee Class

A class called Employee, which models an employee with an ID, name and salary, is designed as shown in the following class diagram. The method raiseSalary (percent) increases the salary by the given percentage. Develop the Employee class and suitable main method for demonstration.

In this example, the Employee class has a constructor to initialize the employee’s ID, name, and salary. The raiseSalary method takes a percentage as a parameter and raises the salary accordingly. The toString method is overridden to provide a meaningful string representation of the Employee object. The main method demonstrates the usage of the Employee class by creating an instance, displaying its details, raising the salary, and then displaying the updated details.

Program 04 : 2D Point Class

A class called MyPoint, which models a 2D point with x and y coordinates, is designed as follows:

  • Two instance variables x (int) and y (int).
  • A default (or “no-arg”) constructor that construct a point at the default location of (0, 0).
  • A overloaded constructor that constructs a point with the given x and y coordinates.
  • A method setXY() to set both x and y.
  • A method getXY() which returns the x and y in a 2-element int array.
  • A toString() method that returns a string description of the instance in the format “(x, y)”.
  • A method called distance(int x, int y) that returns the distance from this point to another point at the given (x, y) coordinates
  • An overloaded distance(MyPoint another) that returns the distance from this point to the given MyPoint instance (called another)
  • Another overloaded distance() method that returns the distance from this point to the origin (0,0) Develop the code for the class MyPoint. Also develop a JAVA program (called TestMyPoint) to test all the methods defined in the class.

MyPoint.java

Testmypoint.java.

This TestMyPoint program creates two MyPoint objects, sets and retrieves coordinates, and tests the various distance calculation methods. Feel free to modify and expand this code as needed.

Program 05 : Inheritance & Polymorphism – Shape Class

Develop a JAVA program to create a class named shape. Create three sub classes namely: circle, triangle and square, each class has two member functions named draw () and erase (). Demonstrate polymorphism concepts by developing suitable methods, defining member data and main program.

In this program, the Shape class is the superclass, and Circle , Triangle , and Square are its subclasses. The draw() and erase() methods are overridden in each subclass. The main method creates an array of Shape objects and initializes it with instances of the different subclasses. When iterating through the array and calling the draw() and erase() methods, polymorphism allows the appropriate overridden methods in each subclass to be executed.

Program 06 : Abstract Class

Develop a JAVA program to create an abstract class Shape with abstract methods calculateArea() and calculatePerimeter(). Create subclasses Circle and Triangle that extend the Shape class and implement the respective methods to calculate the area and perimeter of each shape.

In this program, Shape is an abstract class with abstract methods calculateArea() and calculatePerimeter() . The Circle and Triangle classes extend Shape and provide their implementations for these abstract methods. The ShapeDemo class demonstrates creating objects of these shapes and calculating their areas and perimeters.

Program 07 : Resizable interface

Develop a JAVA program to create an interface Resizable with methods resizeWidth(int width) and resizeHeight(int height) that allow an object to be resized. Create a class Rectangle that implements the Resizable interface and implements the resize methods.

In this program, the Resizable interface declares the methods resizeWidth and resizeHeight . The Rectangle class implements this interface and provides the specific implementation for resizing the width and height. The main method in the ResizeDemo class creates a Rectangle object, displays its original information, resizes it, and then displays the updated information.

Program 08 : Outer class

Develop a JAVA program to create an outer class with a function display. Create another class inside the outer class named inner with a function called display and call the two functions in the main class.

In this program, the Outer class has a method named display , and it also contains an inner class named Inner with its own display method. In the main method of the OuterInnerDemo class, an instance of the outer class ( Outer ) is created, and its display method is called. Then, an instance of the inner class ( Inner ) is created using the outer class instance, and its display method is called. This demonstrates the concept of nesting classes in Java.

Program 09 : Custom Exception

Develop a JAVA program to raise a custom exception (user defined exception) for DivisionByZero using try, catch, throw and finally.

In this program:

  • The DivisionByZeroException class is a custom exception that extends the Exception class.
  • The divide method performs division and throws the custom exception if the denominator is zero.
  • In the main method, we attempt to divide and catch the custom exception if it occurs. The finally block is used for code that must be executed, whether an exception is thrown or not.

When you run this program with a denominator of 0, it will throw the DivisionByZeroException , catch it, print the error message, and then execute the finally block.

Program 10 : Packages

Develop a JAVA program to create a package named mypack and import & implement it in a suitable class.

Package mypack

Now, let’s create the main program in a different file outside the mypack folder:

PackageDemo class using mypack Package

To compile and run this program, you need to follow these steps:

Organize your directory structure as follows:

Compile the files:

Program 11 : Runnable Interface

Write a program to illustrate creation of threads using runnable class. (start method start each of the newly created thread. Inside the run method there is sleep() for suspend the thread for 500 milliseconds).

In this program, we define a MyRunnable class that implements the Runnable interface. The run method contains a loop where the thread sleeps for 500 milliseconds, printing its ID during each iteration. We also handle potential interruptions caused by thread operations.

In the RunnableThreadExample class, we create five instances of MyRunnable , each associated with a separate thread. The start method is called on each thread, initiating their concurrent execution. After a brief period of allowing the threads to run, we gracefully stop each thread using the stopThread method.

Program 12 : Thread Class

Develop a program to create a class MyThread in this class a constructor, call the base class constructor, using super and start the thread. The run method of the class starts after this. It can be observed that both main thread and created child thread are executed concurrently.

  • The MyThread class extends Thread .
  • The constructor of MyThread calls the base class constructor using super(name) to set the thread’s name and starts the thread.
  • The run method is overridden and contains a loop to print counts. The thread sleeps for 500 milliseconds in each iteration.
  • In the main method, an instance of MyThread is created, which starts the child thread concurrently.
  • The main thread also prints counts and sleeps for 500 milliseconds in each iteration.

When you run this program, you’ll observe that both the main thread and the child thread are executed concurrently, and their outputs may be interleaved.

If you are also looking for other Lab Manuals, head over to my following blog :

VTU Lab Manuals using FOSS

Prabodh C P

' data-src=

Prabodh C P is a faculty in the Dept of CSE SIT, Tumkur and also currently a Research Scholar pursuing PhD in IIT Hyderabad. He conducts online classes for C, C++, Python. For more info call +919392302100

Related Posts

java lab assignment questions with answers

MongoDB Lab Manual – BDS456B

java lab assignment questions with answers

COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY – 21CSL66

java lab assignment questions with answers

Artificial Intelligence Lab Component (BAD402)

Leave a reply cancel reply.

Your email address will not be published. Required fields are marked *

Search Tutorials

Java variables mcq - multiple choice questions and answers, q. what is the purpose of a variable in java, q. what is the data type of the variable "x" in the following code snippet: int x = 5;, q. which of the following is not a valid variable name in java, q. what is the default value of an uninitialized int variable in java, q. which keyword is used to declare a constant variable in java, q. which of the following is a valid variable declaration in java, q. what is the scope of a local variable in java, q. what is the difference between instance variables and local variables in java, q. what is the purpose of the final keyword in java, q. what is the data type of the variable "name" in the following code snippet: string name = "john";, q. what is the correct way to declare an integer variable in java, q. what will be the value of x after executing the following code snippet, q. what is the correct syntax to declare a constant variable in java, q. which of the following statements is true about variable names in java, q. what is the scope of a variable declared inside a method in java, q. what is the default value of an uninitialized integer variable in java, q. which of the following is a valid variable name in java, q. what is the difference between local variables and instance variables in java, q. which of the following is the correct way to declare a string variable in java, q. what is the purpose of initializing a variable in java, popular posts.

  • Spring Boot Interview Questions
  • Implement Spring Boot Security and understand Spring Security Architecture
  • E-commerce Website - Online Book Store using Angular 8 + Spring Boot
  • Spring Boot +JSON Web Token(JWT) Hello World Example
  • Angular 7 + Spring Boot Application Hello World Example
  • Build a Real Time Chat Application using Spring Boot + WebSocket + RabbitMQ
  • Pivotal Cloud Foundry Tutorial - Deploy Spring Boot Application Hello World Example
  • Deploying Spring Based WAR Application to Docker
  • EIP patterns using Apache Camel
  • Spring Cloud- Netflix Eureka + Ribbon Simple Example
  • Spring Cloud- Netflix Hystrix Circuit Breaker Simple Example
  • Spring Boot + Swagger Example Hello World Example
  • Spring Boot Batch Simple example
  • Spring Boot + Apache Kafka Example
  • Spring Boot Admin Simple Example
  • Spring Boot Security - Introduction to OAuth
  • Spring Boot OAuth2 Part 1 - Getting The Authorization Code
  • Spring Boot OAuth2 Part 2 - Getting The Access Token And Using it to Fetch Data.
  • JBoss Drools Hello World-Stateful Knowledge Session using KieSession
  • Understand Drools Stateful vs Stateless Knowledge Session
  • JBoss Drools- Understanding Drools Decision Table using Simple Example
  • Spring Batch Interview Questions
  • Spring AOP Interview Questions
  • Angular 2 Interview Questions
  • Apache Camel Interview Questions
  • JBoss Fuse Interview Questions
  • Drools Interview Questions
  • Java 8 Interview Questions
  • Spring Cloud Interview Questions
  • Microservices Interview Questions
  • Java HashMap and ConcurrentHashMap Interview Questions
  • Snowflake frequently asked interview questions
  • SAP FI - Accounts Receivable frequently asked interview questions
  • Top SAP ALV Interview Questions
  • Top SAP Business Objects Administration Interview Questions
  • EC2 frequently asked interview questions
  • Mule ESB frequently asked interview questions
  • Apache Kafka Interview Questions
  • Tosca Testing Tool Interview Questions
  • Top Maven Build Tool Interview Questions
  • Top Gradle Build Tool Interview Questions
  • Miscellaneous Topics

Java Programming Exercises

  • All Exercises
  • Java 8 - Lambdas & Streams
  • Binary Tree

I created this website to help developers improve their programming skills by practising simple coding exercises. The target audience is Software Engineers, Test Automation Engineers, or anyone curious about computer programming. The primary programming language is Java, as it is mature and easy to learn, but you can practice the same problems in any other language (Kotlin, Python, Javascript, etc.).

  • Binary Tree problems are common at Google, Amazon and Facebook coding interviews.
  • Sharpen your lambda and streams skills with Java 8 coding practice problems .
  • Check our Berlin Clock solution , a commonly used code exercise.
  • We have videos too! Check out the FizzBuzz solution , a problem widely used on phone screenings.

How does it work ?

1. Choose difficulty

Easy, moderate or challenging.

2. Choose the exercise

From a list of coding exercises commonly found in interviews.

3. Type in your code

No IDE, no auto-correct... just like the whiteboard interview question.

4. Check results

Typically 3-5 unit tests that verify your code.

[email protected]

Email

Javatpoint Logo

Java Tutorial

Control statements, java object class, java inheritance, java polymorphism, java abstraction, java encapsulation, java oops misc.

JavaTpoint

Java is one of the most demanding languages in the market today. As a fact, ten million developers across the globe work on the , though the number is increasing day by day. So if you are a Java developer, a budding Java aspirant, or a student, you will most likely be attending a or a Java viva exam. Most commonly, the interviewers ask questions to check your programming knowledge.

The use of garbage collection in Java is to recognize and remove objects that are no more required by a program and are unnecessary consuming the program resources that could be freed and reused by other objects. An object in Java is subject to garbage collection when it turns inaccessible to the Java program in which it is initiated.

Lambda Expressions, often called lambdas, are a new feature introduced with Java 8. They provide an easier way to work with interfaces that have only got one method, and they are often used in places where the programmer use anonymous classes.

Sometimes we need to write several lines to accomplish what we want to do when all we care about is to print any statement. Using a Lambda expression, we can do that in a single line. Therefore, increasing the program efficiency by reducing the lines of codes.

A thread is a single sequential flow of control within a process where each process can contain two or more "threads". In Java, a thread is created and coordinated by the .

Every process (or application) in Java language contains at least one thread (also known as the main thread). Depending on the programmers need, the process can contain multiple threads as well to handle different tasks such as memory management and 1/0.

Syntax for reading data from a Buffer:

Syntax for writing data from a Buffer:

There are two main reasons for this:

Therefore, instead of tying up the main thread, we can create multiple threads and execute the long-running task on those threads. This would free up the main thread, so that it can continue executing. This process is called . It can report progress or accept user input while the long-running task continues to execute in the background.

A deadlock occurs when two or more threads are blocked on locks and every thread that's blocked is holding a lock that another block thread wants. For example: thread 1 is holding lock 1 and waiting to acquire lock 2 but thread 2 is holding lock 2 and waiting to acquire lock 1. It creates a situation where all the threads holding the locks are blocked therefore it will never release the locks they're holding and so none of the waiting threads will actually ever run.

A BufferedReader reads text from the input stream and buffers the characters into a character array. Reading chunks of data from a stream (unlike a file) is more efficient than reading just a few characters at a time.

Therefore we can conclude that BufferReader is more streamlined and faster. Also, we can specify the size of the buffer, but the default is 8k, and that is also sufficient for most purposes.

In Java 1.4, a new I/O package was added to the Java SDK called Java.nio The package was introduced as an expansion to Java I/O because the classes in the package implemented 1/0 in a non-blocking manner. The package Java.nio was also meant to fix some of the problems developers could run into when using the Java.io classes to work with the file system.

The driver is simply a Java library containing classes that implement the JDBC API. Because all have to implement the same interfaces, it's not difficult to change the data source an application uses. For example, if an application uses an SQLite database, and then we decide later that we want to use a MySQL database, all we have to do use the MySQL JDBC driver instead of the SQLite one (in addition to migrating the data to a MySQL DB, of course).

: Java.sql (core JDBC) and Javax.sql (optional JDBC). The APIs in the Javax.sql package is required when working with database servers. We'll talk about those later. All the popular databases provide JDBC drivers. The JDK ships with a database called a derby, which can be used for desktop applications or when prototyping. The derby JDBC driver is also included in the JDK.

Sockets are used in Java programming because of their flexibility and easy communication protocols. They also cause low network traffic such as HTML forms and CGI scripts that create and transfer the complete web pages for each new data request.

The communications that occurs through Socket only enables to send packets of raw data between applications.

With respect to multithreading, synchronization is the process of controlling the access of multiple threads to shared resources. In Java, we can synchronize methods and statements. Whenever we synchronize any method in Java program, it allows only one thread to execute at one time. Therefore, if a thread is using a synchronize method, all the other threads that want to execute the same method or any other synchronized method initiated in the same class will suspend until the execution of the running thread is completed.

The JSTL <c: for each > is an used to loop or repeat the nested body content a fixed number of times. This tag is an alternative for Java loops such as

The is an API widely used in Java programming to facilitate mailing operations such as on the Internet.

It is a protocol-independent and platform-independent framework available as an optional package with the Java SE platform and incorporated in the Java EE platform as well.

The can be used for many conducting other events. It can be used to register the user (sending notifications unlike thank you for visiting my website or subscribing to our newsletter), forgot the password (set and update a new password through mail), sending update notifications, etc,

The two packages that contain the core classes of are given below:

JSTL includes five types of tags:

Web container or servlet container is responsible to create the object of Servlets.

The RequestDispacher interface in Servlet is used to dispatch requests to other resources such as HTML, Servlet or JSP. However, it can also be used to incorporate the content of another resource.

Attribute is a map object that enables the Servlets to share information among themselves (mainly between one servlet to another). Attributes can be used to set, get or remove in request, session or application scope.

In JSP, Session for a particular time frame.

Session Tracking is a mechanism used by the web container to maintain the state of a user. The HTTP and web servers are stateless protocols. Therefore all requests and responses are independent. Every time a user requests to the server, it is treated as a new request. So to prevent this and to maintain the state of a user (recognize to a particular user), we use Session Tracking.

The common methods used in Session Tracking are given below:

The exception implicit object was created only for the JSP error page and is defined using the isErrorPage attribute. Therefore, we cannot use the exception implicit object in any JSP page.

Yes, we can forward a request from the JSP page to Servlet by using the JSP "forward action" tag and by mentioning the URL pattern of the Servlet.

JSP technology is extensible through the development of tags or custom actions that are encapsulated in tag libraries.

In Java, the static initializer is defined as a static {} block of code that runs only once before the constructor or main method is called. It is useful when the user wants to execute a complex calculation to determine 'n' value or if its value is fetched from a database.

The Java Transaction API (JTA) permits the applications to execute distributed transactions that can access and update data on multiple networked computing resources.

A transaction is defined as a logical unit of work that either succeeds or generates no result. In contrast, a Distributed transaction can access and update data on multiple computing networked resources.

The different transactional attributes are as follows:





Youtube

  • Send your Feedback to [email protected]

Help Others, Please Share

facebook

Learn Latest Tutorials

Splunk tutorial

Transact-SQL

Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial

Preparation

Aptitude

Verbal Ability

Interview Questions

Interview Questions

Company Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

RSS Feed

Welcome to Java! Easy Max Score: 3 Success Rate: 97.05%

Java stdin and stdout i easy java (basic) max score: 5 success rate: 96.86%, java if-else easy java (basic) max score: 10 success rate: 91.36%, java stdin and stdout ii easy java (basic) max score: 10 success rate: 92.69%, java output formatting easy java (basic) max score: 10 success rate: 96.54%, java loops i easy java (basic) max score: 10 success rate: 97.67%, java loops ii easy java (basic) max score: 10 success rate: 97.32%, java datatypes easy java (basic) max score: 10 success rate: 93.69%, java end-of-file easy java (basic) max score: 10 success rate: 97.92%, java static initializer block easy java (basic) max score: 10 success rate: 96.12%, cookie support is required to access hackerrank.

Seems like cookies are disabled on this browser, please enable them to open this website

COMMENTS

  1. PDF Java Programming Lab Manual

    Lab Objectives: 4CS4-25.1: To be able to develop an in depth understanding of programming in Java: data types, variables, operators, operator precedence, Decision and control statements, arrays, switch statement, Iteration Statements, Jump Statements, Using break, Using continue, return. 4CS4-25.2: To be able to write Object Oriented programs ...

  2. Java Exercises

    Output: 5. Click Here for the Solution. 3. Write a Program to Swap Two Numbers. Input: a=2 b=5. Output: a=5 b=2. Click Here for the Solution. 4. Write a Java Program to convert Integer numbers and Binary numbers.

  3. Java programming Exercises, Practice, Solution

    The best way we learn anything is by practice and exercise questions. Here you have the opportunity to practice the Java programming language concepts by solving the exercises starting from basic to more complex exercises. A sample solution is provided for each exercise. It is recommended to do these exercises by yourself first before checking ...

  4. Lab 14

    Inheritance is a concept that explains how one class gains the attributes of another, including the inherited class's methods and variables. This allows us to define more complex classes through the use of more general base classes. It also eliminates redundant code that could appear in multiple similar classes.

  5. PDF Chapter 7: Arrays Lab Exercises

    the key for a 10-question quiz. You will need to store the key in an array. 3. Ask the user to enter the answers for the quiz to be graded. As for the key, these can be entered on a single line. Again there needs to be one for each question. Note that these answers do not need to be stored; each answer can simply be compared to the key as it is ...

  6. Hands On Java Lab 9 Exercise

    Also copy the packages ann and hoj and add them to your project. Then open the file Grades.java, and take a few moments to look it over. As indicated by its documentation, Grades.java is a skeleton program that (partially) encodes the algorithm given above. Today's exercise will consist of completing this program.

  7. Java Coding Practice

    Explore the Java coding exercises for practicing with commands below. First, read the conditions, scroll down to the Solution box, and type your solution. Then, click Verify (above the Conditions box) to check the correctness of your program. Exercise 1 Exercise 2 Exercise 3. Start task.

  8. Java Lab Exercise One

    Assignment 1 lab assignment one due date: sep. 25 11:59 pm grade weight: for each of the following questions, develop java code, place all your solutions into Skip to document Ask an Expert

  9. Object Oriented Programming with JAVA

    Prabodh C P Nov 18, 2023. In this blog post, you will find solutions for the laboratory subject Object Oriented Programming with JAVA (BCSL306A) course work for the III semester of VTU university. The solutions to the lab component are coded in Java. Along with the Java programs for each question I have provided samples of program output as well.

  10. Solved Assignment 1: Object Oriented Programming in Java

    Question: Assignment 1: Object Oriented Programming in Java - Lab (2%) This assignment relates to the following Course Learning Requirements: CLR 1: Implement an objected-oriented program design incorporating the use of best practice design patterns using the JAVA programming language. Objective of this Assignment: Demonstrate the skills ...

  11. JAVA Programming

    0 0 questions 20 20 students. Follow this course. JAVA Programming (CSE 1007) Follow. ... 2.Object Oriented Programming with Java Lab Exercise sand Solutions. 95 pages 2021/2022 100% (4) 2021/2022 100% (4) Save. ... Programming IN JAVA LAB Assignment-3. 8 pages 2023/2024 None. 2023/2024 None. Save. CIC Manual - vjdc. 86 pages 2016/2017 None ...

  12. Java Variables MCQ

    This multiple choice quiz on Java variables assesses your understanding of variable declaration, initialization, scope, and data type compatibility. Test your knowledge on how variables are defined, assigned values, and utilized in Java programming. This quiz covers fundamental concepts essential for mastering Java variable handling.

  13. JAVA LAB Assignment-2

    JAVA LAB ASSIGNMENT-NAME- SIDDHARTH REDDY REG- 19BCE Q2)a ) For a Mobile Shop project, create "Telephone" class with details like mobile_id, model_name and available_quantity in "Phone" package. Inherit from this class and create a class for

  14. Solved JAVA LAB Assignment 10 % Write full Java program

    Computer Science questions and answers; JAVA LAB Assignment 10 % Write full Java program Question 1: Suppose gpa is a variable containing the grade point average of a student. Suppose the goal of a program is to let a student know if he/she made the Dean's list (the gpa must be 3.5 or above).

  15. Solved Lab Assignment 5- Java Swing 1. Create the following

    Computer Science questions and answers; Lab Assignment 5- Java Swing 1. Create the following user interface:1. The user will enter name and umber of days. 2. Choose a bike model. 3. User will have an option if he or she is a senior citizen or a member. 4. The user will press compute and the program will output the total. 5.

  16. Java Programming Exercises with Solutions

    Highlights. Binary Tree problems are common at Google, Amazon and Facebook coding interviews.; Sharpen your lambda and streams skills with Java 8 coding practice problems.; Check our Berlin Clock solution, a commonly used code exercise.; We have videos too! Check out the FizzBuzz solution, a problem widely used on phone screenings.

  17. Advanced Java Viva Questions

    Advanced Java Viva Questions. Java is one of the most demanding languages in the market today. As a fact, ten million developers across the globe work on the Java programming language, though the number is increasing day by day.So if you are a Java developer, a budding Java aspirant, or a computer science student, you will most likely be attending a Java interview or a Java viva exam.

  18. Object Oriented Programming lab(Java)

    Date. Rating. year. Ratings. Studying Object Oriented Programming lab (Java) CSL203 at APJ Abdul Kalam Technological University? On Studocu you will find 17 practice materials, practical,

  19. Java Lab Assignment

    JAVA LAB ASSIGNMENT.docx - Free download as Word Doc (.doc / .docx), PDF File (.pdf), Text File (.txt) or read online for free. The document contains details about an assignment on OOP in Java lab for a student named Akash Chakraborty studying in the 8th semester of the iMCA2 stream with student ID 161001102037. It lists 18 questions to write Java programs related to patterns, calculators ...

  20. Assignment 2: Concurrency in Java

    Computer Science questions and answers. Assignment 2: Concurrency in Java - Lab (2%)This assignment relates to the following Course Learning Requirements:CLR 1: Implement an objected-oriented program design incorporating the use of best practice design patterns using the JAVA programming language.CLR 2: Understand multithreading concepts ...

  21. Solve Java

    Java Stdin and Stdout I. Easy Java (Basic) Max Score: 5 Success Rate: 96.86%. Solve Challenge. Java If-Else. Easy Java (Basic) Max Score: 10 Success Rate: 91.36%. Solve Challenge. Java Stdin and Stdout II. Easy Java (Basic) Max Score: 10 Success Rate: 92.69%. Solve Challenge. Java Output Formatting.

  22. Java lab Expt-05

    Module II - Object oriented design - II. Java Programming100% (1) 18. Java-Cheat-Sheet - Nothing. Java Programming100% (1) 47. LAB Manual Core Java - Lab manuual. Java Programming100% (1) Java lab assignments name: sahil anil gamre. department: information technology. division: roll no: 28 subject: java lab experiment aim: create class with three.

  23. Solved Lab Assignment (100 points): n this lab, you will

    Computer Science questions and answers; Lab Assignment (100 points): n this lab, you will demonstrate your understanding of Java undamentals and methods. There are TWO programs to be ompleted. . For this program, you can write all steps in the main(), or in separate methods.