{"id":1123,"date":"2017-03-20T09:54:17","date_gmt":"2017-03-20T04:24:17","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=1123"},"modified":"2017-03-29T13:04:32","modified_gmt":"2017-03-29T07:34:32","slug":"class-public-declared-file-named-java","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/class-public-declared-file-named-java\/","title":{"rendered":"[ Solution 1 Answers ] Class <X> Is Public, Should Be Declared In A File Named <X>.Java"},"content":{"rendered":"<p><label class=\"label label-warning\">PROBLEM:<\/label><\/p>\n<ul>\n<li>When the class name and the filename of a given Java program doesn\u2019t match then we will get this error.<\/li>\n<li>Considering an example where the file is named as wiki.java<\/li>\n<\/ul>\n[pastacode lang=\u201djava\u201d manual=\u201dpublic%20class%20techy%20%0A%7B%20%20%20%20%20%0A%20%20%20%20%20%20%20%20public%20static%20void%20main(String%5B%5D%20args)%20%0A%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22Hello%2C%20wikitechy!%22)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%09%0A\u201d message=\u201djava code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<p><span style=\"color: #000000;\">1 error found:<\/span><\/p>\n<p><span style=\"color: #000000;\">File: wiki.java\u00a0 [line: 1]<\/span><\/p>\n<p><span style=\"color: #000000;\">Error: class techy is public, should be declared in a file named wiki.java<\/span><\/p>\n<p><label class=\"label label-info\">SOLUTION 1:<\/label><\/p>\n<ul>\n<li>Since wiki does not match with techy, the code will not compile properly. To fix this error kind of error, either we need to rename the file or change the class name as \u201cwiki.java\u201d<\/li>\n<li>As the error message suggests, if we declare a class as public, it needs its wiki.java file. If we don\u2019t want to do that, we don\u2019t define it as public.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>PROBLEM: When the class name and the filename of a given Java program doesn\u2019t match then we will get this error. Considering an example where the file is named as wiki.java [pastacode lang=\u201djava\u201d manual=\u201dpublic%20class%20techy%20%0A%7B%20%20%20%20%20%0A%20%20%20%20%20%20%20%20public%20static%20void%20main(String%5B%5D%20args)%20%0A%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22Hello%2C%20wikitechy!%22)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%09%0A\u201d message=\u201djava code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/] [ad type=\u201dbanner\u201d] 1 error found: File: wiki.java\u00a0 [line: 1] Error: class techy is public, should be declared [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2139],"tags":[2325,2308,2316,2327,2311,2315,2321,2313,2310,2324,2309,2320,2323,2317,2318,2314,2312,2326,2319,2322,2328],"class_list":["post-1123","post","type-post","status-publish","format-standard","hentry","category-java","tag-8-error-class-funfactsactivity-is-public","tag-android-studio-class-is-public-should-be-declared-in-a-file-named","tag-arrays-java-class-is-public-should-be-declared-in-a-file-named","tag-class-is-public","tag-class-names-are-only-accepted-if-annotation","tag-error-cannot-find-symbol","tag-error-class-is-public","tag-error-could-not-find-or-load-main-class-helloworld","tag-error-could-not-find-or-load-main-class-main","tag-error9","tag-how-to-declare-file-in-java","tag-j2me-error-class-myclass-is-public-should-be-declared-in-a-file-named","tag-java-error-class-is-public","tag-java-error-should-be-declared-in-a-file-named","tag-javascript-class-is-public","tag-main-method-not-found-in-class","tag-modifier-private-not-allowed-here","tag-should-be-declared","tag-should-be-declared-in-a-file-named-java","tag-should-be-declared-in-a-file-named-java-public","tag-should-be-declared-in-a-file"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=1123"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1123\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=1123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=1123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=1123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}