[Go to site: main page, start]

0% found this document useful (0 votes)
10 views12 pages

Java Programming Examples and Concepts

The document contains a comprehensive index of Java programming exercises, covering various fundamental concepts such as printing, variable types, operators, object-oriented principles, and exception handling. Each program includes code snippets and expected output, demonstrating practical applications of Java features. The exercises range from basic tasks like printing text to more advanced topics like multithreading and generic programming.

Uploaded by

shivansh jaiswal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

Java Programming Examples and Concepts

The document contains a comprehensive index of Java programming exercises, covering various fundamental concepts such as printing, variable types, operators, object-oriented principles, and exception handling. Each program includes code snippets and expected output, demonstrating practical applications of Java features. The exercises range from basic tasks like printing text to more advanced topics like multithreading and generic programming.

Uploaded by

shivansh jaiswal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

INDEX

S.N
Name of the Program

1 WRITE A PROGRAM in Java to print Hello

2 WRITE A PROGRAM in java to understand the


difference between print () and println ()
3 WRITE A PROGRAM in Java with two classes create
a object of first class and call into another class
(having main method)
4 WRITE A PROGRAM in java to product of two
numbers
5 WRITE A PROGRAM in java product of two
numbers (Input by the user)
6 WRITE A PROGRAM in java to illustrate the concept
of local, instance and static variable
7 WRITE A PROGRAM in java to implement implicit
and explicit type casting
8 WRITE A PROGRAM in java to implement the
various operators in java
9 WRITE A PROGRAM in Java for constructor
overloading
10 WRITE A PROGRAM in Java for method
overloading
11 WRITE A PROGRAM in Java for method overriding

12 WRITE A PROGRAM in java to show run time


polymorphism (up casting)
13 WRITE A PROGRAM in java for access specifiers (all
four)
14 WRITE A PROGRAM in java to implement the single
dimension array
15 WRITE A PROGRAM in java to copy the elements
from one array to another array
16 WRITE A PROGRAM in java to perform the addition
and multiplication in 2-D array
17 WRITE A PROGRAM in Java for simple inheritance

18 WRITE A PROGRAM in java for Final keyword

19 WRITE A PROGRAM in java for super keyword

20 WRITE A PROGRAM in Java chaining constructor

21 WRITE A PROGRAM in Java for abstract method


and abstract class
22 WRITE A PROGRAM in Java for interface
23 WRITE A PROGRAM in Java multiple inheritance

24 WRITE A PROGRAM in Java for Object Cloning


(shallow and deep copy)
25 WRITE A PROGRAM in Java for Inner Classes (all
types)
26 WRITE A PROGRAM in java to create the package
(user defined package)
27 WRITE A PROGRAM in Java for exception handling
by using try, catch and finally
28 WRITE A PROGRAM in Java for throw and throws
Exception
29 WRITE A PROGRAM in Java to throw your own
Exceptions
30 WRITE A PROGRAM in Java to reading and writing
in file using byte stream
31 WRITE A PROGRAM in Java to reading and writing
in file using character stream.
32 WRITE A PROGRAM in Java to reading and writing
through console class.
33 WRITE A PROGRAM in Java how to create thread
using Thread Class.
34 WRITE A PROGRAM in Java how to create thread
using runnable interface.
35 WRITE A PROGRAM in Java to implement the
multithreading.
36 WRITE A PROGRAM in Java to achieve
synchronization in threads.
37 WRITE A PROGRAM in Java to implement the
concept of Priorities in threads.
38 WRITE A PROGRAM in Java to illustrate the concept
of Generic Programming
39 WRITE A PROGRAM in Java to illustrate the concept
of event handling (using various event handlers)
40 Create a simple student registration application
using various swing components (like:
JFrame, JButton, JLabel, text fields, text areas,
check box and radio buttons).
Program 1: Print Hello
Code:
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello");
}
}

Output:
Hello
Program 2: Difference between print() and println()
Code:
public class PrintExample {
public static void main(String[] args) {
[Link]("Hello ");
[Link]("World");
[Link]();
[Link]("Hello World");
}
}

Output:
Hello World
Hello World
Program 3: Two Classes Object Example
Code:
class FirstClass {
void display() {
[Link]("Hello from FirstClass");
}
}

public class SecondClass {


public static void main(String[] args) {
FirstClass obj = new FirstClass();
[Link]();
}
}

Output:
Hello from FirstClass
Program 4: Product of Two Numbers
Code:
public class Product {
public static void main(String[] args) {
int a = 5, b = 4;
int product = a * b;
[Link]("Product: " + product);
}
}

Output:
Product: 20
Program 5: Product of Two Numbers (Input by the user)
Code:
import [Link];

public class ProductInput {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter first number: ");
int a = [Link]();
[Link]("Enter second number: ");
int b = [Link]();
[Link]("Product: " + (a * b));
}
}

Output:
Enter first number: 5
Enter second number: 6
Product: 30
Program 6: Local, Instance and Static Variable
Code:
public class Variables {
static int staticVar = 10; // static variable
int instanceVar = 20; // instance variable

void method() {
int localVar = 30; // local variable
[Link]("Local: " + localVar);
[Link]("Instance: " + instanceVar);
[Link]("Static: " + staticVar);
}

public static void main(String[] args) {


Variables obj = new Variables();
[Link]();
}
}

Output:
Local: 30
Instance: 20
Static: 10
Program 7: Implicit and Explicit Type Casting
Code:
public class TypeCasting {
public static void main(String[] args) {
int a = 10;
double d = a; // implicit casting
[Link]("Implicit casting: " + d);

double x = 10.5;
int y = (int)x; // explicit casting
[Link]("Explicit casting: " + y);
}
}

Output:
Implicit casting: 10.0
Explicit casting: 10
Program 8: Various Operators
Code:
public class Operators {
public static void main(String[] args) {
int a = 10, b = 5;
[Link]("Addition: " + (a + b));
[Link]("Subtraction: " + (a - b));
[Link]("Multiplication: " + (a * b));
[Link]("Division: " + (a / b));
[Link]("Modulus: " + (a % b));
}
}

Output:
Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2
Modulus: 0
Program 9: Constructor Overloading
Code:
class Overload {
Overload() {
[Link]("Default Constructor");
}
Overload(int a) {
[Link]("Parameterized Constructor: " + a);
}
}

public class ConstructorTest {


public static void main(String[] args) {
new Overload();
new Overload(10);
}
}

Output:
Default Constructor
Parameterized Constructor: 10
Program 10: Method Overloading
Code:
public class MethodOverload {
void show() {
[Link]("No parameters");
}
void show(int a) {
[Link]("Integer: " + a);
}
void show(String s) {
[Link]("String: " + s);
}
public static void main(String[] args) {
MethodOverload m = new MethodOverload();
[Link]();
[Link](10);
[Link]("Hello");
}
}

Output:
No parameters
Integer: 10
String: Hello

You might also like