tag:blogger.com,1999:blog-694855878384792308.post2788618652169658289..comments2024-03-15T23:19:22.318-07:00Comments on Java67: Can You Run Java Program Without a Main Method? [Interview Question Answer]javin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-694855878384792308.post-50161159497548843592022-03-05T20:08:03.670-08:002022-03-05T20:08:03.670-08:00what is inheritancewhat is inheritanceAnonymoushttps://www.blogger.com/profile/04715205391797531115noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-88623366865526809292018-06-28T02:25:28.845-07:002018-06-28T02:25:28.845-07:00package com.st.ems.corejava;
import java.util.Sca...package com.st.ems.corejava;<br /><br />import java.util.Scanner;<br /><br />public class Pallindrome {<br /><br /> public static void main(String[] args) {<br /><br /> int n, b, sum = 0, rem;<br /><br /> Scanner sc = new Scanner(System.in);<br /> System.out.print("Enter a Number=");<br /> n = sc.nextInt();<br /> b = n;<br /><br /> while (n > 0) {<br /> rem = n % 10;<br /> sum = sum * 10 + rem;<br /> n = n / 10;<br /> }<br /> if (b == sum)<br /> System.out.println("Number is Pallindrome");<br /> else<br /> System.out.println("Number is not Pallindrome");<br /><br /> }<br /><br />}<br />Anonymoushttps://www.blogger.com/profile/17914822526319632043noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-35002865373497263682018-03-08T02:28:57.360-08:002018-03-08T02:28:57.360-08:00{
static
{
System.out.println("hello")...{<br /><br />static <br />{<br />System.out.println("hello");<br />System.exit(0);<br />}<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-60078136151747750112018-02-28T03:32:59.532-08:002018-02-28T03:32:59.532-08:00Here is the link : How to check if number is palin...Here is the link : <a href="http://www.java67.com/2012/09/palindrome-java-program-to-check-number.html" rel="nofollow">How to check if number is palindrome in Java</a>javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-23705047315632652572018-02-28T03:32:21.393-08:002018-02-28T03:32:21.393-08:00Hello Anonymous, I have already written one, you c...Hello Anonymous, I have already written one, you can check it here<br />http://www.java67.com/2012/09/palindrome-java-program-to-check-number.htmljavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-22702515106573467312018-02-27T22:18:44.803-08:002018-02-27T22:18:44.803-08:00write a program in java to enter a number and chec...write a program in java to enter a number and check whether number is a palindrone or not<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-10117701264855521942018-01-02T02:56:50.319-08:002018-01-02T02:56:50.319-08:00you can also:
- convert java class into dll using...you can also:<br /> - convert java class into dll using Excelsior Jet, load it and call any java method, not only main()<br />- load JVM as DLL, then using JNI, load any java class and call any its methodАлексейhttps://www.blogger.com/profile/07642080816410805240noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-21695900755223676582017-07-11T22:37:06.018-07:002017-07-11T22:37:06.018-07:00yes
by using static blockyes<br />by using static blockAnonymoushttps://www.blogger.com/profile/12021017999615322711noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-20750184039317423922017-06-18T05:59:09.391-07:002017-06-18T05:59:09.391-07:00Yes, we can write java program without main. until...Yes, we can write java program without main. until java6, it is possible execute without main because jvm will load main class bytecode to the memory without checking main method, jvm will execute staticblock & jvm will display required msg.<br />incase of java7, jvm will search for main method and then jvm load bytecode to memory for execution...if not found then it rises an execption like "main method not found".<br />This(execution of writing prog without main method) is possible in servlets also...... <br /><br /><br /><br /> <br /><br /><br /><br /><br />class Demo{ <br />static{ <br />System.out.println("static block is Executed"); <br />System.exit(0); <br />} <br />} <br />Anonymoushttps://www.blogger.com/profile/16842529139568236999noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-8304975971263810142015-12-08T00:49:18.548-08:002015-12-08T00:49:18.548-08:00In Java, Up to Java 6 it was possible to do this u...In Java, Up to Java 6 it was possible to do this using the Static Initialization Block. For solve the problem to a execute java program without having main method.<br />For example we have writing the following code using static block:<br /> <br /> <br />public class CheckWithoutMain{ <br /> static{ <br /> System.out.println("static block is Executed"); <br /> System.exit(0); <br /> } <br />} <br /><br />To read more in details please visit this articles-----http://www.mindstick.com/Articles/11934/how-to-execute-a-java-program-without-having-a-main-methodAnonymoushttps://www.blogger.com/profile/04910210755296316523noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-24378371249916807682015-11-02T06:31:50.988-08:002015-11-02T06:31:50.988-08:00Well, an api or library does not need to have a ma...Well, an api or library does not need to have a main method, if that case counts? Anonymoushttps://www.blogger.com/profile/15024766378622033700noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-61065512077257306572015-10-03T22:06:31.027-07:002015-10-03T22:06:31.027-07:00What are the use cases we can use it?What are the use cases we can use it?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-7510411912243296852014-12-26T12:12:33.307-08:002014-12-26T12:12:33.307-08:00package com.test;
public class Test {
static {
...package com.test;<br /><br />public class Test {<br /> static {<br /> System.out.println("HOLAAAA");<br /> System.exit(1);<br /> }<br /><br />}<br /><br />//coco<br />//Command line :)<br />//java -Djava.security.manager=com.test.Test<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-30692665068285550452014-06-04T13:54:32.735-07:002014-06-04T13:54:32.735-07:00abstract class Test extends javafx.application.App...abstract class Test extends javafx.application.Application<br />{<br /> <br />static <br /> {<br /> System.out.println("hello");<br /> System.exit(0);<br /> }<br /><br />}<br /><br /><br /><br /><br /><br />//this code is new feature in jdk 8 version.without writing main method we can get the output in jdk8.in jdk 7 or older,application class is not there so we will get error.and we can also get the output by writing normal code of static block in jdk6 or older like <br /><br /><br /><br />class Test<br />{<br /> <br />static <br /> {<br /> System.out.println("hello");<br /> System.exit(0);<br /> }<br /><br />}<br /><br /><br /><br />it is impossible to print output in jdk 7.but if u will write main method without implementation that time u can print the content of static block in jdk 7 also.<br />so just remember in jdk6 or older it is possible,in jdk 7 it is not possible and in jdk 8 it is possible by extending our class by application class as shown above.<br />also applets,servlets,MIDlets(for mobile app) is having there own life cycle so that they can also execute without main.u can also create ur personal JVM launcher in which u can define anything u want that ur personal jvm willl not search the main method...kushhttps://www.blogger.com/profile/17615376205866309895noreply@blogger.com