Java Tutorial

Java methods, java classes, java file handling, java how to, 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.

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:

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:

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:

Java Bitwise Operators

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

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.

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.

Now that you've learned how to declare and initialize variables, you probably want to know how to do something with them. Learning the operators of the Java programming language is a good place to start. Operators are special symbols that perform specific operations on one, two, or three operands , and then return a result.

As we explore the operators of the Java programming language, it may be helpful for you to know ahead of time which operators have the highest precedence. The operators in the following table are listed according to precedence order. The closer to the top of the table an operator appears, the higher its precedence. Operators with higher precedence are evaluated before operators with relatively lower precedence. Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.

In general-purpose programming, certain operators tend to appear more frequently than others; for example, the assignment operator " = " is far more common than the unsigned right shift operator " >>> ". With that in mind, the following discussion focuses first on the operators that you're most likely to use on a regular basis, and ends focusing on those that are less common. Each discussion is accompanied by sample code that you can compile and run. Studying its output will help reinforce what you've just learned.

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

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

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.

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.

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 .

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.

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:

  • 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:

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

Javatpoint Logo

Java Tutorial

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

JavaTpoint

  • 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

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.

Learn to Code, Prepare for Interviews, and Get Hired

01 Career Opportunities

  • Top 50 Java Interview Questions and Answers
  • Java Developer Salary Guide in India – For Freshers & Experienced

02 Beginner

  • Top 50 Java Full Stack Developer Interview Questions and Answers
  • Data Structures in Java
  • Best Java Developer Roadmap 2024
  • Single Inheritance in Java
  • Hierarchical Inheritance in Java
  • Arithmetic operators in Java
  • What are Copy Constructors In Java? Explore Types,Examples & Use
  • Hybrid Inheritance in Java
  • What is a Bitwise Operator in Java? Type, Example and More

Assignment operator in Java

  • Multiple Inheritance in Java
  • Ternary Operator in Java - (With Example)
  • Parameterized Constructor in Java
  • Unary operator in Java
  • Logical operators in Java
  • Relational operators in Java
  • Constructor Chaining in Java
  • do...while Loop in Java
  • Primitive Data Types in Java
  • Java Full Stack Developer Salary
  • for Loop in Java: Its Types and Examples
  • while Loop in Java
  • What is a Package in Java?
  • Constructor Overloading in Java
  • Top 10 Reasons to know why Java is Important?
  • What is Java? A Beginners Guide to Java
  • Differences between JDK, JRE, and JVM: Java Toolkit
  • Variables in Java: Local, Instance and Static Variables
  • Conditional Statements in Java: If, If-Else and Switch Statement
  • Data Types in Java - Primitive and Non-Primitive Data Types
  • What are Operators in Java - Types of Operators in Java ( With Examples )
  • Looping Statements in Java - For, While, Do-While Loop in Java
  • Java VS Python
  • Jump Statements in JAVA - Types of Statements in JAVA (With Examples)
  • Java Arrays: Single Dimensional and Multi-Dimensional Arrays
  • What is String in Java - Java String Types and Methods (With Examples)

03 Intermediate

  • OOPs Concepts in Java: Encapsulation, Abstraction, Inheritance, Polymorphism
  • What is Class in Java? - Objects and Classes in Java {Explained}
  • Access Modifiers in Java: Default, Private, Public, Protected
  • Constructors in Java: Types of Constructors with Examples
  • Abstract Class in Java: Concepts, Examples, and Usage
  • Polymorphism in Java: Compile time and Runtime Polymorphism
  • What is Inheritance in Java: Types of Inheritance in Java
  • What is Exception Handling in Java? Types, Handling, and Common Scenarios

04 Questions

  • Top 50 Java MCQ Questions
  • Top 50 Java 8 Interview Questions and Answers
  • Java Multithreading Interview Questions and Answers 2024

05 Training Programs

  • Java Programming Course
  • C++ Programming Course
  • MERN: Full-Stack Web Developer Certification Training
  • Data Structures and Algorithms Training
  • Assignment Operator In Ja..

Assignment operator in Java

Java Programming For Beginners Free Course

Assignment operators in java: an overview.

We already discussed the Types of Operators in the previous tutorial Java. In this Java tutorial , we will delve into the different types of assignment operators in Java, and their syntax, and provide examples for better understanding. Because Java is a flexible and widely used programming language. Assignment operators play a crucial role in manipulating and assigning values to variables. To further enhance your understanding and application of Java assignment operator's concepts, consider enrolling in the best Java Certification Course .

What are the Assignment Operators in Java?

Assignment operators in Java are used to assign values to variables . They are classified into two main types: simple assignment operator and compound assignment operator.

The general syntax for a simple assignment statement is:

And for a compound assignment statement:

Read More - Advanced Java Interview Questions

Read More - Mostly Asked Java Multithreading Interview Questions

Types of Assignment Operators in Java

  • Simple Assignment Operator: The Simple Assignment Operator is used with the "=" sign, where the operand is on the left side and the value is on the right. The right-side value must be of the same data type as that defined on the left side.
  • Compound Assignment Operator:  Compound assignment operators combine arithmetic operations with assignments. They provide a concise way to perform an operation and assign the result to the variable in one step. The Compound Operator is utilized when +,-,*, and / are used in conjunction with the = operator.

1. Simple Assignment Operator (=):

The equal sign (=) is the basic assignment operator in Java. It is used to assign the value on the right-hand side to the variable on the left-hand side.

Explanation

2. addition assignment operator (+=) :, 3. subtraction operator (-=):, 4. multiplication operator (*=):.

Read More - Java Developer Salary

5. Division Operator (/=):

6. modulus assignment operator (%=):, example of assignment operator in java.

Let's look at a few examples in our Java Playground to illustrate the usage of assignment operators in Java:

  • Unary Operator in Java
  • Arithmetic Operators in Java
  • Relational Operators in Java
  • Logical Operators in Java
  • Ternary Operator in Java

Q1. Can I use multiple assignment operators in a single statement?

Q2. are there any other compound assignment operators in java, q3. how many types of assignment operators.

  • 1. (=) operator
  • 1. (+=) operator
  • 2. (-=) operator
  • 3. (*=) operator
  • 4. (/=) operator
  • 5. (%=) operator

Live Classes Schedule

Can't find convenient schedule? Let us know

About Author

Author image

We use cookies to make interactions with our websites and services easy and meaningful. Please read our Privacy Policy for more details.

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

facebook

You are leaving MIT OpenCourseWare

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

1. Write Hello World Program in Java

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

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

7. Write a Program to Calculate Simple Interest in Java

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

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

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

  • 27. Write a Program for Insertion Sort in Java

28. Java Program for Selection Sort.

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

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

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

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

Topic Wise Java Exercises List

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

Java Practice Problems for Searching Algorithms

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

Java Exercise

Java Practice Programs

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

The solution to the Problem is mentioned below:

Click Here for the Solution

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

Pattern Exercises in Java

Array Exercises in Java

Array Exercises in Java

String Exercises in Java

Strings Exercises in Java

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

Sorting_in_java

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

27. Write a Program for Insertion Sort in Java.

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

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

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

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

Java Exercise – FAQ

1. how to do java projects for beginners.

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

2. Is Java easy for beginners?

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

3. Why Java is used?

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

Please Login to comment...

Similar reads.

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

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

' src=

  • All Courses
  • Privacy Policy

' src=

Swayam Solver

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

assignment 6 java

NPTEL Programming in Java Jan 2024 Week 6 to 12

assignment 6 java

   Please scroll down for latest Programs.  👇 

Week 6 : Programming Assignment 1

Week 6 : programming assignment 2, week 6 : programming assignment 3, week 6 : programming assignment 4, week 6 : programming assignment 5, week 7 : programming assignment 1.

  • a parameterized constructor to initialize the private fields
  • the getter/setter methods for each field

Week 7 : Programming Assignment 2

  • a parameterized constructor to initialize the private field
  • public void deposit(...) // to deposit money
  • public void withdraw(...) // to withdraw money, should print "Insufficient funds!" if not enough money to withdraw
  • public double getBalance() // to return the current balance

Week 7 : Programming Assignment 3

  • a parameterized constructor to initialize the Circle class
  • @Override the area function to compute the area of a circle ( Use Math.PI  for value of pi, not 22/7)
  • @Override the displayInfo() function to print exactly in the format provided by the test cases.

Week 7 : Programming Assignment 4

  • Create a class "Circle" that implements the "Shape" interface and provides its own implementation for calculateArea().
  • Create another class "Rectangle" that implements the "Shape" interface and provides its own implementation for calculateArea().
  • @Override the area function to compute the area of a rectangle

Week 7 : Programming Assignment 5

  • Create a class "FlyingFish" that implements both interfaces and provides its own implementation for fly() and swim()
  • It should have a private variable name, use a constructor to set the value and the functions fly() and swim() to print exactly as given in the test case.

Week 8 : Programming Assignment 1

  • name (String)
  • sound (String)
  • public void makeSound()  - This method should display the name of the animal and the sound it makes.

Week 8 : Programming Assignment 2

Week 8 : programming assignment 3, week 8 : programming assignment 4, week 8 : programming assignment 5, no comments:, post a comment.

Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.

Programming in Java | Week 6

Session: JAN-APR 2024

Course name: Programming In Java

Course Link: Click Here

For answers or latest updates join our telegram channel: Click here to join

These are NPTEL Programming In Java Week 6 Assignment 6 Answers

Q1. What is the output of the following program? a. “Programming In Java” b. Run time error c. Compile time error d. ArithmeticException

Answer: c. Compile time error c. Compile time error

Q2. What is the output of the following program? a. 1 3 b. 1 2 3 4 c. Runtime error d. 1 2

Answer: a. 1 3

Q3. For the program given below, what will be the output after its execution? a. 0 b. true c. 1 d. false

Answer: c. 1

Q4. Which of the following is a correct constructor for a thread object? a. Thread(Runnable a, String str); b. Thread(Runnable a, int priority); c. Thread(Runnable a, ThreadGroup t); d. Thread(int priority);

Answer: a. Thread(Runnable a, String str);

Q5. What is the output of the following program? a. Compiler Error b. “Running” c. Runtime Exception d. No output, but no error

Answer: b. “Running”

Q6. How many threads does the following program run on? a. 0 b. 1 c. 2 d. 3

Answer: c. 2

Q7. In the following java program, what is the NAME of the thread? a. thread b. main c. system d. None of the above

Answer: b. main

Q8. Which of the following line(s) of code is suitable to START a thread at #1? a. Thread t = new Thread(Nptel); b. Thread t = new Thread(Nptel); t.start(); c. Nptel run = new Nptel(); Thread t = new Thread(run); t.start(); d. Thread t = new Thread(); Nptel.run();

Answer: c. Nptel run = new Nptel(); Thread t = new Thread(run); t.start();

Q9. What is the name of the priority of this Thread in this program? a. 1 b. 4 c. 0 d. 5

Answer: d. 5

Q10. What does I/O stand for in Java? a. Input/Output b. Inheritance/Overriding c. Integer/Object d. Iteration/Observation

Answer: a. Input/Output

Programming Assignment

Question 1 Complete the code fragment to read two integer inputs from keyboard and find the quotient and remainder.

Question 2 Complete the code segment to count number of digits in an integer using while loop.

Question 3 Complete the code segment to display the factors of a number n.

Question 4 Complete the code segment to find the standard deviation of the 1-D array. Use the following formula: σ=√(1/N∑N to i=1(X i −μ) 2 ) Here, σ = Population standard deviation N = Number of observations in the population Xi = ith observation in the population μ = Population mean

Question 5 Write a program which will print a pattern of “*” ‘s of height “n”. For example: Input: n = 3 Output: *** ** * ** ***

More Weeks of Programming In Java: Click here

More Nptel Courses: https://progiez.com/nptel-assignment-answers

Session: JULY-DEC 2023

Course Name: Programming In Java

Question 1 Complete the code segment to print the following using the concept of extending the Thread class in Java: —————–OUTPUT——————- Thread is Running. ————————————————-

Question 2 In the following program, a thread class Question62 is created using the Runnable interface Complete the main() to create a thread object of the class Question62 and run the thread. It should print the output as given below. —————–OUTPUT——————- Welcome to Java Week 6 New Question. Main Thread has ended. ————————————————-

Question 3 A part of the Java program is given, which can be completed in many ways, for example using the concept of thread, etc. Follow the given code and complete the program so that your program prints the message “NPTEL Java week-6 new Assignment Q3”. Your program should utilize the given interface/ class.

Question 4 Execution of two or more threads occurs in a random order. The keyword ‘synchronized’ in Java is used to control the execution of thread in a strict sequence. In the following, the program is expected to print the output as given below. Do the necessary use of ‘synchronized’ keyword, so that, the program prints the Final sum as given below: —————–OUTPUT——————- Final sum:6000 ————————————————-

Question 5 Given a snippet of code, add necessary codes to print the following: —————–OUTPUT——————- Name of thread ‘t1’:Thread-0 Name of thread ‘t2’:Thread-1 New name of thread ‘t1’:Week 6 Assignment Q5 New name of thread ‘t2’:Week 6 Assignment Q5 New ————————————————-

More Nptel Courses: Click here

Session: JAN-APR 2023

Course Name: Programming in Java

Q1. Which of the following is NOT TRUE in Java? a. Every thread has a priority. b. JVM allows multiple threads of execution running concurrently. c. Threads with higher priority are executed first. d. You cannot set a maximum priority value that a thread can have.

Answer: d. You cannot set a maximum priority value that a thread can have.

Q2. Consider the following code. Which of the following is TRUE regarding the above code? a. Creating a thread in Java using Runnable interface b. Thread creation by declaring a class to be a subclass of Thread c. Overriding the run method of class Thread d. The class implements the run method.

Answer: a, d

Q3. Which of the following cannot be used to create an instance of Thread? a. By implementing the Runnable interface. b. By extending the Thread class. c. By creating a new class named Thread and calling method run(). d. By importing the Thread class from the related package.

Answer: c, d

Q4. Which method start () will do which of the following? a. Causes this thread to begin execution. b. Either start the execution for new thread or pause an ongoing thread. c. The JVM calls the run method of this thread. d. Recovers a thread from deadlock and begin execution

Answer: d. Recovers a thread from deadlock and begin execution

Q5. Which method start () will do which of the following? a. Causes this thread to begin execution. b. Either start the execution for new thread or pause an ongoing thread. c. The JVM calls the run method of this thread. d. Recovers a thread from deadlock and begin execution

Answer: a, c

Q6. Which of the following is not platform independent in Java? a) Everything in Java thread is platform dependent. b) The thread constructor with the stackSize parameter is platform dependent. c) The inheritance in java is platform dependent as multiple classes are involved. d) There is no platform dependency in Java.

Answer: b) The thread constructor with the stackSize parameter is platform dependent.

Q7. The following is a simple program using the concept of thread. What is the output of the above program? a. 1 3 b. 2 4 6 8 c. Runtime error d. 2 4

Answer: b. 2 4 6 8

Q8. For the program given below, what will be the output after its execution? a. 1 b. 10 c. 01 d. 11

Answer: a. 1

Q9. Which of the following method returns a reference to the currently executing thread object? a. public static boolean interrupted() b. public static Thread currentThread() c. public final boolean isAlive() d. public final void suspend()

Answer: b. public static Thread currentThread()

Q10. Which of the following methods can be used to reduce over-utilization of CPU? a. public static void yield() b. public static void main(String args[]) c. public static void sleep(long millis) d. public void start()

Answer: a. public static void yield()

Programming Assignment of Programming in Java

Complete the code segment to print the following using the concept of extending the Thread class in Java: —————–OUTPUT——————- Thread is Running. ————————————————-

In the following program, a thread class Question62 is created using the Runnable interface Complete the main() to create a thread object of the class Question62 and run the thread. It should print the output as given below. —————–OUTPUT——————- Welcome to Java Week 6 New Question. Main Thread has ended. ————————————————-

A part of the Java program is given, which can be completed in many ways, for example using the concept of thread, etc. Follow the given code and complete the program so that your program prints the message “NPTEL Java week-6 new Assignment Q3”. Your program should utilize the given interface/ class.

Execution of two or more threads occurs in a random order. The keyword ‘synchronized’ in Java is used to control the execution of thread in a strict sequence. In the following, the program is expected to print the output as given below. Do the necessary use of ‘synchronized’ keyword, so that, the program prints the Final sum as given below: —————–OUTPUT——————- Final sum:6000 ————————————————-

Given a snippet of code, add necessary codes to print the following: —————–OUTPUT——————- Name of thread ‘t1’:Thread-0 Name of thread ‘t2’:Thread-1 New name of thread ‘t1’:Week 6 Assignment Q5 New name of thread ‘t2’:Week 6 Assignment Q5 New ————————————————-

More Weeks of Programming In Java: Click Here

More Nptel courses: https://progiez.com/nptel-assignment-answers/

Session: JULY-DEC 2022

Course Name: Programming in Java NPTEL

Link of Course: Click Here

Q1. Which of the following is NOT a method of the Thread class in Java? a. public void run() b. public void exit() c. public void start() d. public final int getPriority()

Q2. Which of the following statement is true in case of starting a thread with “run)” and *start0′ method? a. There is no difference between starting a thread with ‘run()’ and ‘start()’ method. b. When you call start() method. main thread intenally calls run() method to start newly Created Thread c. When you call run() method directly no new Thread is created and code inside run() will execute on curent Thread. d. None

Q3. Which of the following can be used to create an instance of Thread? a. By implementing the Runnable interface. b. By extending the Thread class. c. By creating a new class named Thread and calling method run(). d. By importing the Thread class from package.

Answer: a, b

Q4. What is the output of the following program? a. Hello World b. a Arithmetic Exception c. ArithmeticException Exception Hello World d. ArithmeticException Hello World e. none

Q5. Which method restarts a dead thread a. start() b. restart() c. restart Thread) d. none

Q6. Assume the following method is properly synchronized and called from a thread A on an object B: wait(2000); After calling this method, when will the thread A become a candidate to get another turn at the CPU? a. After thread A is notified, or after two seconds b. Two seconds after thread A is notified. c. After the lock on B is released, or after two seconds. d. Two seconds after lock B is released.

Q7. The following is a simple program using the concept of thread. What is the output of the above program? a. 1 3 b. 1 2 3 4 c. Runtime error d. 2 4

Q8. For the program given below, what will be the output after its execution? a. 01 b. False True c. True True d. 11

Q9. Which of the following is/are not a correct constructor for a thread object? a. Thread(Runnable a, String str): b Thread(Runnable a, int priority): c. Thread(Runnable a, ThreadGroup t): d. Thread(int priority):

Answer: b, c, d

Q10. Which exception is thrown when an array element is accessed beyond the array size? a. ArayElementOut OfBounds b. Arraylndex OutOiBounds Exception c. AmaylndexOutOfBounds d. None of these

Programming Assignment Solutions

Question 1 Complete the code segment to print the following using the concept of extending the Thread class in Java: OUTPUT Thread is Running.

Question 2 In the following program, a thread class Question62 is created using the Runnable interface Complete the main() to create a thread object of the class Question62 and run the thread. It should print the output as given below. OUTPUT Welcome to Java Week 6 New Question. Main Thread has ended.

Question 3 A part of the Java program is given, which can be completed in many ways, for example using the concept of thread, etc. Follow the given code and complete the program so that your program prints the message “NPTEL Java week-6 new Assignment Q3“. Your program should utilize the given interface/ class.Invalid HTML tag: tag name o:p is not allowed

Question 4 Execution of two or more threads occurs in a random order. The keyword ‘synchronized’ in Java is used to control the execution of thread in a strict sequence. In the following, the program is expected to print the output as given below. Do the necessary use of ‘synchronized’ keyword, so that, the program prints the Final sum as given below: OUTPUT Final sum:6000

Question 5 Given a snippet of code, add necessary codes to print the following: OUTPUT Name of thread ‘t1’:Thread-0 Name of thread ‘t2’:Thread-1 New name of thread ‘t1’:Week 6 Assignment Q5 New name of thread ‘t2’:Week 6 Assignment Q5 New

More NPTEL Solutions: https://progiez.com/nptel

These are NPTEL Programming In Java Week 6 Assignment 6 Answers

COMMENTS

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

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

  3. Assignment #6

    In this video, I have explained about "Core Java - Assignment #6".Programs explained in this video: ️ Print the sum of the elements of a multidimensional arr...

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

  5. Operators (The Java™ Tutorials > Learning the Java Language

    Learning the operators of the Java programming language is a good place to start. Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result. As we explore the operators of the Java programming language, it may be helpful for you to know ahead of time which operators have the highest ...

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

    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. ... 6. Java Bitwise Operators. Bitwise operators in Java are used to perform operations on individual bits. For example,

  7. All Java Assignment Operators (Explained With Examples)

    There are mainly two types of assignment operators in Java, which are as follows: Simple Assignment Operator ; We use the simple assignment operator with the "=" sign, where the left side consists of an operand and the right side is a value. The value of the operand on the right side must be of the same data type defined on the left side.

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

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

  10. Assignment operator in Java

    Assignment Operators in Java: An Overview. We already discussed the Types of Operators in the previous tutorial Java. In this Java tutorial, we will delve into the different types of assignment operators in Java, and their syntax, and provide examples for better understanding.Because Java is a flexible and widely used programming language. Assignment operators play a crucial role in ...

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

  12. CMSC_Assignment6/BevShopDriverApp.java at main

    BevShopDriverApp.java. Cannot retrieve latest commit at this time. /* CMSC203 Assignment 6 Class: CMSC203 CRN 23999 Program: Assignment 6 Instructor: Farnaz Eivazi Description: Driver class Due Date: 12/11/2022 Integrity Pledge: I pledge that I have completed the programming assignment independently. I have not copied the code from a student or ...

  13. Shortcut "or-assignment" (|=) operator in Java

    The |= is a compound assignment operator ( JLS 15.26.2) for the boolean logical operator | ( JLS 15.22.2 ); not to be confused with the conditional-or || ( JLS 15.24 ). There are also &= and ^= corresponding to the compound assignment version of the boolean logical & and ^ respectively. In other words, for boolean b1, b2, these two are ...

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

  15. 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 ... DrawGraphics.java . 6 Graphics strikes back! assn06.zip (This ZIP file contains: 6 .java files.) 7 Magic squares Mercury.txt . Luna.txt . Solutions . Course Info ...

  16. Java Exercises

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

  17. Assignment-6/BevShopDriverApp.java at main

    BevShopDriverApp.java. Cannot retrieve latest commit at this time. History. Code. 124 lines (101 loc) · 5.35 KB. /* * Class: CMSC203 * Instructor:Grinberg * Description: Make an order with three different types of beverage choice options * Due: 04/29/2024 * Platform/compiler:Eclipse * I pledge that I have completed the programming * assignment ...

  18. Assigning in Java?

    In Java, your variables can be split into two categories: Objects, and everything else (int, long, byte, etc). A primitive type (int, long, etc), holds whatever value you assign it. An object variable, by contrast, holds a reference to an object somewhere. So if you assign one object variable to another, you have copied the reference, both A ...

  19. Help for Assignment 6: Array Statistics : r/EdhesiveHelp

    If you need answer for a test, assignment, quiz or other, you've come to the right place. ... // for StudentStatsArray.java. public class StudentStatsArray {private final Student[] students; public StudentStatsArray(Student[] students) {this.students = students;}

  20. Assignment 6

    #Data Structure and Algorithms# Java Programming# NPTEL Course# NPTEL Lectures# Algorithm Tutorial# Java Data Structures# NPTEL Online Course# Data Structure...

  21. Swayam Solver: NPTEL Programming in Java Jan 2024 Week 6 to 12

    NPTEL Programming in Java Jan 2024 Week 6 to 12 Posted on March 01, 2024 ... Week 6 : Programming Assignment 1. Due on 2024-03-14, 23:59 IST. Complete the code fragment to read two integer inputs from keyboard and find the quotient and remainder. Your last recorded submission was on 2024-03-01, 22:30 IST. Select the Language for this assignment.

  22. NPTEL Programming In Java Week 6 Assignment 6 Answers

    A part of the Java program is given, which can be completed in many ways, for example using the concept of thread, etc. Follow the given code and complete the program so that your program prints the message "NPTEL Java week-6 new Assignment Q3". Your program should utilize the given interface/ class. Solution: