Java Coding Practice

java assignments

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 assignments

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 assignments

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:

  • Java Course
  • 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 Assignment Operators with Examples

Operators constitute the basic building block of any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they provide.

Types of Operators: 

  • Arithmetic Operators
  • Unary Operators
  • Assignment Operator
  • Relational Operators
  • Logical Operators
  • Ternary Operator
  • Bitwise Operators
  • Shift Operators

This article explains all that one needs to know regarding Assignment Operators. 

Assignment Operators

These operators are used to assign values to a variable. The left side operand of the assignment operator is a variable, and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type of the operand on the left side. Otherwise, the compiler will raise an error. This means that the assignment operators have right to left associativity, i.e., the value given on the right-hand side of the operator is assigned to the variable on the left. Therefore, the right-hand side value must be declared before using it or should be a constant. The general format of the assignment operator is, 

Types of Assignment Operators in Java

The Assignment Operator is generally of two types. They are:

1. Simple Assignment Operator: The Simple Assignment Operator is used with the “=” sign where the left side consists of the operand and the right side consists of a value. The value of the right side must be of the same data type that has been defined on the left side.

2. Compound Assignment Operator: The Compound Operator is used where +,-,*, and / is used along with the = operator.

Let’s look at each of the assignment operators and how they operate: 

1. (=) operator: 

This is the most straightforward assignment operator, which is used to assign the value on the right to the variable on the left. This is the basic definition of an assignment operator and how it functions. 

Syntax:  

Example:  

2. (+=) operator: 

This operator is a compound of ‘+’ and ‘=’ operators. It operates by adding the current value of the variable on the left to the value on the right and then assigning the result to the operand on the left. 

Note: The compound assignment operator in Java performs implicit type casting. Let’s consider a scenario where x is an int variable with a value of 5. int x = 5; If you want to add the double value 4.5 to the integer variable x and print its value, there are two methods to achieve this: Method 1: x = x + 4.5 Method 2: x += 4.5 As per the previous example, you might think both of them are equal. But in reality, Method 1 will throw a runtime error stating the “i ncompatible types: possible lossy conversion from double to int “, Method 2 will run without any error and prints 9 as output.

Reason for the Above Calculation

Method 1 will result in a runtime error stating “incompatible types: possible lossy conversion from double to int.” The reason is that the addition of an int and a double results in a double value. Assigning this double value back to the int variable x requires an explicit type casting because it may result in a loss of precision. Without the explicit cast, the compiler throws an error. Method 2 will run without any error and print the value 9 as output. The compound assignment operator += performs an implicit type conversion, also known as an automatic narrowing primitive conversion from double to int . It is equivalent to x = (int) (x + 4.5) , where the result of the addition is explicitly cast to an int . The fractional part of the double value is truncated, and the resulting int value is assigned back to x . It is advisable to use Method 2 ( x += 4.5 ) to avoid runtime errors and to obtain the desired output.

Same automatic narrowing primitive conversion is applicable for other compound assignment operators as well, including -= , *= , /= , and %= .

3. (-=) operator: 

This operator is a compound of ‘-‘ and ‘=’ operators. It operates by subtracting the variable’s value on the right from the current value of the variable on the left and then assigning the result to the operand on the left. 

4. (*=) operator:

 This operator is a compound of ‘*’ and ‘=’ operators. It operates by multiplying the current value of the variable on the left to the value on the right and then assigning the result to the operand on the left. 

5. (/=) operator: 

This operator is a compound of ‘/’ and ‘=’ operators. It operates by dividing the current value of the variable on the left by the value on the right and then assigning the quotient to the operand on the left. 

6. (%=) operator: 

This operator is a compound of ‘%’ and ‘=’ operators. It operates by dividing the current value of the variable on the left by the value on the right and then assigning the remainder to the operand on the left. 

Please Login to comment...

Similar reads.

  • Java-Operators

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

  • ▼Java Exercises
  • ▼Java Basics
  • Basic Part-I
  • Basic Part-II
  • ▼Java Data Types
  • Java Enum Types
  • ▼Java Control Flow
  • Conditional Statement
  • Recursive Methods
  • ▼Java Math and Numbers
  • ▼Object Oriented Programming
  • Java Constructor
  • Java Static Members
  • Java Nested Classes
  • Java Inheritance
  • Java Abstract Classes
  • Java Interface
  • Java Encapsulation
  • Java Polymorphism
  • Object-Oriented Programming
  • ▼Exception Handling
  • Exception Handling Home
  • ▼Functional Programming
  • Java Lambda expression
  • ▼Multithreading
  • Java Thread
  • Java Multithreading
  • ▼Data Structures
  • ▼Strings and I/O
  • File Input-Output
  • ▼Date and Time
  • ▼Advanced Concepts
  • Java Generic Method
  • ▼Algorithms
  • ▼Regular Expressions
  • Regular Expression Home
  • ▼JavaFx Exercises
  • JavaFx Exercises Home
  • ..More to come..

Java Basic Programming : Exercises, Practice, Solution

Java basic exercises [150 exercises with solution].

[ An editor is available at the bottom of the page to write and execute the scripts.   Go to the editor ]

1. Write a Java program to print 'Hello' on screen and your name on a separate line. Expected Output : Hello Alexandra Abramov

Click me to see the solution

2. Write a Java program to print the sum of two numbers. Test Data: 74 + 36 Expected Output : 110

3. Write a Java program to divide two numbers and print them on the screen. Test Data : 50/3 Expected Output : 16

4. Write a Java program to print the results of the following operations. Test Data: a. -5 + 8 * 6 b. (55+9) % 9 c. 20 + -3*5 / 8 d. 5 + 15 / 3 * 2 - 8 % 3 Expected Output : 43 1 19 13

5. Write a Java program that takes two numbers as input and displays the product of two numbers. Test Data: Input first number: 25 Input second number: 5 Expected Output : 25 x 5 = 125

6. Write a Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers. Test Data: Input first number: 125 Input second number: 24 Expected Output : 125 + 24 = 149 125 - 24 = 101 125 x 24 = 3000 125 / 24 = 5 125 mod 24 = 5

7. Write a Java program that takes a number as input and prints its multiplication table up to 10. Test Data: Input a number: 8 Expected Output : 8 x 1 = 8 8 x 2 = 16 8 x 3 = 24 ... 8 x 10 = 80

8. Write a Java program to display the following pattern. Sample Pattern :

9. Write a Java program to compute the specified expressions and print the output. Test Data: ((25.5 * 3.5 - 3.5 * 3.5) / (40.5 - 4.5)) Expected Output 2.138888888888889

10. Write a Java program to compute a specified formula. Specified Formula : 4.0 * (1 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11)) Expected Output 2.9760461760461765

11. Write a Java program to print the area and perimeter of a circle. Test Data: Radius = 7.5 Expected Output Perimeter is = 47.12388980384689 Area is = 176.71458676442586

12. Write a Java program that takes three numbers as input to calculate and print the average of the numbers. Click me to see the solution

13. Write a Java program to print the area and perimeter of a rectangle. Test Data: Width = 5.5 Height = 8.5

Expected Output Area is 5.6 * 8.5 = 47.60 Perimeter is 2 * (5.6 + 8.5) = 28.20

14. Write a Java program to print an American flag on the screen. Expected Output

15. Write a Java program to swap two variables. Click me to see the solution

16. Write a Java program to print a face. Expected Output

17. Write a Java program to add two binary numbers. Input Data: Input first binary number: 10 Input second binary number: 11 Expected Output

18. Write a Java program to multiply two binary numbers. Input Data: Input the first binary number: 10 Input the second binary number: 11 Expected Output

19. Write a Java program to convert an integer number to a binary number. Input Data: Input a Decimal Number : 5 Expected Output

20. Write a Java program to convert a decimal number to a hexadecimal number. Input Data: Input a decimal number: 15 Expected Output

21. Write a Java program to convert a decimal number to an octal number. Input Data: Input a Decimal Number: 15 Expected Output

22. Write a Java program to convert a binary number to a decimal number. Input Data: Input a binary number: 100 Expected Output

23. Write a Java program to convert a binary number to a hexadecimal number. Input Data: Input a Binary Number: 1101 Expected Output

24. Write a Java program to convert a binary number to an octal number. Input Data: Input a Binary Number: 111 Expected Output

25. Write a Java program to convert a octal number to a decimal number. Input Data: Input any octal number: 10 Expected Output

26. Write a Java program to convert a octal number to a binary number. Input Data: Input any octal number: 7 Expected Output

27. Write a Java program to convert a octal number to a hexadecimal number. Input Data: Input a octal number : 100 Expected Output

28. Write a Java program to convert a hexadecimal value into a decimal number. Input Data: Input a hexadecimal number: 25 Expected Output

29. Write a Java program to convert a hexadecimal number into a binary number. Input Data: Enter Hexadecimal Number : 37 Expected Output

30. Write a Java program to convert a hexadecimal value into an octal number. Input Data: Input a hexadecimal number: 40 Expected Output

31. Write a Java program to check whether Java is installed on your computer. Expected Output

32. Write a Java program to compare two numbers. Input Data: Input first integer: 25 Input second integer: 39 Expected Output

33. Write a Java program and compute the sum of an integer's digits. Input Data: Input an integer: 25 Expected Output

34. Write a Java program to compute hexagon area. Area of a hexagon = (6 * s^2)/(4*tan(π/6)) where s is the length of a side Input Data: Input the length of a side of the hexagon: 6 Expected Output

35. Write a Java program to compute the area of a polygon. Area of a polygon = (n*s^2)/(4*tan(π/n)) where n is n-sided polygon and s is the length of a side Input Data: Input the number of sides on the polygon: 7 Input the length of one of the sides: 6 Expected Output

36. Write a Java program to compute the distance between two points on the earth's surface. Distance between the two points [ (x1,y1) & (x2,y2)] d = radius * arccos(sin(x1) * sin(x2) + cos(x1) * cos(x2) * cos(y1 - y2)) Radius of the earth r = 6371.01 Kilometers Input Data: Input the latitude of coordinate 1: 25 Input the longitude of coordinate 1: 35 Input the latitude of coordinate 2: 35.5 Input the longitude of coordinate 2: 25.5 Expected Output

37. Write a Java program to reverse a string. Input Data: Input a string: The quick brown fox Expected Output

38. Write a Java program to count letters, spaces, numbers and other characters in an input string. Expected Output

39. Write a Java program to create and display a unique three-digit number using 1, 2, 3, 4. Also count how many three-digit numbers are there. Expected Output

40. Write a Java program to list the available character sets in charset objects. Expected Output

41. Write a Java program to print the ASCII value of a given character. Expected Output

42. Write a Java program to input and display your password. Expected Output

43. Write a Java program to print the following string in a specific format (see output). Sample Output

44. Write a Java program that accepts an integer (n) and computes the value of n+nn+nnn. Sample Output:

45. Write a Java program to find the size of a specified file. Sample Output:

46. Write a Java program to display system time. Sample Output:

47. Write a Java program to display the current date and time in a specific format. Sample Output:

48. Write a Java program to print odd numbers from 1 to 99. Prints one number per line. Sample Output:

49. Write a Java program to accept a number and check whether the number is even or not. Prints 1 if the number is even or 0 if odd. Sample Output:

50. Write a Java program to print numbers between 1 and 100 divisible by 3, 5 and both. Sample Output:

51. Write a Java program to convert a string to an integer. Sample Output:

52. Write a Java program to calculate the sum of two integers and return true if the sum is equal to a third integer. Sample Output:

53. Write a Java program that accepts three integers from the user. It returns true if the second number is higher than the first number and the third number is larger than the second number. If "abc" is true, the second number does not need to be larger than the first number. Sample Output:

54. Write a Java program that accepts three integers from the user and returns true if two or more of them (integers) have the same rightmost digit. The integers are non-negative. Sample Output:

55. Write a Java program to convert seconds to hours, minutes and seconds. Sample Output:

56. Write a Java program to find the number of values in a given range divisible by a given value. For example x = 5, y=20 and p =3, find the number of integers within the range x..y and that are divisible by p i.e. { i :x ≤ i ≤ y, i mod p = 0 } Sample Output:

57. Write a Java program to accept an integer and count the factors of the number. Sample Output:

58. Write a Java program to capitalize the first letter of each word in a sentence. Sample Output:

59. Write a Java program to convert a string into lowercase. Sample Output:

60. Write a Java program to find the penultimate (next to the last) word in a sentence. Sample Output:

61. Write a Java program to reverse a word. Sample Output:

62. Write a Java program that accepts three integer values and returns true if one is 20 or more less than the others' subtractions. Sample Output:

63. Write a Java program that accepts two integer values from the user and returns the largest value. However if the two values are the same, return 0 and find the smallest value if the two values have the same remainder when divided by 6. Sample Output:

64. Write a Java program that accepts two integer values between 25 and 75 and returns true if there is a common digit in both numbers. Sample Output:

65. Write a Java program to calculate the modules of two numbers without using any inbuilt modulus operator. Sample Output:

66. Write a Java program to compute the sum of the first 100 prime numbers. Sample Output:

67. Write a Java program to insert a word in the middle of another string. Insert "Tutorial" in the middle of "Python 3.0", so the result will be Python Tutorial 3.0. Sample Output:

68. Write a Java program to create another string of 4 copies of the last 3 characters of the original string. The original string length must be 3 and above. Sample Output:

70. Write a Java program to create a string in the form of short_string + long_string + short_string from two strings. The strings must not have the same length. Test Data: Str1 = Python Str2 = Tutorial Sample Output:

71. Write a Java program to create the concatenation of the two strings except removing the first character of each string. The length of the strings must be 1 and above. Test Data: Str1 = Python Str2 = Tutorial Sample Output:

72. Write a Java program to create a string taking the first three characters from a given string. If the string length is less than 3 use "#" as substitute characters. Test Data: Str1 = " " Sample Output:

73. Write a Java program to create a string taking the first and last characters from two given strings. If the length of each string is 0 use "#" for missing characters. Test Data: str1 = "Python" str2 = " " Sample Output:

74. Write a Java program to test if 10 appears as the first or last element of an array of integers. The array length must be broader than or equal to 2. Sample Output: Test Data: array = 10, -20, 0, 30, 40, 60, 10

75. Write a Java program to test if the first and last elements of an array of integers are the same. The array length must be broader than or equal to 2. Test Data: array = 50, -20, 0, 30, 40, 60, 10 Sample Output:

76. Write a Java program to test if the first and last element of two integer arrays are the same. The array length must be greater than or equal to 2. Test Data: array1 = 50, -20, 0, 30, 40, 60, 12 array2 = 45, 20, 10, 20, 30, 50, 11 Sample Output:

77. Write a Java program to create an array of length 2 from two integer arrays with three elements. The newly created array will contain the first and last elements from the two arrays. Test Data: array1 = 50, -20, 0 array2 = 5, -50, 10 Sample Output:

78. Write a Java program to test that a given array of integers of length 2 contains a 4 or a 7. Sample Output:

79. Write a Java program to rotate an array (length 3) of integers in the left direction. Sample Output:

80. Write a Java program to get the largest value between the first and last elements of an array (length 3) of integers. Sample Output:

81. Write a Java program to swap the first and last elements of an array (length must be at least 1) and create another array. Sample Output:

82. Write a Java program to find the largest element between the first, last, and middle values in an array of integers (even length). Sample Output:

83. Write a Java program to multiply the corresponding elements of two integer arrays. Sample Output:

84. Write a Java program to take the last three characters from a given string. It will add the three characters at both the front and back of the string. String length must be greater than three and more. Test data: "Python" will be "honPythonhon" Sample Output:

85. Write a Java program to check if a string starts with a specified word. Sample Data: string1 = "Hello how are you?" Sample Output:

88. Write a Java program to get the current system environment and system properties. Click me to see the solution

89. Write a Java program to check whether a security manager has already been established for the current application or not. Click me to see the solution

90. Write a Java program to get the value of environment variables PATH, TEMP, USERNAME. Click me to see the solution

91. Write a Java program to measure how long code executes in nanoseconds. Click me to see the solution

92. Write a Java program to count the number of even and odd elements in a given array of integers. Click me to see the solution

93. Write a Java program to test if an array of integers contains an element 10 next to 10 or an element 20 next to 20, but not both. Click me to see the solution

94. Write a Java program to rearrange all the elements of a given array of integers so that all the odd numbers come before all the even numbers. Click me to see the solution

95. Write a Java program to create an array (length # 0) of string values. The elements will contain "0", "1", "2" … through ... n-1. Click me to see the solution

96. Write a Java program to check if there is a 10 in an array of integers with a 20 somewhere later on. Click me to see the solution

97. Write a Java program to check if an array of integers contains a specified number next to each other or two same numbers separated by one element. Click me to see the solution

98. Write a Java program to check if the value 20 appears three times and no 20's are next to each other in the array of integers. Click me to see the solution

99. Write a Java program that checks if a specified number appears in every pair of adjacent integers of a given array of integers. Click me to see the solution

100. Write a Java program to count the elements that differ by 1 or less between two given arrays of integers with the same length. Click me to see the solution

101. Write a Java program to determine whether the number 10 in a given array of integers exceeds 20. Click me to see the solution

102. Write a Java program to check if a specified array of integers contains 10 or 30. Click me to see the solution

103. Write a Java program to create an array from a given array of integers. The newly created array will contain elements from the given array after the last element value is 10. Click me to see the solution

104. Write a Java program to create an array from a given array of integers. The newly created array will contain the elements from the given array before the last element value of 10. Click me to see the solution

105. Write a Java program to check if a group of numbers (l) at the start and end of a given array are the same. Click me to see the solution

106. Write a Java program to create an array left shifted from a given array of integers. Click me to see the solution

107. Write a Java program to check if an array of integers contains three increasing adjacent numbers. Click me to see the solution

108. Write a Java program to add all the digits of a given positive integer until the result has a single digit. Click me to see the solution

109. Write a Java program to form a staircase shape of n coins where every k-th row must have exactly k coins. Click me to see the solution

110. Write a Java program to check whether the given integer is a power of 4 or not. Given num = 64, return true. Given num = 6, return false. Click me to see the solution

111. Write a Java program to add two numbers without arithmetic operators. Given x = 10 and y = 12; result = 22 Click me to see the solution

112. Write a Java program to compute the number of trailing zeros in a factorial. 7! = 5040, therefore the output should be 1 Click me to see the solution

113. Write a Java program to merge two given sorted arrays of integers and create another sorted array. array1 = [1,2,3,4] array2 = [2,5,7, 8] result = [1,2,2,3,4,5,7,8] Click me to see the solution

114. Write a Java program that rotates a string by an offset (rotate from left to right. Click me to see the solution

115. Write a Java program to check if a positive number is a palindrome or not. Input a positive integer: 151 Is 151 is a palindrome number? true Click me to see the solution

116. Write a Java program that iterates integers from 1 to 100. For multiples of three print "Fizz" instead of the number and print "Buzz" for five. When the number is divided by three and five, print "fizz buzz". Click me to see the solution

117. Write a Java program to compute the square root of a given number. Input a positive integer: 25 Square root of 25 is: 5 Click me to see the solution

118. Write a Java program to get the first occurrence (Position starts from 0.) of a string within a given string. Click me to see the solution

119. Write a Java program to get the first occurrence (Position starts from 0.) of an element of a given array. Click me to see the solution

120. Write a Java program that searches for a value in an m x n matrix. Click me to see the solution

121. Write a Java program to reverse a linked list. Example: For linked list 20->40->60->80, the reversed linked list is 80->60->40->20 Click me to see the solution

122. Write a Java program to find a contiguous subarray with the largest sum from a given array of integers. Note: In computer science, the maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers which has the largest sum. For example, for the sequence of values −2, 1, −3, 4, −1, 2, 1, −5, 4; the contiguous subarray with the largest sum is 4, −1, 2, 1, with sum 6. The subarray should contain one integer at least. Click me to see the solution

123. Write a Java program to find the subarray with smallest sum from a given array of integers. Click me to see the solution

124. Write a Java program to find the index of a value in a sorted array. If the value does not find return the index where it would be if it were inserted in order. Example: [1, 2, 4, 5, 6] 5(target) -> 3(index) [1, 2, 4, 5, 6] 0(target) -> 0(index) [1, 2, 4, 5, 6] 7(target) -> 5(index) Click me to see the solution

125. Write a Java program to get the preorder traversal of the values of the nodes in a binary tree. Example: 10 / \ 20 30 / \ 40 50 Expected output: 10 20 40 50 30 Click me to see the solution

126. Write a Java program to get the in-order traversal of its nodes' values in a binary tree. 10 / \ 20 30 / \ 40 50 Example:{10, 20, 30, 40, 50} Output: 40 20 50 10 30 Click me to see the solution

127. Write a Java program to get the Postorder traversal of its nodes' values in a binary tree. 10 / \ 20 30 / \ 40 50 Click me to see the solution

128. Write a Java program to calculate the median of a non-sorted array of integers. Original array: [10, 2, 38, 22, 38, 23] Median of the said array of integers: 30 Original array: [10, 2, 38, 23, 38, 23, 21] Median of the said array of integers: 23 Click me to see the solution

129. Write a Java program to find a number that appears only once in a given array of integers. All numbers occur twice. Source Array : [10, 20, 10, 20, 30, 40, 40, 30, 50] 50 appears only once Click me to see the solution

130. Write a Java program to find the maximum depth of a given binary tree. Sample Output: The Maximum depth of the binary tree is: 3 Click me to see the solution

131. Write a Java program to find the updated length of a sorted array where each element appears only once (remove duplicates). Original array: [1, 1, 2, 3, 3, 3, 4, 5, 6, 7, 7] The length of the original array is: 11 After removing duplicates, the new length of the array is: 7 Click me to see the solution

132. Write a Java program to find the updated length of a given sorted array where duplicate elements appear at most twice. Original array: [1, 1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7, 7] The length of the original array is: 13 After removing duplicates, the new length of the array is: 10 Click me to see the solution

133. Write a Java program to find a path from top left to bottom in the right direction which minimizes the sum of all numbers along its path. Note: Move either down or right at any point in time. Sample Output: Sum of all numbers along its path: 13 Click me to see the solution

134. Write a Java program to find distinct ways to climb to the top (n steps to reach the top) of stairs. Each time you climb, you can climb 1 or 2 steps. Example: n = 5 a) 1+1+1+1+1 = 5 b) 1+1+1+2 = 5 c) 1+2+2 = 5 d) 2+2+1 = 5 e) 2+1+1+1 = 5 f) 2+1+2 = 5 g) 1+2+1+1 = 5 h) 1+1+2+1 = 5 Sample Output: Distinct ways can you climb to the top: 8 Click me to see the solution

135. Write a Java program to remove duplicates from a sorted linked list. Original List with duplicate elements: 12->12->13->14->15->15->16->17->17 After removing duplicates from the said list: 12->13->14->15->16->17 Click me to see the solution

136. Write a Java program to find possible distinct paths from the top-left corner to the bottom-right corner of a given grid (m x n). Note: You can move either down or right at any point in time. Sample Output: Unique paths from top-left corner to bottom-right corner of the said grid: 3 Click me to see the solution

137. Write a Java program to find possible unique paths considering some obstacles, from top-left corner to bottom-right corner of a given grid (m x n). Note: You can move either down or right at any point in time and an obstacle and empty space is marked as 1 and 0 respectively in the grid. Sample grid: int[][] obstacle_Grid ={ {0, 0, 0}, {0, 1, 0}, {0, 0, 0}, }; Sample Output: Unique paths from top-left corner to bottom-right corner of the said grid (considering some obstacles): 2 Click me to see the solution

138. Write a Java program to find the longest words in a dictionary. Example-1: { "cat", "flag", "green", "country", "w3resource" } Result: "w3resource" Example-2: { "cat", "dog", "red", "is", "am" } Result: "cat", "dog", "red" Click me to see the solution

139. Write a Java program to get the index of the first and the last number of a subarray where the sum of numbers is zero. This is from a given array of integers. Original Array : [1, 2, 3, -6, 5, 4] Index of the subarray of the said array where the sum of numbers is zero: [0, 3] Click me to see the solution

140. Write a Java program to merge all overlapping intervals from a given collection of intervals. Sample Output: 1 6 8 10 15 20 Click me to see the solution

141. Write a Java program to check if a given string has all distinct characters. Sample Output: Original String : xyyz String has all unique characters: false Click me to see the solution

142. Write a Java program to check if two strings are anagrams or not. According to Wikipedia "An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, the word anagram can be rearranged into nag a ram, or the word binary into brainy." Sample Output: String-1 : wxyz String-2 : zyxw Check if two given strings are anagrams or not?: true Click me to see the solution

143. Write a Java program to merge the two sorted linked lists. Sample Output: Merge Two Sorted ListsT: 1 2 3 7 9 13 40 Click me to see the solution

144. Write a Java program to remove all occurrences of a specified value in a given array of integers. Return the updated array length. Sample Output: Original array: [1, 4, 6, 7, 6, 2] The length of the new array is: 4 Click me to see the solution

145. Write a Java program to remove the nth element from the end of a given list. Sample Output: Original node: 1 2 3 4 5 After removing 2nd element from end: 1 2 3 5 Click me to see the solution

146. Write a Java program to convert an array of sorted items into a binary search tree. Maintain the minimal height of the tree. Sample Output: 2 1 4 6 5 3 Click me to see the solution

147. Write a Java program to find the number of bits required to flip to convert two given integers. Sample Output: 2 Click me to see the solution

148. Write a Java program to find the index of the first unique character in a given string. Assume that there is at least one unique character in the string. Sample Output: Original String: wresource First unique character of the above: 0 Click me to see the solution

149. Write a Java program to check if a given string is a permutation of another given string. Sample Output: Original strings: xxyz yxzx true Click me to see the solution

150. Write a Java program to test if a binary tree is a subtree of another binary tree. Sample Output: Original strings: xxyz yxzx true Click me to see the solution

Java Code Editor:

More to Come !

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

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases. See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.

Assignment, Arithmetic, and Unary Operators

The simple assignment operator.

One of the most common operators that you'll encounter is the simple assignment operator " = ". You saw this operator in the Bicycle class; it assigns the value on its right to the operand on its left:

This operator can also be used on objects to assign object references , as discussed in Creating Objects .

The Arithmetic Operators

The Java programming language provides operators that perform addition, subtraction, multiplication, and division. There's a good chance you'll recognize them by their counterparts in basic mathematics. The only symbol that might look new to you is " % ", which divides one operand by another and returns the remainder as its result.

Operator Description
Additive operator (also used for String concatenation)
Subtraction operator
Multiplication operator
Division operator
Remainder operator

The following program, ArithmeticDemo , tests the arithmetic operators.

This program prints the following:

You can also combine the arithmetic operators with the simple assignment operator to create compound assignments . For example, x+=1; and x=x+1; both increment the value of x by 1.

The + operator can also be used for concatenating (joining) two strings together, as shown in the following ConcatDemo program:

By the end of this program, the variable thirdString contains "This is a concatenated string.", which gets printed to standard output.

The Unary Operators

The unary operators require only one operand; they perform various operations such as incrementing/decrementing a value by one, negating an expression, or inverting the value of a boolean.

Operator Description
Unary plus operator; indicates positive value (numbers are positive without this, however)
Unary minus operator; negates an expression
Increment operator; increments a value by 1
Decrement operator; decrements a value by 1
Logical complement operator; inverts the value of a boolean

The following program, UnaryDemo , tests the unary operators:

The increment/decrement operators can be applied before (prefix) or after (postfix) the operand. The code result++; and ++result; will both end in result being incremented by one. The only difference is that the prefix version ( ++result ) evaluates to the incremented value, whereas the postfix version ( result++ ) evaluates to the original value. If you are just performing a simple increment/decrement, it doesn't really matter which version you choose. But if you use this operator in part of a larger expression, the one that you choose may make a significant difference.

The following program, PrePostDemo , illustrates the prefix/postfix unary increment operator:

About Oracle | Contact Us | Legal Notices | Terms of Use | Your Privacy Rights

Copyright © 1995, 2022 Oracle and/or its affiliates. All rights reserved.

Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.

  • AI assistance for guided coding help
  • Projects to apply new skills
  • Quizzes to test your knowledge
  • A certificate of completion

java assignments

Skill level

Time to complete

Prerequisites

About this course

Popular for its versatility and ability to create a wide variety of applications, learning Java opens up your possibilities when coding. With it, you’ll be able to develop large systems, software, and mobile applications — and even create mobile apps for Android. Learn important Java coding fundamentals and practice your new skills with real-world projects.

Skills you'll gain

Build core programming concepts

Learn object-oriented concepts

Create Java projects

Hello World

Welcome to the world of Java programming! Java is a popular object-oriented programming language that is used in many different industries.

Learn about datatypes in Java and how we use them. Then, practice your skills with two projects where you create and manipulate variables.

Object-Oriented Java

Learn about object-oriented programming in Java. Explore syntax for defining classes and creating instances.

Conditionals and Control Flow

Conditionals and control flow in Java programs.

Arrays and ArrayLists

Build lists of data with Java arrays and ArrayLists.

Use loops to iterate through lists and repeat code.

String Methods

The Java String class provides a lot of useful methods for performing operations on strings and data manipulation.

Certificate of completion available with Plus or Pro

The platform

Hands-on learning

An AI-generated hint within the instructions of a Codecademy project

Projects in this course

Planting a tree, java variables: mad libs, earn a certificate of completion.

  • Show proof Receive a certificate that demonstrates you've completed a course or path.
  • Build a collection The more courses and paths you complete, the more certificates you collect.
  • Share with your network Easily add certificates of completion to your LinkedIn profile to share your accomplishments.

java assignments

Learn Java course ratings and reviews

  • 5 stars 59%
  • 4 stars 28%

Our learners work at

  • Google Logo
  • Amazon Logo
  • Microsoft Logo
  • Reddit Logo
  • Spotify Logo
  • YouTube Logo
  • Instagram Logo

Frequently asked questions about Java

What is java.

Java is an open-source, general-purpose programming language known for its versatility and stability. It’s used for everything from building websites to operating systems and wearable devices. You can even find Java in outer space, running the Mars rover.

What does Java do?

What kind of jobs can java get me, are java and javascript the same, what do i need to know before learning java, join over 50 million learners and start learn java today, looking for something else, related resources, java and the command line, java program structure, java style guide, related courses and paths, study for the ap computer science a exam (java), intro to java, java for programmers, browse more topics.

  • Cloud Computing 2,108,893 learners enrolled
  • Mobile Development 1,260,951 learners enrolled
  • Code Foundations 7,043,228 learners enrolled
  • For Business 3,086,129 learners enrolled
  • Computer Science 5,489,876 learners enrolled
  • Java 1,121,194 learners enrolled
  • Web Development 4,705,343 learners enrolled
  • Data Science 4,224,770 learners enrolled
  • Python 3,415,008 learners enrolled

Two people in conversation while learning to code with Codecademy on their laptops

Unlock additional features with a paid plan

Practice projects, assessments, certificate of completion.

Browse Course Material

Course info, instructors.

  • Adam Marcus

Departments

  • Electrical Engineering and Computer Science

As Taught In

  • Programming Languages
  • Software Design and Engineering

Learning Resource Types

Introduction to programming in java, course description.

This course is an introduction to software engineering, using the Java™ programming language. It covers concepts useful to 6.005. Students will learn the fundamentals of Java. The focus is on developing high quality, working software that solves real problems.

The course is designed for students with some programming …

The course is designed for students with some programming experience, but if you have none and are motivated you will do fine. Students who have taken 6.005 should not take this course. Each class is composed of one hour of lecture and one hour of assisted lab work.

This course is offered during the Independent Activities Period (IAP), which is a special 4-week term at MIT that runs from the first week of January until the end of the month.

A set of two images based on a small cup. Primitives fit into the cup, and objects don't.

You are leaving MIT OpenCourseWare

Javatpoint Logo

Java Tutorial

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

JavaTpoint

Java is a popular programming language that software developers use to construct a wide range of applications. It is a simple, robust, and platform-independent object-oriented language. There are various types of assignment operators in Java, each with its own function.

In this section, we will look at Java's many types of assignment operators, how they function, and how they are utilized.

To assign a value to a variable, use the basic assignment operator (=). It is the most fundamental assignment operator in Java. It assigns the value on the right side of the operator to the variable on the left side.

In the above example, the variable x is assigned the value 10.

To add a value to a variable and subsequently assign the new value to the same variable, use the addition assignment operator (+=). It takes the value on the right side of the operator, adds it to the variable's existing value on the left side, and then assigns the new value to the variable.

To subtract one numeric number from another, use the subtraction operator. All numeric data types, including integers and floating-point values, can be utilised with it. Here's an illustration:

In this example, we create two integer variables, a and b, subtract b from a, and then assign the result to the variable c.

To combine two numerical numbers, use the multiplication operator. All numeric data types, including integers and floating-point values, can be utilised with it. Here's an illustration:

In this example, we declare two integer variables, a and b, multiply their values using the multiplication operator, and then assign the outcome to the third variable, c.

To divide one numerical number by another, use the division operator. All numeric data types, including integers and floating-point values, can be utilised with it. Here's an illustration:

In this example, we declare two integer variables, a and b, divide them by one another using the division operator, and then assign the outcome to the variable c.

It's vital to remember that when two numbers are divided, the outcome will also be an integer, and any residual will be thrown away. For instance:

The modulus assignment operator (%=) computes the remainder of a variable divided by a value and then assigns the resulting value to the same variable. It takes the value on the right side of the operator, divides it by the current value of the variable on the left side, and then assigns the new value to the variable on the left side.





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

Get the Reddit app

A subreddit for all questions related to programming in any language.

I give you the best 200+ assignments I have ever created (Java)

I'm a public school teacher who has taught the basics of programming to nearly 2,000 ordinary students over the past fifteen years.

I have seen a lot of coding tutorials online, but most of them go too fast ! Maybe some people can learn variables and loops and functions all in one day, but not my students.

So after some prompting from my wife, I've finally decided to post a link to the 200+ assignments I have used to teach Java to my own classes.

I almost never lecture.

Students learn programming by DOING it.

They work through the assignments at their own pace.

Each assignment is only SLIGHTLY harder than the previous one.

The concepts move at normal person speed.

Hopefully the programs are at least somewhat interesting.

Anyway, I'll be happy to help anyone get started. Installing the Java compiler (JDK) and getting your first program to compile is BY FAR the hardest part.

My assignments are at programmingbydoing.com .

Cheers, and thanks for reading this far.

-Graham "holyteach" Mitchell

tl;dr - If you've tried to teach yourself to code but quickly got lost and frustrated, then my assignments might be for you.

Edit : Wow! Thanks so much for all the support. I knew my assignments were great for my own students, but it is good to hear others enjoy them, too. Some FAQs:

I've created r/programmingbydoing . Feel free to post questions and help each other out there.

No, there are currently no solutions available. My current students use these assignments, too.

I'm sorry some of the assignments are a bit unclear. I do lecture sometimes, and I didn't write all of the assignments.

By continuing, you agree to our User Agreement and acknowledge that you understand the Privacy Policy .

Enter the 6-digit code from your authenticator app

You’ve set up two-factor authentication for this account.

Enter a 6-digit backup code

Create your username and password.

Reddit is anonymous, so your username is what you’ll go by here. Choose wisely—because once you get a name, you can’t change it.

Reset your password

Enter your email address or username and we’ll send you a link to reset your password

Check your inbox

An email with a link to reset your password was sent to the email address associated with your account

Choose a Reddit account to continue

Java Assignment Operators

Java programming tutorial index.

The Java Assignment Operators are used when you want to assign a value to the expression. The assignment operator denoted by the single equal sign = .

In a Java assignment statement, any expression can be on the right side and the left side must be a variable name. For example, this does not mean that "a" is equal to "b", instead, it means assigning the value of 'b' to 'a'. It is as follows:

Java also has the facility of chain assignment operators, where we can specify a single value for multiple variables.

Java Assignment Operators

OperatorsExampleExplanation
=x = 9Value 25 is assigned to x
+=x += 9This is same as x = x + 9
-=x -= 9This is same as x = x – 9
*=x *= 9This is same as x = x * 9
/=x /= 9This is same as x = x / 9
%=x %= 9This is same as x = x % 9

Java Assignment Operators example

Learn Java practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn java interactively, java introduction.

  • Get Started With Java
  • Your First Java Program
  • Java Comments

Java Fundamentals

  • Java Variables and Literals
  • Java Data Types (Primitive)

Java Operators

  • Java Basic Input and Output
  • Java Expressions, Statements and Blocks

Java Flow Control

  • Java if...else Statement

Java Ternary Operator

  • Java for Loop
  • Java for-each Loop
  • Java while and do...while Loop
  • Java break Statement
  • Java continue Statement
  • Java switch Statement
  • Java Arrays
  • Java Multidimensional Arrays
  • Java Copy Arrays

Java OOP(I)

  • Java Class and Objects
  • Java Methods
  • Java Method Overloading
  • Java Constructors
  • Java Static Keyword
  • Java Strings
  • Java Access Modifiers
  • Java this Keyword
  • Java final keyword
  • Java Recursion

Java instanceof Operator

Java OOP(II)

  • Java Inheritance
  • Java Method Overriding
  • Java Abstract Class and Abstract Methods
  • Java Interface
  • Java Polymorphism
  • Java Encapsulation

Java OOP(III)

  • Java Nested and Inner Class
  • Java Nested Static Class
  • Java Anonymous Class
  • Java Singleton Class
  • Java enum Constructor
  • Java enum Strings
  • Java Reflection
  • Java Package
  • Java Exception Handling
  • Java Exceptions
  • Java try...catch
  • Java throw and throws
  • Java catch Multiple Exceptions
  • Java try-with-resources
  • Java Annotations
  • Java Annotation Types
  • Java Logging
  • Java Assertions
  • Java Collections Framework
  • Java Collection Interface
  • Java ArrayList
  • Java Vector
  • Java Stack Class
  • Java Queue Interface
  • Java PriorityQueue
  • Java Deque Interface
  • Java LinkedList
  • Java ArrayDeque
  • Java BlockingQueue
  • Java ArrayBlockingQueue
  • Java LinkedBlockingQueue
  • Java Map Interface
  • Java HashMap
  • Java LinkedHashMap
  • Java WeakHashMap
  • Java EnumMap
  • Java SortedMap Interface
  • Java NavigableMap Interface
  • Java TreeMap
  • Java ConcurrentMap Interface
  • Java ConcurrentHashMap
  • Java Set Interface
  • Java HashSet Class
  • Java EnumSet
  • Java LinkedHashSet
  • Java SortedSet Interface
  • Java NavigableSet Interface
  • Java TreeSet
  • Java Algorithms
  • Java Iterator Interface
  • Java ListIterator Interface

Java I/o Streams

  • Java I/O Streams
  • Java InputStream Class
  • Java OutputStream Class
  • Java FileInputStream Class
  • Java FileOutputStream Class
  • Java ByteArrayInputStream Class
  • Java ByteArrayOutputStream Class
  • Java ObjectInputStream Class
  • Java ObjectOutputStream Class
  • Java BufferedInputStream Class
  • Java BufferedOutputStream Class
  • Java PrintStream Class

Java Reader/Writer

  • Java File Class
  • Java Reader Class
  • Java Writer Class
  • Java InputStreamReader Class
  • Java OutputStreamWriter Class
  • Java FileReader Class
  • Java FileWriter Class
  • Java BufferedReader
  • Java BufferedWriter Class
  • Java StringReader Class
  • Java StringWriter Class
  • Java PrintWriter Class

Additional Topics

  • Java Keywords and Identifiers

Java Operator Precedence

Java Bitwise and Shift Operators

  • Java Scanner Class
  • Java Type Casting
  • Java Wrapper Class
  • Java autoboxing and unboxing
  • Java Lambda Expressions
  • Java Generics
  • Nested Loop in Java
  • Java Command-Line Arguments

Java Tutorials

  • Java Math IEEEremainder()

Operators are symbols that perform operations on variables and values. For example, + is an operator used for addition, while * is also an operator used for multiplication.

Operators in Java can be classified into 5 types:

  • Arithmetic Operators
  • Assignment Operators
  • Relational Operators
  • Logical Operators
  • Unary Operators
  • Bitwise Operators

1. Java Arithmetic Operators

Arithmetic operators are used to perform arithmetic operations on variables and data. For example,

Here, the + operator is used to add two variables a and b . Similarly, there are various other arithmetic operators in Java.

Operator Operation
Addition
Subtraction
Multiplication
Division
Modulo Operation (Remainder after division)

Example 1: Arithmetic Operators

In the above example, we have used + , - , and * operators to compute addition, subtraction, and multiplication operations.

/ Division Operator

Note the operation, a / b in our program. The / operator is the division operator.

If we use the division operator with two integers, then the resulting quotient will also be an integer. And, if one of the operands is a floating-point number, we will get the result will also be in floating-point.

% Modulo Operator

The modulo operator % computes the remainder. When a = 7 is divided by b = 4 , the remainder is 3 .

Note : The % operator is mainly used with integers.

2. Java Assignment Operators

Assignment operators are used in Java to assign values to variables. For example,

Here, = is the assignment operator. It assigns the value on its right to the variable on its left. That is, 5 is assigned to the variable age .

Let's see some more assignment operators available in Java.

Operator Example Equivalent to

Example 2: Assignment Operators

3. java relational operators.

Relational operators are used to check the relationship between two operands. For example,

Here, < operator is the relational operator. It checks if a is less than b or not.

It returns either true or false .

Operator Description Example
Is Equal To returns
Not Equal To returns
Greater Than returns
Less Than returns
Greater Than or Equal To returns
Less Than or Equal To returns

Example 3: Relational Operators

Note : Relational operators are used in decision making and loops.

4. Java Logical Operators

Logical operators are used to check whether an expression is true or false . They are used in decision making.

Operator Example Meaning
(Logical AND) expression1 expression2 only if both and are
(Logical OR) expression1 expression2 if either or is
(Logical NOT) expression if is and vice versa

Example 4: Logical Operators

Working of Program

  • (5 > 3) && (8 > 5) returns true because both (5 > 3) and (8 > 5) are true .
  • (5 > 3) && (8 < 5) returns false because the expression (8 < 5) is false .
  • (5 < 3) || (8 > 5) returns true because the expression (8 > 5) is true .
  • (5 > 3) || (8 < 5) returns true because the expression (5 > 3) is true .
  • (5 < 3) || (8 < 5) returns false because both (5 < 3) and (8 < 5) are false .
  • !(5 == 3) returns true because 5 == 3 is false .
  • !(5 > 3) returns false because 5 > 3 is true .

5. Java Unary Operators

Unary operators are used with only one operand. For example, ++ is a unary operator that increases the value of a variable by 1 . That is, ++5 will return 6 .

Different types of unary operators are:

Operator Meaning
: not necessary to use since numbers are positive without using it
: inverts the sign of an expression
: increments value by 1
: decrements value by 1
: inverts the value of a boolean
  • Increment and Decrement Operators

Java also provides increment and decrement operators: ++ and -- respectively. ++ increases the value of the operand by 1 , while -- decrease it by 1 . For example,

Here, the value of num gets increased to 6 from its initial value of 5 .

Example 5: Increment and Decrement Operators

In the above program, we have used the ++ and -- operator as prefixes (++a, --b) . We can also use these operators as postfix (a++, b++) .

There is a slight difference when these operators are used as prefix versus when they are used as a postfix.

To learn more about these operators, visit increment and decrement operators .

6. Java Bitwise Operators

Bitwise operators in Java are used to perform operations on individual bits. For example,

Here, ~ is a bitwise operator. It inverts the value of each bit ( 0 to 1 and 1 to 0 ).

The various bitwise operators present in Java are:

Operator Description
Bitwise Complement
Left Shift
Right Shift
Unsigned Right Shift
Bitwise AND
Bitwise exclusive OR

These operators are not generally used in Java. To learn more, visit Java Bitwise and Bit Shift Operators .

Other operators

Besides these operators, there are other additional operators in Java.

The instanceof operator checks whether an object is an instanceof a particular class. For example,

Here, str is an instance of the String class. Hence, the instanceof operator returns true . To learn more, visit Java instanceof .

The ternary operator (conditional operator) is shorthand for the if-then-else statement. For example,

Here's how it works.

  • If the Expression is true , expression1 is assigned to the variable .
  • If the Expression is false , expression2 is assigned to the variable .

Let's see an example of a ternary operator.

In the above example, we have used the ternary operator to check if the year is a leap year or not. To learn more, visit the Java ternary operator .

Now that you know about Java operators, it's time to know about the order in which operators are evaluated. To learn more, visit Java Operator Precedence .

Table of Contents

  • Introduction
  • Java Arithmetic Operators
  • Java Assignment Operators
  • Java Relational Operators
  • Java Logical Operators
  • Java Unary Operators
  • Java Bitwise Operators

Sorry about that.

Related Tutorials

Java Tutorial

java assignments

Java Tutorial

Java methods, java classes, java file handling, java how to's, java reference, java examples, java operators.

Operators are used to perform operations on variables and values.

In the example below, we use the + operator to add together two values:

Try it Yourself »

Although the + operator is often used to add together two values, like in the example above, it can also be used to add together a variable and a value, or a variable and another variable:

Java divides the operators into the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Bitwise operators

Arithmetic Operators

Arithmetic operators are used to perform common mathematical operations.

Operator Name Description Example Try it
+ Addition Adds together two values x + y
- Subtraction Subtracts one value from another x - y
* Multiplication Multiplies two values x * y
/ Division Divides one value by another x / y
% Modulus Returns the division remainder x % y
++ Increment Increases the value of a variable by 1 ++x
-- Decrement Decreases the value of a variable by 1 --x

Advertisement

Java Assignment Operators

Assignment operators are used to assign values to variables.

In the example below, we use the assignment operator ( = ) to assign the value 10 to a variable called x :

The addition assignment operator ( += ) adds a value to a variable:

A list of all assignment operators:

Operator Example Same As Try it
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
&= x &= 3 x = x & 3
|= x |= 3 x = x | 3
^= x ^= 3 x = x ^ 3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3

Java Comparison Operators

Comparison operators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions.

The return value of a comparison is either true or false . These values are known as Boolean values , and you will learn more about them in the Booleans and If..Else chapter.

In the following example, we use the greater than operator ( > ) to find out if 5 is greater than 3:

Operator Name Example Try it
== Equal to x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y

Java Logical Operators

You can also test for true or false values with logical operators.

Logical operators are used to determine the logic between variables or values:

Operator Name Description Example Try it
&&  Logical and Returns true if both statements are true x < 5 &&  x < 10
||  Logical or Returns true if one of the statements is true x < 5 || x < 4
! Logical not Reverse the result, returns false if the result is true !(x < 5 && x < 10)

Java Bitwise Operators

Bitwise operators are used to perform binary logic with the bits of an integer or long integer.

Operator Description Example Same as Result Decimal
& AND - Sets each bit to 1 if both bits are 1 5 & 1 0101 & 0001 0001  1
| OR - Sets each bit to 1 if any of the two bits is 1 5 | 1 0101 | 0001 0101  5
~ NOT - Inverts all the bits ~ 5  ~0101 1010  10
^ XOR - Sets each bit to 1 if only one of the two bits is 1 5 ^ 1 0101 ^ 0001 0100  4
<< Zero-fill left shift - Shift left by pushing zeroes in from the right and letting the leftmost bits fall off 9 << 1 1001 << 1 0010 2
>> Signed right shift - Shift right by pushing copies of the leftmost bit in from the left and letting the rightmost bits fall off 9 >> 1 1001 >> 1 1100 12
>>> Zero-fill right shift - Shift right by pushing zeroes in from the left and letting the rightmost bits fall off 9 >>> 1 1001 >>> 1 0100 4

Note: The Bitwise examples above use 4-bit unsigned examples, but Java uses 32-bit signed integers and 64-bit signed long integers. Because of this, in Java, ~5 will not return 10. It will return -6. ~00000000000000000000000000000101 will return 11111111111111111111111111111010

In Java, 9 >> 1 will not return 12. It will return 4. 00000000000000000000000000001001 >> 1 will return 00000000000000000000000000000100

Test Yourself With Exercises

Multiply 10 with 5 , and print the result.

Start the Exercise

Get Certified

COLOR PICKER

colorpicker

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected]

Top Tutorials

Top references, top examples, get certified.

  • Java Operators

Last updated: January 8, 2024

java assignments

Java applications have a notoriously slow startup and a long warmup time. The CRaC (Coordinated Restore at Checkpoint) project from OpenJDK can help improve these issues by creating a checkpoint with an application's peak performance and restoring an instance of the JVM to that point.

To take full advantage of this feature, BellSoft provides containers that are highly optimized for Java applications. These package Alpaquita Linux (a full-featured OS optimized for Java and cloud environment) and Liberica JDK (an open-source Java runtime based on OpenJDK).

These ready-to-use images allow us to easily integrate CRaC in a Spring Boot application:

Improve Java application performance with CRaC support

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, you can get started over on the documentation page .

And, you can also ask questions and leave feedback on the Azure Container Apps GitHub page .

Whether you're just starting out or have years of experience, Spring Boot is obviously a great choice for building a web application.

Jmix builds on this highly powerful and mature Boot stack, allowing devs to build and deliver full-stack web applications without having to code the frontend. Quite flexibly as well, from simple web GUI CRUD applications to complex enterprise solutions.

Concretely, The Jmix Platform includes a framework built on top of Spring Boot, JPA, and Vaadin , and comes with Jmix Studio, an IntelliJ IDEA plugin equipped with a suite of developer productivity tools.

The platform comes with interconnected out-of-the-box add-ons for report generation, BPM, maps, instant web app generation from a DB, and quite a bit more:

>> Become an efficient full-stack developer with Jmix

DbSchema is a super-flexible database designer, which can take you from designing the DB with your team all the way to safely deploying the schema .

The way it does all of that is by using a design model , a database-independent image of the schema, which can be shared in a team using GIT and compared or deployed on to any database.

And, of course, it can be heavily visual, allowing you to interact with the database using diagrams, visually compose queries, explore the data, generate random data, import data or build HTML5 database reports.

>> Take a look at DBSchema

Get non-trivial analysis (and trivial, too!) suggested right inside your IDE or Git platform so you can code smart, create more value, and stay confident when you push.

Get CodiumAI for free and become part of a community of over 280,000 developers who are already experiencing improved and quicker coding.

Write code that works the way you meant it to:

>> CodiumAI. Meaningful Code Tests for Busy Devs

The AI Assistant to boost Boost your productivity writing unit tests - Machinet AI .

AI is all the rage these days, but for very good reason. The highly practical coding companion, you'll get the power of AI-assisted coding and automated unit test generation . Machinet's Unit Test AI Agent utilizes your own project context to create meaningful unit tests that intelligently aligns with the behavior of the code. And, the AI Chat crafts code and fixes errors with ease, like a helpful sidekick.

Simplify Your Coding Journey with Machinet AI :

>> Install Machinet AI in your IntelliJ

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

Download the E-book

Do JSON right with Jackson

Get the most out of the Apache HTTP Client

Get Started with Apache Maven:

Working on getting your persistence layer right with Spring?

Explore the eBook

Building a REST API with Spring?

Get started with Spring and Spring Boot, through the Learn Spring course:

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Get started with Spring and Spring Boot, through the reference Learn Spring course:

>> LEARN SPRING

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth , to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project .

You can explore the course here:

>> Learn Spring Security

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot .

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

1. Overview

Operators are a fundamental building block of any programming language. We use operators to perform operations on values and variables.

Java provides many groups of operators. They are categorized by their functionalities.

In this tutorial, we’ll walk through all Java operators to understand their functionalities and how to use them.

2. Arithmetic Operators

We use arithmetic operators to perform simple mathematical operations. We should note that arithmetic operators only work with primitive number types and their boxed types , such as int and  Integer .

Next, let’s see what operators we have in the arithmetic operator group.

2.1. The Addition Operator

The addition operator (+) allows us to add two values or concatenate two strings:

2.2. The Subtraction Operator

Usually, we use the subtraction operator (-) to subtract one value from another:

2.3. The Multiplication Operator

The multiplication operator (*) is used to multiply two values or variables:

2.4. The Division Operator

The division operator (/) allows us to divide the left-hand value by the right-hand one:

When we use the division operator on two integer values ( byte , short , int , and long ), we should note that the result is the quotient value. The remainder is not included .

As the example above shows, if we calculate 15 / 2 , the quotient is 7, and the remainder is 1 . Therefore, we have 15 / 2 = 7 .

2.5. The Modulo Operator

We can get the quotient using the division operator. However, if we just want to get the remainder of a division calculation, we can use the modulo operator (%):

3. Unary Operators

As the name implies, unary operators only require one single operand . For example, we usually use unary operators to increment, decrement, or negate a variable or value.

Now, let’s see the details of unary operators in Java.

3.1. The Unary Plus Operator

The unary plus operator (+) indicates a positive value. If the number is positive, we can omit the ‘+’ operator:

3.2. The Unary Minus Operator

Opposite to the unary plus operator, the unary minus operator (-) negates a value or an expression:

3.3. The Logical Complement Operator

The logical complement operator (!) is also known as the “NOT” operator . We can use it to invert the value of a boolean variable or value:

3.4. The Increment Operator

The increment operator (++) allows us to increase the value of a variable by 1:

3.5. The Decrement Opeartor

The decrement operator (–) does the opposite of the increment operator. It decreases the value of a variable by 1:

We should keep in mind that the increment and decrement operators can only be used on a variable . For example, “ int a = 5; a++; ” is fine. However, the expression “ 5++ ” won’t be compiled.

4. Relational Operators

Relational operators can be called “comparison operators” as well. Basically, we use these operators to compare two values or variables.

4.1. The “Equal To” Operator

We use the “equal to” operator (==) to compare the values on both sides. If they’re equal, the operation returns true :

The “equal to” operator is pretty straightforward. On the other hand, the Object class has provided the equals() method. As the Object class is the superclass of all Java classes, all Java objects can use the equals() method to compare each other.

When we want to compare two objects – for instance, when we compare Long objects or compare String s –  we should choose between the comparison method from the equals() method and that of the “equal to” operator wisely .

4.2. The “Not Equal To” Operator

The “not equal to” operator (!=) does the opposite of the ‘==’ operator. If the values on both sides are not equal, the operation returns true :

4.3. The “Greater Than” Operator

When we compare two values with the “greater than” operator (>), it returns true if the value on the left-hand side is greater than the value on the right-hand side:

4.4. The “Greater Than or Equal To” Operator

The “greater than or equal to” operator (>=) compares the values on both sides and returns true if the left-hand side operand is greater than or equal to the right-hand side operand:

4.5. The “Less Than” Operator

The “less than” operator (<) compares two values on both sides and returns true if the value on the left-hand side is less than the value on the right-hand side:

4.6. The “Less Than or Equal To” Operator

Similarly, the “less than or equal to” operator (<=) compares the values on both sides and returns true if the left-hand side operand is less than or equal to the right-hand side:

5. Logical Operators

We have two logical operators in Java: the logical AND and OR operators. Basically, their function is pretty similar to the AND gate and the OR gate in digital electronics.

Usually, we use a logical operator with two operands, which are variables or expressions that can be evaluated as boolean .

Next, let’s take a closer look at them.

5.1. The Logical AND Operator

The logical AND operator ( && ) returns true only if both operands are true :

5.2. The Logical OR Operator

Unlike the ‘ && ‘ operator, the logical OR operator ( || ) returns true if at least one operand is  true :

We should note that the logical OR operator has the short-circuiting effect : It returns true as soon as one of the operands is evaluated as true, without evaluating the remaining operands.

6. Ternary Operator

A ternary operator is a short form of the if-then-else statement. It has the name ternary as it has three operands. First, let’s have a look at the standard if-then-else statement syntax:

We can convert the above if-then-else statement into a compact version using the ternary operator:

Let’s look at its syntax:

Next, let’s understand how the ternary operator works through a simple example:

7. Bitwise and Bit Shift Operators

As the article “ Java bitwise operators ” covers the details of bitwise and bit shift operators, we’ll briefly summarize these operators in this tutorial.

7.1. The Bitwise AND Operator

The bitwise AND operator (&) returns the bit-by-bit AND of input values:

7.2. The Bitwise OR Operator

The bitwise OR operator (|) returns the bit-by-bit OR of input values:

7.3. The Bitwise XOR Operator

The bitwise XOR (exclusive OR) operator (^) returns the bit-by-bit XOR of input values:

7.4. The Bitwise Complement Operator

The bitwise complement operator (~) is a unary operator. It returns the value’s complement representation, which inverts all bits from the input value:

7.5. The Left Shift Operator

Shift operators shift the bits to the left or right by the given number of times.

The left shift operator (<<) shifts the bits to the left by the number of times defined by the right-hand side operand. After the left shift, the empty space in the right is filled with 0.

Next, let’s left shift the number 12 twice:

n << x has the same effect of multiplying the number  n  with x power of two.

7.6. The Signed Right Shift Operator

The signed right shift operator (>>) shifts the bits to the right by the number of times defined by the right-hand side operand and fills 0 on voids left as a result.

We should note that the leftmost position after the shifting depends on the sign extension .

Next, let’s do “signed right shift” twice on the numbers 12 and -12 to see the difference:

As the second example above shows, if the number is negative, the leftmost position after each shift will be set by the sign extension.

n >> x has the same effect of dividing the number n by x power of two.

7.7. The Unsigned Right Shift Operator

The unsigned right shift operator (>>>) works in a similar way as the ‘>>’ operator. The only difference is that after a shift, the leftmost bit is set to 0 .

Next, let’s unsigned right shift twice on the numbers 12 and -12 to see the difference:

As we can see in the second example above, the >>> operator fills voids on the left with 0 irrespective of whether the number is positive or negative .

8. The “ instanceof ” Operator

Sometimes, when we have an object, we would like to test if it’s an instance of a given type . The “ instanceof ” operator can help us to do it:

9. Assignment Operators

We use assignment operators to assign values to variables. Next, let’s see which assignment operators we can use in Java.

9.1. The Simple Assignment Operator

The simple assignment operator (=) is a straightforward but important operator in Java. Actually, we’ve used it many times in previous examples. It assigns the value on its right to the operand on its left:

9.2. Compound Assignments

We’ve learned arithmetic operators. We can combine the arithmetic operators with the simple assignment operator to create compound assignments.

For example, we can write “ a = a + 5 ” in a compound way: “ a += 5 “.

Finally, let’s walk through all supported compound assignments in Java through examples:

10. Conclusion

Java provides many groups of operators for different functionalities. In this article, we’ve passed through the operators in Java.

Looking for the ideal Linux distro for running modern Spring apps in the cloud?

Meet Alpaquita Linux : lightweight, secure, and powerful enough to handle heavy workloads.

This distro is specifically designed for running Java apps . It builds upon Alpine and features significant enhancements to excel in high-density container environments while meeting enterprise-grade security standards.

Specifically, the container image size is ~30% smaller than standard options, and it consumes up to 30% less RAM:

>> Try Alpaquita Containers now.

Explore the secure, reliable, and high-performance Test Execution Cloud built for scale. Right in your IDE:

Basically, write code that works the way you meant it to.

AI is all the rage these days, but for very good reason. The highly practical coding companion, you'll get the power of AI-assisted coding and automated unit test generation . Machinet's Unit Test AI Agent utilizes your own project context to create meaningful unit tests that intelligently aligns with the behavior of the code.

Build your API with SPRING - book cover

COMMENTS

  1. Java programming Exercises, Practice, Solution

    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 ...

  2. Introduction to Programming in Java · Computer Science

    Programming assignments. Creative programming assignments that we have used at Princeton. You can explore these resources via the sidebar at left. Introduction to Programming in Java. Our textbook Introduction to Programming in Java [ Amazon · Pearson · InformIT] is an interdisciplinary approach to the traditional CS1 curriculum with Java. We ...

  3. Java Exercises

    Java is a popular programming language that can be used to create various types of applications, such as desktop, web, enterprise, and mobile. Java is also an object-oriented language, which means that it organizes data and behaviour into reusable units called classes and objects. Java is known for its portability, performance, security, and robust

  4. 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.

  5. Java Assignment Operators with Examples

    Note: The compound assignment operator in Java performs implicit type casting. Let's consider a scenario where x is an int variable with a value of 5. int x = 5; If you want to add the double value 4.5 to the integer variable x and print its value, there are two methods to achieve this: Method 1: x = x + 4.5. Method 2: x += 4.5.

  6. Java Exercises

    Get certified by completing the JAVA course. Track your progress - it's free! Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.

  7. Java Basic Programming Exercises

    Write a Java program to compute the area of a polygon. Area of a polygon = (n*s^2)/ (4*tan (π/n)) where n is n-sided polygon and s is the length of a side Input Data: Input the number of sides on the polygon: 7 Input the length of one of the sides: 6 Expected Output. The area is: 130.82084798405722.

  8. Assignments

    This section provides the assignments for the course, supporting files, and a special set of assignment files that can be annotated. Browse Course Material ... GravityCalculator.java 2 FooCorporation 3 Marathon Marathon.java 4 Library Book.java . Library.java . 5 Graphics! initial.png . SimpleDraw.java ...

  9. Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials

    This beginner Java tutorial describes fundamentals of programming in the Java programming language ... The Simple Assignment Operator. One of the most common operators that you'll encounter is the simple assignment operator "=". You saw this operator in the Bicycle class; it assigns the value on its right to the operand on its left: ...

  10. Learn Java

    Popular for its versatility and ability to create a wide variety of applications, learning Java opens up your possibilities when coding. With it, you'll be able to develop large systems, software, and mobile applications — and even create mobile apps for Android. Learn important Java coding fundamentals and practice your new skills with ...

  11. Introduction to Programming in Java

    This course is an introduction to software engineering, using the Java™ programming language. It covers concepts useful to 6.005. Students will learn the fundamentals of Java. The focus is on developing high quality, working software that solves real problems. The course is designed for students with some programming experience, but if you have none and are motivated you will do fine.

  12. Types of Assignment Operators in Java

    To assign a value to a variable, use the basic assignment operator (=). It is the most fundamental assignment operator in Java. It assigns the value on the right side of the operator to the variable on the left side. Example: int x = 10; int x = 10; In the above example, the variable x is assigned the value 10.

  13. All Java Assignment Operators (Explained With Examples)

    The general format of a Java assignment operator is as follows: variable = expression; Explanation: variable: This is the name of the variable to which you want to assign a value. expression: This is the value or result that you want to assign to the variable. The assignment operator (=) is used to assign the value of the expression on the right-hand side to the variable on the left-hand side.

  14. I give you the best 200+ assignments I have ever created (Java)

    A subreddit for all questions related to programming in any language. I give you the best 200+ assignments I have ever created (Java) I'm a public school teacher who has taught the basics of programming to nearly 2,000 ordinary students over the past fifteen years. I have seen a lot of coding tutorials online, but most of them go too fast!

  15. 800+ Java Practice Challenges // Edabit

    How Edabit Works. This is an introduction to how challenges on Edabit work. In the Code tab above you'll see a starter function that looks like this: public static boolean returnTrue () { } All you have to do is type return true; between the curly braces { } and then click the Check button. If you did this correctly, the button will turn re ...

  16. Java Assignment Operators

    Java Assignment Operators. The Java Assignment Operators are used when you want to assign a value to the expression. The assignment operator denoted by the single equal sign =. In a Java assignment statement, any expression can be on the right side and the left side must be a variable name. For example, this does not mean that "a" is equal to ...

  17. Java Assignment operators

    The Java Assignment operators are used to assign the values to the declared variables. The equals ( = ) operator is the most commonly used Java assignment operator. For example: int i = 25; The table below displays all the assignment operators in the Java programming language. Operators.

  18. Java Operators: Arithmetic, Relational, Logical and more

    2. Java Assignment Operators. Assignment operators are used in Java to assign values to variables. For example, int age; age = 5; Here, = is the assignment operator. It assigns the value on its right to the variable on its left. That is, 5 is assigned to the variable age. Let's see some more assignment operators available in Java.

  19. Programming Assignments

    Below are links to a number of creative programming assignments that we've used at Princeton. Some are from COS 126: Introduction to Computer Science; others are from COS 226: Data Structures and Algorithms . The main focus is on scientific, commercial, and recreational applications. The assignments are posed in terms of C or Java, but they ...

  20. Java Tutorial

    Example Get your own Java Server. Click on the "Run example" button to see how it works. We recommend reading this tutorial, in the sequence listed in the left menu. Java is an object oriented language and some concepts may be new. Take breaks when needed, and go over the examples as many times as needed.

  21. Java Operators

    Java Comparison Operators. Comparison operators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions. The return value of a comparison is either true or false. These values are known as Boolean values, and you will learn more about them in the Booleans and If ...

  22. Java Operators

    Next, let's see which assignment operators we can use in Java. 9.1. The Simple Assignment Operator. The simple assignment operator (=) is a straightforward but important operator in Java. Actually, we've used it many times in previous examples. It assigns the value on its right to the operand on its left:

  23. Object Oriented Programming in Java

    Course Opening Title • 0 minutes • Preview module. Welcome (Object Oriented Java Programming: Data Structures and Beyond Specialization) • 3 minutes. Welcome (Object Oriented Programming in Java Specialization) • 1 minute. Project prototype • 4 minutes. Your Path through the Course • 5 minutes.