08/01/2020

What is Java Bytecode | Why Java is Platform Independent

Studywow: Topics= 1.Program to convert a String into Upper-Case. 2.Why Java is platform independent. 3.Program to merge two Arrays. 4(a). What is Java bytecode. 4(b). Design a webpage in HTML that contains special symbols.
Read more topics of Java to (click here).


Q1. Write a program to convert a string into upper case completely?

Ans. public class StringToUpperCaseEmp {
public static void main(String[] args) {
String str = "string abc touppercase";
String strUpper = str.toUpperCase();
System.out.println("Original String:" + str);
System.out.println("String changed to upper case: + strUpper);
}
}
Output : Original String : string abc touppercase
String changed to upper case : STRING ABC TOUPPERCASE .


Q2. Why Java is platform independent ?

Ans. Java is considered as platform independent because of many different reasons which are listed below:
(a) Output of a Java compiler is non-executable code, i.e. bytecode.
(b) Bytecode is a highly optimised set of instructions.
(c) Bytecode is executed by Java runtime system, which is called the Java Virtual Machine (JVM).
(d) JVM is an interpreter.
(e) JVM accepts bytecode as input and execute it.


Q3. Write a program to merge two arrays ?

Ans. You can merge two arrays into a single array by the use of list. Add all the methods of List class and Arrays.toString() method of Array class.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String args[]) {
String a[] = { "A", "E", "I"};
String b[] = { "0", "U" };
List list = new ArrayList (Arrays.asList (a));
list.addAll (Arrays.asList (b));
Object[] c = list.toArray();
System.out.println (Arrays.toString (c));
} }
Output: [A, E, I, O, U]


Q4. (a) What is Java bytecode ?

Ans. Java bytecode is similar to machine code, except that it can be interpreted and executed only by a Java processor, called Java Virtual Machine (JVM). The bytecode remains the same on different platforms.


Q4. (b) Design a webpage in HTML that contains special symbols ?

Ans. Coding containing special symbols for subscript, superscript and trademark:
<html>
<head>
<title>A Simple Inline Element Example</title>
</head>
<body>
<H1>HTML Sub and Sup elements</H1>
<P>We all need H <SUB>2</SUB>0.</P>
<P>E = MC<SUP>2</SUP></P>
<P>Eat a Burger<SUP>TM</SUP>Today!</P>
</body>
</html>



[ Topics= 1.Program to convert a String into Upper-Case. 2.Why Java is platform independent. 3.Program to merge two Arrays. 4(a). What is Java bytecode. 4(b). Design a webpage in HTML that contains special symbols. ]


Join us on Facebook and Twitter  to get the latest study material. You can also ask us any questions.
Facebook = @ studywow
(click on it or search "studywow" on facebook)
Twitter = @ studywow
(click on it or search "studywow" on Twitter)
Email= studywow.com@gmail.com
Send us your query anytime!


External Website links:

1. Program to convert a String into Upper-Case. (click here)
2. Why Java is platform independent. (click here)
3. Program to merge two Arrays. (click here)
4. What is Java bytecode. (click here)
5. Design a webpage in HTML that contains special symbols. (click here)

[ Topics= 1.Program to convert a String into Upper-Case. 2.Why Java is platform independent. 3.Program to merge two Arrays. 4(a). What is Java bytecode. 4(b). Design a webpage in HTML that contains special symbols. ]